45#include <fairmq/Device.h>
76 LOG(info) <<
"[HMPID Pedestal Calculation - v.1 - Init] ( create Decoder for " <<
Geo::MAXEQUIPMENTS <<
" equipments !";
83 mSigmaCut = ic.
options().
get<
float>(
"sigmacut");
84 mWriteToFiles = ic.
options().
get<
bool>(
"use-files");
85 mPedestalsBasePath = ic.
options().
get<std::string>(
"files-basepath");
86 mPedestalsCCDBBasePath = mPedestalsBasePath;
88 mWriteToDB = ic.
options().
get<
bool>(
"use-ccdb");
94 mPedestalTag = ic.
options().
get<std::string>(
"pedestals-tag");
95 mFastAlgorithm = ic.
options().
get<
bool>(
"fast-decode");
97 mWriteToDCSDB = ic.
options().
get<
bool>(
"use-dcsccdb");
102 mDcsCcdbAliveHours = ic.
options().
get<
int>(
"dcsccdb-alivehours");
105 LOG(info) <<
"Calculate Ped/Thresh." + (mWriteToDB ?
" Store in DCSCCDB at " + mPedestalsBasePath +
" with Tag:" + mPedestalTag :
" CCDB not used !");
111 if (mPedestalTag ==
"run_number") {
112 const std::string NAStr =
"NA";
126 recordPedInDcsCcdb();
135void PedestalsCalculationTask::recordPedInFiles()
151 auto padsFileName = fmt::format(
"{}_{}.dat", mPedestalsBasePath,
std::to_string(e));
152 FILE* fpads = fopen(padsFileName.c_str(),
"w");
153 if (fpads ==
nullptr) {
154 mExTimer.
logMes(
"error creating the file = " + std::string(padsFileName));
155 LOG(error) <<
"error creating the file = " << padsFileName;
166 Average = SumOfCharge / Samples;
167 Variance = sqrt(abs((Samples * SumOfSquares) - (SumOfCharge * SumOfCharge))) / Samples;
173 Threshold = (uint32_t)(Variance * mSigmaCut + Average);
174 Buffer = ((Threshold & 0x001FF) << 9) | (
Pedestal & 0x001FF);
175 fprintf(fpads,
"%05X\n", Buffer);
177 for (
int h = 48;
h < 64;
h++) {
178 fprintf(fpads,
"%05X\n", 0);
183 fprintf(fpads,
"%05X\n", 0xA0A0A);
190void PedestalsCalculationTask::recordPedInDcsCcdb()
193 LOG(info) <<
"Store Pedestals in DCS CCDB ";
195 float xb, yb, ch, Samples;
196 double SumOfCharge, SumOfSquares, Average, Variance;
197 uint32_t
Pedestal, Threshold, PedThr;
198 std::string PedestalFixedTag =
"Latest";
203#define PEDTHFORMAT "%05X,"
204#define COLUMNTAIL false
207 char* outBuffer =
new char[bufferDim];
209 char* endPtr = outBuffer + bufferDim;
215 inserPtr = outBuffer;
224 Average = SumOfCharge / Samples;
225 Variance = sqrt(abs((Samples * SumOfSquares) - (SumOfCharge * SumOfCharge))) / Samples;
231 Threshold = (uint32_t)(Variance * mSigmaCut + Average);
232 PedThr = ((Threshold & 0x001FF) << 9) | (
Pedestal & 0x001FF);
233 assert(inserPtr < endPtr);
234 snprintf(inserPtr, endPtr - inserPtr,
PEDTHFORMAT, PedThr);
238 for (
int h = 48;
h < 64;
h++) {
239 assert(inserPtr < endPtr);
240 snprintf(inserPtr, endPtr - inserPtr,
PEDTHFORMAT, 0);
247 assert(inserPtr < endPtr);
248 snprintf(inserPtr, endPtr - inserPtr,
"%05X\n", 0xA0A0A);
255 long maxTimeStamp = minTimeStamp + (3600L * mDcsCcdbAliveHours * 1000);
257 auto filename = fmt::format(
"{}_{}.dat", mPedestalsBasePath, PedestalFixedTag);
258 mExTimer.
logMes(
"File name = >" +
filename +
"< (" + mPedestalsCCDBBasePath +
"," + PedestalFixedTag);
260 mDbMetadata.emplace(
"Tag", PedestalFixedTag.c_str());
268void PedestalsCalculationTask::recordPedInCcdb()
271 LOG(info) <<
"Store Pedestals in ccdb ";
274 double Samples, SumOfCharge, SumOfSquares, Average, Variance;
288 TMatrixF* pS = (TMatrixF*)aSigmas.At(
m);
289 TMatrixF* pP = (TMatrixF*)aPedestals.At(
m);
298 (*pP)(
x,
y) = SumOfCharge / Samples;
299 (*pS)(
x,
y) = sqrt(abs((Samples * SumOfSquares) - (SumOfCharge * SumOfCharge))) / Samples;
309 long maxTimeStamp = minTimeStamp + (3600L * 24 * (5 * 365) * 1000);
315 TString
filename = TString::Format(
"%s/%s/Mean_%d", mPedestalsCCDBBasePath.c_str(), mPedestalTag.c_str(),
i);
316 mDbMetadata.emplace(
"Tag", mPedestalTag.c_str());
323 TString
filename = TString::Format(
"%s/%s/Sigma_%d", mPedestalsCCDBBasePath.c_str(), mPedestalTag.c_str(),
i);
324 mDbMetadata.emplace(
"Tag", mPedestalTag.c_str());
334 LOG(
debug) <<
"*********** In decodeTF **************";
336 auto& inputs = pc.
inputs();
338 for (
auto it = parser.
begin(),
end = parser.
end(); it !=
end; ++it) {
339 uint32_t* theBuffer = (uint32_t*)it.raw();
340 mDeco->
setUpStream(theBuffer, it.size() + it.offset());
342 if (mFastAlgorithm) {
349 LOG(
debug) <<
"End Page decoding !";
352 mTotalDigits += mDeco->
mDigits.size();
361 std::vector<o2::framework::InputSpec> inputs;
364 std::vector<o2::framework::OutputSpec> outputs;
367 "HMP-PestalsCalculation",
371 Options{{
"files-basepath", VariantType::String,
"HMP/Config", {
"Name of the Base Path of Pedestals/Thresholds files."}},
372 {
"use-files", VariantType::Bool,
false, {
"Register the Pedestals/Threshold values into ASCII files"}},
373 {
"use-ccdb", VariantType::Bool,
false, {
"Register the Pedestals/Threshold values into the CCDB"}},
374 {
"ccdb-uri", VariantType::String,
"http://ccdb-test.cern.ch:8080", {
"URI for the CCDB access."}},
375 {
"use-dcsccdb", VariantType::Bool,
false, {
"Register the Pedestals/Threshold values into the DCS-CCDB"}},
376 {
"dcsccdb-uri", VariantType::String,
"http://ccdb-test.cern.ch:8080", {
"URI for the DCS-CCDB access."}},
377 {
"dcsccdb-alivehours", VariantType::Int, 3, {
"Alive hours in DCS-CCDB."}},
378 {
"fast-decode", VariantType::Bool,
true, {
"Use the fast algorithm. (error 0.8%)"}},
379 {
"pedestals-tag", VariantType::String,
"Latest", {
"The tag applied to this set of pedestals/threshold values"}},
380 {
"sigmacut", VariantType::Float, 4.0f, {
"Sigma values for the Thresholds calculation."}}}};
A raw page parser for DPL input.
Definition of the Names Generator class.
Class for time synchronization of RawReader instances.
int storeAsTFileAny(const T *obj, std::string const &path, std::map< std::string, std::string > const &metadata, long startValidityTimestamp=-1, long endValidityTimestamp=-1, std::vector< char >::size_type maxSize=0) const
void init(std::string const &hosts)
bool isHostReachable() const
T get(const char *key) const
The parser handles transparently input in the format of raw pages.
const_iterator end() const
const_iterator begin() const
ConfigParamRegistry const & options()
InputRecord & inputs()
The inputs associated with this processing context.
ServiceRegistryRef services()
The services registry associated with this processing context.
void stop()
stop : stops the timer
void elapseMes(std::string const message)
void start()
start : starts the timer
void logMes(std::string const message)
static constexpr int N_COLUMNS
static constexpr int N_XROWS
static constexpr int N_MODULES
static constexpr int N_DILOGICS
static constexpr int N_CHANNELS
static constexpr int N_YCOLS
static constexpr int MAXEQUIPMENTS
float getAverageEventSize(int Equipment)
void decodePageFast(uint32_t **streamBuf)
void init()
Init all the members variables.
std::vector< o2::hmpid::Digit > mDigits
double getChannelSquare(int Equipment, int Column, int Dilogic, int Channel)
void decodePage(uint32_t **streamBuffer)
uint16_t getChannelSamples(int Equipment, int Column, int Dilogic, int Channel)
bool setUpStream(void *Buffer, long BufferLen)
double getPadSum(int Module, int Row, int Column)
uint16_t getPadSamples(int Module, int Row, int Column)
double getPadSquares(int Module, int Row, int Column)
double getChannelSum(int Equipment, int Column, int Dilogic, int Channel)
void decodeTF(framework::ProcessingContext &pc)
void init(framework::InitContext &ic) final
void run(framework::ProcessingContext &pc) final
void endOfStream(framework::EndOfStreamContext &ec) override
This is invoked whenever we have an EndOfStream event.
long getCurrentTimestamp()
returns the timestamp in long corresponding to "now"
std::vector< char > DCSconfigObject_t
void addConfigItem(DCSconfigObject_t &configVector, std::string key, const T value)
Defining PrimaryVertex explicitly as messageable.
std::vector< ConfigParamSpec > Options
std::vector< InputSpec > select(char const *matcher="")
o2::framework::DataProcessorSpec getPedestalsCalculationSpec(std::string inputSpec="TF:HMP/RAWDATA")
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::string to_string(gsl::span< T, Size > span)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"