29 : mDataSource(datasource), mRunMFT(doMFT)
31 std::string detector = doMFT ?
"MFT" :
"ITS";
47 LOG(info) <<
"ITSMFTDeadMapBuilder init... " << mSelfName;
49 mTFSampling = ic.
options().
get<
int>(
"tf-sampling");
50 mTFSamplingTolerance = ic.
options().
get<
int>(
"tf-sampling-tolerance");
51 if (mTFSamplingTolerance > mTFSampling) {
52 LOG(warning) <<
"Invalid request tf-sampling-tolerance larger or equal than tf-sampling. Setting tolerance to " << mTFSampling - 1;
53 mTFSamplingTolerance = mTFSampling - 1;
55 mSampledSlidingWindowSize = ic.
options().
get<
int>(
"tf-sampling-history-size");
56 mTFLength = ic.
options().
get<
int>(
"tf-length");
57 mDoLocalOutput = ic.
options().
get<
bool>(
"local-output");
58 mObjectName = ic.
options().
get<std::string>(
"outfile");
59 mCCDBUrl = ic.
options().
get<std::string>(
"ccdb-url");
60 if (mCCDBUrl ==
"none") {
64 mLocalOutputDir = ic.
options().
get<std::string>(
"output-dir");
65 mSkipStaticMap = ic.
options().
get<
bool>(
"skip-static-map");
66 mNoGroupITSLanes = ic.
options().
get<
bool>(
"no-group-its-lanes");
78 mSampledHistory.clear();
80 mStaticChipStatus.clear();
84 if (!mSkipStaticMap) {
85 mStaticChipStatus.resize(N_CHIPS,
false);
88 LOG(info) <<
"Sampling one TF every " << mTFSampling <<
" with " << mTFSamplingTolerance <<
" TF tolerance";
95std::vector<uint16_t> ITSMFTDeadMapBuilder::getChipIDsOnSameCable(uint16_t chip)
97 if (mRunMFT || chip < N_CHIPS_ITSIB) {
98 return std::vector<uint16_t>{chip};
100 uint16_t firstchipcable = 7 * (uint16_t)((chip - N_CHIPS_ITSIB) / 7) + N_CHIPS_ITSIB;
101 std::vector<uint16_t> chipList(7);
102 std::generate(chipList.begin(), chipList.end(), [&firstchipcable]() { return firstchipcable++; });
107bool ITSMFTDeadMapBuilder::acceptTF(
long orbit)
113 if (mTFSamplingTolerance < 1) {
114 return ((
orbit / mTFLength) % mTFSampling == 0);
117 if ((
orbit / mTFLength) % mTFSampling > mTFSamplingTolerance) {
121 long sampling_index =
orbit / mTFLength / mTFSampling;
123 if (mSampledTFs.find(sampling_index) == mSampledTFs.end()) {
125 mSampledTFs.insert(sampling_index);
126 mSampledHistory.push_back(sampling_index);
128 if (mSampledHistory.size() > mSampledSlidingWindowSize) {
129 long oldIndex = mSampledHistory.front();
130 mSampledHistory.pop_front();
131 mSampledTFs.erase(oldIndex);
142void ITSMFTDeadMapBuilder::finalizeOutput()
145 if (!mSkipStaticMap) {
146 std::vector<uint16_t> staticmap{};
147 int staticmap_chipcounter = 0;
148 for (uint16_t el = 0; el < mStaticChipStatus.size(); el++) {
149 if (mStaticChipStatus[el]) {
152 staticmap_chipcounter++;
153 bool previous_dead = (el > 0 && !mStaticChipStatus[el - 1]);
154 bool next_dead = (el < mStaticChipStatus.size() - 1 && !mStaticChipStatus[el + 1]);
155 if (!previous_dead && next_dead) {
156 staticmap.push_back(el | (uint16_t)(0x8000));
157 }
else if (previous_dead && next_dead) {
160 staticmap.push_back(el);
164 LOG(info) <<
"Filling static part of the map with " << staticmap_chipcounter <<
" dead chips, saved into " << staticmap.size() <<
" words";
169 if (mDoLocalOutput) {
170 std::string localoutfilename = mLocalOutputDir +
"/" + mObjectName;
171 TFile outfile(localoutfilename.c_str(),
"RECREATE");
172 outfile.WriteObjectAny(&mMapObject,
"o2::itsmft::TimeDeadMap",
"ccdb_object");
189 std::chrono::time_point<std::chrono::high_resolution_clock>
start;
190 std::chrono::time_point<std::chrono::high_resolution_clock>
end;
192 start = std::chrono::high_resolution_clock::now();
196 if (tinfo.globalRunNumberChanged || mFirstOrbitRun == 0x0) {
197 mRunNumber = tinfo.runNumber;
198 mFirstOrbitRun = mFirstOrbitTF;
206 mFirstOrbitTF = tinfo.firstTForbit;
209 long sampled_orbit = mFirstOrbitTF - mFirstOrbitRun;
211 if (!acceptTF(sampled_orbit)) {
216 LOG(info) <<
"Processing step #" << mStepCounter <<
" out of " << mTFCounter <<
" good TF received. First orbit " << mFirstOrbitTF;
220 std::vector<bool> ChipStatus(N_CHIPS,
false);
222 if (mDataSource ==
"digits") {
223 const auto elements = pc.
inputs().
get<gsl::span<o2::itsmft::Digit>>(
"elements");
224 const auto ROFs = pc.
inputs().
get<gsl::span<o2::itsmft::ROFRecord>>(
"ROFs");
225 for (
const auto& rof : ROFs) {
226 auto elementsInTF = rof.getROFData(elements);
227 for (
const auto& el : elementsInTF) {
228 ChipStatus.at((
int)el.getChipIndex()) =
true;
231 }
else if (mDataSource ==
"clusters") {
232 const auto elements = pc.
inputs().
get<gsl::span<o2::itsmft::CompClusterExt>>(
"elements");
233 const auto ROFs = pc.
inputs().
get<gsl::span<o2::itsmft::ROFRecord>>(
"ROFs");
234 for (
const auto& rof : ROFs) {
235 auto elementsInTF = rof.getROFData(elements);
236 for (
const auto& el : elementsInTF) {
237 ChipStatus.at((
int)el.getSensorID()) =
true;
240 }
else if (mDataSource ==
"chipsstatus") {
241 const auto elements = pc.
inputs().
get<gsl::span<char>>(
"elements");
242 for (uint16_t chipID = 0; chipID < elements.size(); chipID++) {
243 if (elements[chipID]) {
244 ChipStatus.at(chipID) =
true;
250 if (!mSkipStaticMap) {
251 for (
size_t el = 0; el < mStaticChipStatus.size(); el++) {
252 mStaticChipStatus[el] = mStaticChipStatus[el] || ChipStatus[el];
257 if (!mRunMFT && !mNoGroupITSLanes) {
258 for (uint16_t el = N_CHIPS_ITSIB; el < ChipStatus.size(); el++) {
259 if (ChipStatus.at(el)) {
260 std::vector<uint16_t> chipincable = getChipIDsOnSameCable(el);
261 for (uint16_t el2 : chipincable) {
262 ChipStatus.at(el2) =
true;
271 for (uint16_t el = 0; el < ChipStatus.size(); el++) {
272 if (ChipStatus.at(el)) {
276 bool previous_dead = (el > 0 && !ChipStatus.at(el - 1));
277 bool next_dead = (el < ChipStatus.size() - 1 && !ChipStatus.at(el + 1));
278 if (!previous_dead && next_dead) {
279 mDeadMapTF.push_back(el | (uint16_t)(0x8000));
280 }
else if (previous_dead && next_dead) {
283 mDeadMapTF.push_back(el);
287 LOG(info) <<
"TF contains " << CountDead <<
" dead chips, saved into " << mDeadMapTF.size() <<
" words.";
290 mMapObject.
fillMap(mFirstOrbitTF, mDeadMapTF);
292 end = std::chrono::high_resolution_clock::now();
293 int difference = std::chrono::duration_cast<std::chrono::microseconds>(
end -
start).count();
295 LOG(info) <<
"Elapsed time in TF processing: " << difference / 1000. <<
" ms";
297 if (pc.
transitionState() == TransitionHandlingState::Requested && !isEnded) {
298 std::string detname = mRunMFT ?
"MFT" :
"ITS";
299 LOG(warning) <<
"Transition state requested for " << detname <<
" process, calling stop() and stopping the process of new data.";
307void ITSMFTDeadMapBuilder::PrepareOutputCcdb(
EndOfStreamContext* ec, std::string ccdburl =
"")
314 std::map<std::string, std::string> md = {{
"map_version", MAP_VERSION}, {
"runNumber",
std::to_string(mRunNumber)}};
316 std::string
path = mRunMFT ?
"MFT/Calib/" :
"ITS/Calib/";
317 std::string name_str =
"TimeDeadMap";
322 info.setFileName(mObjectName);
324 info.setAdjustableEOV();
328 LOG(important) <<
"Sending object " << info.getPath() <<
"/" << info.getFileName()
329 <<
" to ccdb-populator, of size " <<
image->size() <<
" bytes, valid for "
330 << info.getStartValidityTimestamp() <<
" : " << info.getEndValidityTimestamp();
341 else if (!ccdburl.empty()) {
343 LOG(important) << mSelfName <<
" sending object " << ccdburl <<
"/browse/" << info.getPath() <<
"/" << info.getFileName()
344 <<
" of size " <<
image->size() <<
" bytes, valid for "
345 << info.getStartValidityTimestamp() <<
" : " << info.getEndValidityTimestamp();
350 &
image->at(0),
image->size(), info.getFileName(), info.getObjectType(),
351 info.getPath(), info.getMetaData(),
352 info.getStartValidityTimestamp(), info.getEndValidityTimestamp());
358 LOG(warning) <<
"PrepareOutputCcdb called with empty arguments. Doing nothing.";
370 LOG(info) <<
"endOfStream report: " << mSelfName;
373 PrepareOutputCcdb(&ec);
375 LOG(warning) <<
"Time-dependent dead map is empty and will not be forwarded as output";
377 LOG(info) <<
"Stop process of new data because of endOfStream";
388 LOG(info) <<
"stop() report: " << mSelfName;
390 if (!mCCDBUrl.empty()) {
391 std::string detname = mRunMFT ?
"MFT" :
"ITS";
392 LOG(warning) <<
"endOfStream not processed. Sending output to ccdb from the " << detname <<
" deadmap builder workflow.";
393 PrepareOutputCcdb(
nullptr, mCCDBUrl);
395 LOG(alarm) <<
"endOfStream not processed. Nothing forwarded as output.";
397 LOG(info) <<
"Stop process of new data because of stop() call.";
413 std::vector<InputSpec> inputs;
415 if (datasource ==
"digits") {
416 inputs.emplace_back(
"elements", detOrig,
"DIGITS", 0, Lifetime::Timeframe);
417 inputs.emplace_back(
"ROFs", detOrig,
"DIGITSROF", 0, Lifetime::Timeframe);
418 }
else if (datasource ==
"clusters") {
419 inputs.emplace_back(
"elements", detOrig,
"COMPCLUSTERS", 0, Lifetime::Timeframe);
420 inputs.emplace_back(
"ROFs", detOrig,
"CLUSTERSROF", 0, Lifetime::Timeframe);
421 }
else if (datasource ==
"chipsstatus") {
422 inputs.emplace_back(
"elements", detOrig,
"CHIPSSTATUS", 0, Lifetime::Timeframe);
427 std::vector<OutputSpec> outputs;
431 std::string detector = doMFT ?
"mft" :
"its";
432 std::string objectname_default = detector +
"_time_deadmap.root";
435 "itsmft-deadmap-builder_" + detector,
438 AlgorithmSpec{adaptFromTask<ITSMFTDeadMapBuilder>(datasource, doMFT)},
439 Options{{
"tf-sampling", VariantType::Int, 350, {
"Process every Nth TF. Selection according to first TF orbit."}},
440 {
"tf-sampling-tolerance", VariantType::Int, 20, {
"Tolerance on the tf-sampling value (sliding window size)."}},
441 {
"tf-sampling-history-size", VariantType::Int, 1000, {
"Do not check if new TF is contained in a window that is older than N steps."}},
442 {
"tf-length", VariantType::Int, 32, {
"Orbits per TF."}},
443 {
"skip-static-map", VariantType::Bool,
false, {
"Do not fill static part of the map."}},
444 {
"no-group-its-lanes", VariantType::Bool,
false, {
"Do not group ITS OB chips into lanes."}},
445 {
"ccdb-url", VariantType::String,
"", {
"CCDB url. Ignored if endOfStream is processed."}},
446 {
"outfile", VariantType::String, objectname_default, {
"ROOT object file name."}},
447 {
"local-output", VariantType::Bool,
false, {
"Save ROOT tree file locally."}},
448 {
"output-dir", VariantType::String,
"./", {
"ROOT tree local output directory."}}}};
Definition of the ITSMFT compact cluster.
Definition of the ITSMFT time-dependend dead map.
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
T get(const char *key) const
void snapshot(const Output &spec, T const &object)
DataAllocator & outputs()
ConfigParamRegistry const & options()
InputRecord & inputs()
The inputs associated with this processing context.
ServiceRegistryRef services()
The services registry associated with this processing context.
TransitionHandlingState transitionState() const
static constexpr int getNChips()
number of chips per barrel
static constexpr Int_t getNChips()
void endOfStream(EndOfStreamContext &ec) final
This is invoked whenever we have an EndOfStream event.
void stop() final
This is invoked on stop.
void init(InitContext &ic) final
~ITSMFTDeadMapBuilder() override
void run(ProcessingContext &pc) final
ITSMFTDeadMapBuilder(std::string datasource, bool doMFT)
void fillMap(unsigned long firstOrbit, const std::vector< uint16_t > &deadVect)
void setMapVersion(std::string version)
unsigned long getEvolvingMapSize() const
GLsizei const GLchar *const * path
constexpr o2::header::DataOrigin gDataOriginMFT
constexpr o2::header::DataOrigin gDataOriginITS
long getCurrentTimestamp()
returns the timestamp in long corresponding to "now"
int adjustOverriddenEOV(CcdbApi &api, const CcdbObjectInfo &infoNew)
set EOV of overriden objects to SOV-1 of overriding one if it is allowed
std::vector< ConfigParamSpec > Options
o2::framework::DataProcessorSpec getITSMFTDeadMapBuilderSpec(std::string datasource, bool doMFT)
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 concat_string(Ts const &... ts)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"