35 LOGF(info,
"ITSDCSParser init...", mSelfName);
37 this->mCcdbUrl = ic.
options().
get<std::string>(
"ccdb-url");
39 this->mCcdbUrlRct = ic.
options().
get<std::string>(
"ccdb-url-rct");
41 this->mVerboseOutput = ic.
options().
get<
bool>(
"verbose");
54 const auto inString = pc.
inputs().
get<gsl::span<char>>(
"inString");
55 std::string inStringConv;
56 std::copy(inString.begin(), inString.end(), std::back_inserter(inStringConv));
59 std::string line_ending =
"\n";
60 size_t newline_pos = inStringConv.find(line_ending);
61 if (newline_pos && newline_pos != std::string::npos &&
62 inStringConv[newline_pos - 1] ==
'\r') {
70 for (
const std::string& line : this->vectorizeStringList(inStringConv, line_ending)) {
74 this->updateMemoryFromInputString(line);
75 this->appendDeadChipObj();
80 this->saveMissingToOutput();
82 if (this->mConfigDCS.size() && this->mDeadMap.size()) {
83 LOG(info) <<
"Pushing to CCDB...\n";
85 this->mConfigDCS.clear();
97void ITSDCSParser::updateMemoryFromInputString(
const std::string& inString)
101 if (this->mVerboseOutput) {
102 LOG(info) <<
"Parsing string: " << inString;
106 const std::string delimiter =
"|";
107 const std::string terminator =
"!";
109 size_t npos = inString.find(delimiter);
110 if (npos == std::string::npos) {
111 LOG(
error) <<
"Delimiter not found, possibly corrupted data!";
116 this->mStaveName = inString.substr(
pos, npos);
117 this->mSavedStaves.push_back(this->mStaveName);
120 this->mTerminationString =
true;
121 if (inString.back() !=
'!') {
122 this->mTerminationString =
false;
123 LOG(warning) <<
"Terminator not found, possibly incomplete data for stave " << this->mStaveName <<
" !";
127 if (!this->updatePosition(
pos, npos, delimiter,
"RUN", inString)) {
130 this->updateAndCheck(this->mRunNumber, std::stoi(inString.substr(
pos, npos)));
133 if (!this->updatePosition(
pos, npos, delimiter,
"CONFIG", inString)) {
136 this->updateAndCheck(this->mConfigVersion, std::stoi(inString.substr(
pos, npos)));
139 if (!this->updatePosition(
pos, npos, delimiter,
"RUNTYPE", inString)) {
142 this->updateAndCheck(this->mRunType, std::stoi(inString.substr(
pos, npos)));
145 if (!this->updatePosition(
pos, npos, delimiter,
"DISABLED_CHIPS", inString)) {
148 std::string disabledChipsStr = inString.substr(
pos, npos);
149 if (disabledChipsStr.length()) {
150 this->mDisabledChips = this->vectorizeStringListInt(disabledChipsStr,
";");
154 if (!this->updatePosition(
pos, npos, delimiter,
"MASKED_DCOLS", inString)) {
157 std::string maskedDoubleColsStr = inString.substr(
pos, npos);
158 if (maskedDoubleColsStr.length()) {
159 std::vector<std::string> chipVect = this->vectorizeStringList(maskedDoubleColsStr,
";");
160 for (
const std::string&
str : chipVect) {
162 this->mMaskedDoubleCols.push_back(this->vectorizeStringListInt(
str,
":"));
167 if (!this->updatePosition(
pos, npos, delimiter,
"DCOLS_EOR", inString,
true)) {
170 std::string doubleColsEORstr = inString.substr(
pos);
174 if (doubleColsEORstr ==
"|") {
175 this->writeChipInfo(this->mStaveName, -1);
181 size_t pos_del = doubleColsEORstr.rfind(
';');
182 if (pos_del != std::string::npos) {
183 doubleColsEORstr = doubleColsEORstr.erase(pos_del);
186 if (doubleColsEORstr.length()) {
187 std::vector<std::string> bigVect = this->vectorizeStringList(doubleColsEORstr,
"&");
188 for (
const std::string& bigStr : bigVect) {
189 std::vector<std::string> bigVectSplit = this->vectorizeStringList(bigStr,
"|");
190 if (!bigVectSplit.size()) {
195 std::vector<std::string> doubleColDisable = this->vectorizeStringList(bigVectSplit[0],
";");
196 for (
const std::string&
str : doubleColDisable) {
200 std::vector<unsigned short int> doubleColDisableVector = this->vectorizeStringListInt(
str,
":");
201 this->mDoubleColsDisableEOR[doubleColDisableVector[0]].push_back(doubleColDisableVector[1]);
204 if (bigVectSplit.size() > 1) {
205 std::vector<std::string> pixelFlagsEOR = this->vectorizeStringList(bigVectSplit[1],
";");
206 for (
const std::string&
str : pixelFlagsEOR) {
207 std::vector<unsigned short int> pixelFlagsVector = this->vectorizeStringListInt(
str,
":");
208 this->mPixelFlagsEOR[pixelFlagsVector[0]].push_back(pixelFlagsVector[1]);
219bool ITSDCSParser::updatePosition(
size_t&
pos,
size_t& npos,
220 const std::string& delimiter,
const char* word,
221 const std::string& inString,
bool ignoreNpos )
223 pos += npos + delimiter.length() + std::string(word).length();
225 npos = inString.find(delimiter,
pos);
228 if (npos == std::string::npos) {
229 LOG(
error) <<
"Delimiter not found, possibly corrupted data for stave " << this->mStaveName <<
" !";
231 this->writeChipInfo(this->mStaveName, -1);
245void ITSDCSParser::updateAndCheck(
int& memValue,
const int newValue)
251 }
else if (memValue != newValue) {
253 throw std::runtime_error(fmt::format(
"New value {} differs from old value {}", newValue, memValue));
260void ITSDCSParser::updateAndCheck(
short int& memValue,
const short int newValue)
266 }
else if (memValue != newValue) {
268 throw std::runtime_error(fmt::format(
"New value {} differs from old value {}", newValue, memValue));
276std::vector<std::string> ITSDCSParser::vectorizeStringList(
277 const std::string&
str,
const std::string& delimiter)
279 std::vector<std::string> str_vect;
280 size_t prev_pos = 0,
pos = 0;
281 while ((
pos =
str.find(delimiter,
pos)) != std::string::npos) {
282 std::string substr =
str.substr(prev_pos,
pos - prev_pos);
283 if (substr.length()) {
284 str_vect.push_back(substr);
286 pos += delimiter.length();
289 std::string substr =
str.substr(prev_pos,
pos - prev_pos);
290 if (substr.length()) {
291 str_vect.push_back(substr);
297std::vector<unsigned short int> ITSDCSParser::vectorizeStringListInt(
298 const std::string&
str,
const std::string& delimiter)
300 std::vector<unsigned short int> int_vect;
301 size_t prev_pos = 0,
pos = 0;
302 while ((
pos =
str.find(delimiter,
pos)) != std::string::npos) {
303 unsigned short int substr = std::stoi(
str.substr(prev_pos,
pos - prev_pos));
304 int_vect.push_back(substr);
305 pos += delimiter.length();
308 int_vect.push_back(std::stoi(
str.substr(prev_pos,
pos - prev_pos)));
313void ITSDCSParser::saveToOutput()
316 for (
const unsigned short int& chipID :
this->mDisabledChips) {
318 this->writeChipInfo(this->mStaveName, chipID);
330 mDoubleColsDisableEOR.erase(chipID);
331 mPixelFlagsEOR.erase(chipID);
335 for (std::vector<unsigned short int> maskedDoubleCols :
this->mMaskedDoubleCols) {
336 unsigned short int chipID = maskedDoubleCols[0];
337 maskedDoubleCols.erase(maskedDoubleCols.begin());
340 this->writeChipInfo(this->mStaveName, chipID);
348 this->mConfigDCS,
"Dcol_masked_eor", this->intVecToStr(this->mDoubleColsDisableEOR[chipID],
"|"));
349 this->mDoubleColsDisableEOR.erase(chipID);
351 this->mConfigDCS,
"Pixel_flags", this->intVecToStr(this->mPixelFlagsEOR[chipID],
"|"));
352 this->mPixelFlagsEOR.erase(chipID);
357 for (
const auto& [chipID,
v] :
this->mDoubleColsDisableEOR) {
358 std::string
s = this->intVecToStr(
v,
"|");
360 this->writeChipInfo(this->mStaveName, chipID);
365 this->mConfigDCS,
"Pixel_flags", this->intVecToStr(this->mPixelFlagsEOR[chipID],
"|"));
366 this->mPixelFlagsEOR.erase(chipID);
371 for (
const auto& [chipID,
v] :
this->mPixelFlagsEOR) {
372 std::string
s = this->intVecToStr(
v,
"|");
374 this->writeChipInfo(this->mStaveName, chipID);
386void ITSDCSParser::saveMissingToOutput()
389 std::vector<std::string> missingStaves;
390 std::vector<std::string> listStaves = this->listStaves();
391 std::vector<std::string> savedStaves = this->mSavedStaves;
392 std::sort(savedStaves.begin(), savedStaves.end());
393 std::set_difference(listStaves.begin(), listStaves.end(), savedStaves.begin(), savedStaves.end(),
394 std::inserter(missingStaves, missingStaves.begin()));
396 for (std::string stave : missingStaves) {
397 this->writeChipInfo(stave, -1);
406void ITSDCSParser::resetMemory()
409 mDisabledChips.clear();
410 mMaskedDoubleCols.clear();
411 mDoubleColsDisableEOR.clear();
412 mPixelFlagsEOR.clear();
418std::string ITSDCSParser::intVecToStr(
419 const std::vector<unsigned short int>&
v,
const std::string& delin)
427 for (
int i = 1;
i <
v.size();
i++) {
436void ITSDCSParser::writeChipInfo(
437 const std::string& staveName,
const short int chipID)
443 unsigned short int hicPos = getModule(chipID);
444 bool hsPos = getHS(chipID);
471 long tstart = 0, tend = 0;
474 cdbman.setURL(mCcdbUrlRct);
475 cdbman.setFatalWhenNull(
false);
477 if (ts.first < 0 || ts.second < 0) {
478 LOGP(info,
"Failed to retrieve headers from CCDB with run number {}, << this->mRunNumber, will default to using the current time for timestamp information", mRunNumber);
480 tend = tstart + 365L * 24 * 3600 * 1000;
491 std::string
path(
"ITS/Calib/DCS_CONFIG");
492 std::string path_deadMap(
"ITS/Calib/DeadMap");
493 const char*
filename =
"dcs_config.root";
495 std::string filename_deadMap =
"o2-itsmft-NoiseMap_" +
std::to_string(current_time) +
".root";
501 info_deadMap.setFileName(filename_deadMap);
504 LOG(info) <<
"Class Name: " << class_name <<
" | File Name: " <<
filename
505 <<
"\nSending to ccdb-populator the object " <<
info.getPath() <<
"/" <<
info.getFileName()
506 <<
" of size " <<
image->size() <<
" bytes, valid for "
507 <<
info.getStartValidityTimestamp() <<
" : "
508 <<
info.getEndValidityTimestamp();
510 if (mCcdbUrl.empty()) {
517 LOG(info) <<
"Sending object " <<
info.getFileName() <<
" to " << mCcdbUrl <<
"/browse/"
518 <<
info.getPath() <<
" from the ITS string parser workflow";
523 info.getMetaData(),
info.getStartValidityTimestamp(),
info.getEndValidityTimestamp());
527 LOG(info) <<
"Class Name: " << class_name_deadMap <<
" | File Name: " << filename_deadMap
528 <<
"\nSending to ccdb-populator the object " << info_deadMap.getPath() <<
"/" << info_deadMap.getFileName()
529 <<
" of size " << image_deadMap->size() <<
" bytes, valid for "
530 << info_deadMap.getStartValidityTimestamp() <<
" : "
531 << info_deadMap.getEndValidityTimestamp();
533 if (mCcdbUrl.empty()) {
540 LOG(info) <<
"Sending object " << info_deadMap.getFileName() <<
" to " << mCcdbUrl <<
"/browse/"
541 << info_deadMap.getPath() <<
" from the ITS string parser workflow";
545 &image_deadMap->at(0), image_deadMap->size(), info_deadMap.getFileName(), info_deadMap.getObjectType(), info_deadMap.getPath(),
546 info_deadMap.getMetaData(), info_deadMap.getStartValidityTimestamp(), info_deadMap.getEndValidityTimestamp());
553std::vector<std::string> ITSDCSParser::listStaves()
555 std::vector<std::string> vecStaves = {};
556 int stavesPerLayer[] = {12, 16, 20, 24, 30, 42, 48};
557 std::string stavenum =
"";
558 for (
int i = 0;
i < 7;
i++) {
559 for (
int j = 0;
j < stavesPerLayer[
i];
j++) {
561 int precision = 2 - std::min(2, (
int)(stavestring.size()));
564 vecStaves.push_back(stave);
571void ITSDCSParser::appendDeadChipObj()
575 for (
auto ch :
this->mDisabledChips) {
577 unsigned short int hicPos = getModule(ch);
579 unsigned short int chipInMod = ch % 16;
581 unsigned short int globchipID = getGlobalChipID(hicPos, hS, chipInMod);
583 if (mVerboseOutput) {
584 LOG(info) <<
"Masking dead chip " << globchipID;
590unsigned short int ITSDCSParser::getGlobalChipID(
unsigned short int hicPos,
bool hS,
unsigned short int chipInMod)
593 std::vector<unsigned short int> stavesPerLayer = {12, 16, 20, 24, 30, 42, 48};
594 std::vector<unsigned short int> chipPerStave = {9, 9, 9, 112, 112, 196, 196};
595 std::vector<unsigned short int> maxChipIDlayer = {0};
597 for (
int i = 0;
i < 7;
i++) {
598 maxChip += stavesPerLayer[
i] * chipPerStave[
i];
599 maxChipIDlayer.push_back(maxChip - 1);
602 unsigned short int layerNum = std::stoi(this->mStaveName.substr(1, 1));
603 unsigned short int staveNum = std::stoi(this->mStaveName.substr(3, 2));
605 unsigned short int chipid_in_HIC = ((layerNum > 2 && chipInMod > 7) || layerNum == 0) ? chipInMod : chipInMod + 1;
606 unsigned short int modPerLayer = (layerNum > 2 && layerNum < 5) ? 4 : 7;
607 unsigned short int add_HSL = (hS) ? (14 * modPerLayer) : 0;
609 unsigned short int chipIDglob = chipid_in_HIC + maxChipIDlayer[layerNum] + (staveNum)*chipPerStave[layerNum] + (hicPos - 1) * 14 + add_HSL;
615unsigned short int ITSDCSParser::getModule(
unsigned short int chipID)
618 unsigned short int hicPos = 0;
619 if (std::stoi((this->mStaveName).substr(1, 1)) > 2) {
620 if (chipID / 16 <= 7) {
621 hicPos = chipID / 16;
623 hicPos = (chipID / 16) - 8;
632bool ITSDCSParser::getHS(
unsigned short int chipInMod)
636 if (chipInMod / 16 <= 7) {
648 std::vector<InputSpec> inputs;
649 inputs.emplace_back(
"inString", detOrig,
"DCS_CONFIG_FILE", 0, Lifetime::Sporadic);
650 inputs.emplace_back(
"nameString", detOrig,
"DCS_CONFIG_NAME", 0, Lifetime::Sporadic);
652 std::vector<OutputSpec> outputs;
662 {
"verbose", VariantType::Bool,
false, {
"Use verbose output mode"}},
663 {
"ccdb-url", VariantType::String,
"", {
"CCDB url, default is empty (i.e. send output to CCDB populator workflow)"}},
664 {
"ccdb-url-rct", VariantType::String,
"http://o2-ccdb.internal", {
"CCDB url from where to get RCT object for headers, default is o2-ccdb.internal. Use http://alice-ccdb.cern.ch for local tests"}}}};
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error s
char error[CURL_ERROR_SIZE]
static BasicCCDBManager & instance()
std::pair< int64_t, int64_t > getRunDuration(int runnumber, bool fatal=true)
void init(std::string const &hosts)
static std::unique_ptr< std::vector< char > > createObjectImage(const T *obj, CcdbObjectInfo *info=nullptr)
int storeAsBinaryFile(const char *buffer, size_t size, const std::string &fileName, const std::string &objectType, const std::string &path, const std::map< std::string, std::string > &metadata, long startValidityTimestamp, long endValidityTimestamp, std::vector< char >::size_type maxSize=0) const
static constexpr long MINUTE
T get(const char *key) const
void snapshot(const Output &spec, T const &object)
ConfigParamRegistry const & options()
DataAllocator & outputs()
The data allocator is used to allocate memory for the output data.
InputRecord & inputs()
The inputs associated with this processing context.
void run(ProcessingContext &pc) final
void init(InitContext &ic) final
static constexpr int getNChips()
number of chips per barrel
static constexpr std::string_view getName()
NoiseMap class for the ITS and MFT.
void maskFullChip(int chip, bool cleanNoisyPixels=false)
GLsizei const GLchar *const * path
GLenum GLint GLint * precision
constexpr o2::header::DataOrigin gDataOriginITS
long getCurrentTimestamp()
returns the timestamp in long corresponding to "now"
void addConfigItem(DCSconfigObject_t &configVector, std::string key, const T value)
o2::framework::DataProcessorSpec getITSDCSParserSpec()
const short int UNSET_SHORT
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)
static constexpr o2::header::DataOrigin gDataOriginCDBWrapper
static constexpr o2::header::DataOrigin gDataOriginCDBPayload
static std::string getClassName(const T &obj)
get the class name of the object
static std::string concat_string(Ts const &... ts)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"