Skip to content

Commit c2fe6d3

Browse files
committed
With --detect-tf0 raw-reader will autodetect HBFUtils 1st IR
1 parent b62f04f commit c2fe6d3

7 files changed

Lines changed: 68 additions & 32 deletions

File tree

Detectors/Raw/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ o2-raw-file-reader-workflow
312312
--part-per-hbf FMQ parts per superpage (default) of HBF
313313
--raw-channel-config arg optional raw FMQ channel for non-DPL output
314314
--cache-data cache data at 1st reading, may require excessive memory!!!
315-
315+
--detect-tf0 autodetect HBFUtils start Orbit/BC from 1st TF seen
316316
--configKeyValues arg semicolon separated key=value strings
317317

318318
# to suppress various error checks / reporting
@@ -362,7 +362,9 @@ Options:
362362
-m [ --max-tf] arg (=0xffffffff) max. TF ID to read (counts from 0)
363363
-v [ --verbosity ] arg (=0) 1: long report, 2 or 3: print or dump all RDH
364364
-s [ --spsize ] arg (=1048576) nominal super-page size in bytes
365-
-t [ --hbfpertf ] arg (=256) nominal number of HBFs per TF
365+
--detect-tf0 autodetect HBFUtils start Orbit/BC from 1st TF seen
366+
--rorc impose RORC as default detector mode
367+
--configKeyValues arg semicolon separated key=value strings
366368
--nocheck-packet-increment ignore /Wrong RDH.packetCounter increment/
367369
--nocheck-page-increment ignore /Wrong RDH.pageCnt increment/
368370
--check-stop-on-page0 check /RDH.stop set of 1st HBF page/

Detectors/Raw/include/DetectorsRaw/RawFileReader.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ class RawFileReader
5454
ErrNoSuperPageForTF,
5555
NErrorsDefined
5656
};
57+
58+
enum class FirstTFDetection : int { Disabled,
59+
Pending,
60+
Done };
61+
5762
static constexpr std::string_view ErrNames[] = {
5863
// long names for error codes
5964
"Wrong RDH.packetCounter increment", // ErrWrongPacketCounterIncrement
@@ -156,7 +161,7 @@ class RawFileReader
156161

157162
LinkData() = default;
158163
template <typename H>
159-
LinkData(const H& rdh, const RawFileReader* r) : rdhl(rdh), reader(r)
164+
LinkData(const H& rdh, RawFileReader* r) : rdhl(rdh), reader(r)
160165
{
161166
}
162167
bool preprocessCRUPage(const RDHAny& rdh, bool newSPage);
@@ -174,12 +179,11 @@ class RawFileReader
174179
size_t skipNextTF();
175180

176181
void rewindToTF(uint32_t tf);
177-
178182
void print(bool verbose = false, const std::string& pref = "") const;
179183
std::string describe() const;
180184

181185
private:
182-
const RawFileReader* reader = nullptr; //!
186+
RawFileReader* reader = nullptr; //!
183187
};
184188

185189
//=====================================================================================
@@ -237,6 +241,10 @@ class RawFileReader
237241
o2::header::DataDescription getDefaultDataSpecification() const { return mDefDataDescription; }
238242
ReadoutCardType getDefaultReadoutCardType() const { return mDefCardType; }
239243

244+
void imposeFirstTF(uint32_t orbit, uint16_t bc);
245+
void setTFAutodetect(FirstTFDetection v) { mFirstTFAutodetect = v; }
246+
FirstTFDetection getTFAutodetect() const { return mFirstTFAutodetect; }
247+
240248
static o2::header::DataOrigin getDataOrigin(const std::string& ors);
241249
static o2::header::DataDescription getDataDescription(const std::string& ors);
242250
static InputsMap parseInput(const std::string& confUri);
@@ -277,8 +285,8 @@ class RawFileReader
277285
bool mMultiLinkFile = false; //! was > than 1 link seen in the file?
278286
bool mCacheData = false; //! cache data to block after 1st scan (may require excessive memory, use with care)
279287
uint32_t mCheckErrors = 0; //! mask for errors to check
280-
int mVerbosity = 0;
281-
288+
FirstTFDetection mFirstTFAutodetect = FirstTFDetection::Disabled; //!
289+
int mVerbosity = 0; //!
282290
ClassDefNV(RawFileReader, 1);
283291
};
284292

Detectors/Raw/src/RawFileReader.cxx

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -76,24 +76,24 @@ size_t RawFileReader::LinkData::getNextTFSuperPagesStat(std::vector<RawFileReade
7676
{
7777
// get stat. of superpages for this link in this TF. We treat as a start of a superpage the discontinuity in the link data, new TF
7878
// or continuous data exceeding a threshold (e.g. 1MB)
79-
int sz = 0;
80-
int nSP = 0;
81-
int ibl = nextBlock2Read, nbl = blocks.size(), nblPart = 0;
82-
parts.clear();
83-
while (ibl < nbl && (blocks[ibl].tfID == blocks[nextBlock2Read].tfID)) {
84-
if (ibl > nextBlock2Read && (blocks[ibl].testFlag(LinkBlock::StartSP) ||
85-
(sz + blocks[ibl].size) > reader->mNominalSPageSize ||
86-
(blocks[ibl - 1].offset + blocks[ibl - 1].size) < blocks[ibl].offset)) { // new superpage
79+
if (nextBlock2Read >= 0) { // negative nextBlock2Read signals absence of data
80+
int sz = 0, nSP = 0, ibl = nextBlock2Read, nbl = blocks.size(), nblPart = 0;
81+
parts.clear();
82+
while (ibl < nbl && (blocks[ibl].tfID == blocks[nextBlock2Read].tfID)) {
83+
if (ibl > nextBlock2Read && (blocks[ibl].testFlag(LinkBlock::StartSP) ||
84+
(sz + blocks[ibl].size) > reader->mNominalSPageSize ||
85+
(blocks[ibl - 1].offset + blocks[ibl - 1].size) < blocks[ibl].offset)) { // new superpage
86+
parts.emplace_back(RawFileReader::PartStat{sz, nblPart});
87+
sz = 0;
88+
nblPart = 0;
89+
}
90+
sz += blocks[ibl].size;
91+
nblPart++;
92+
ibl++;
93+
}
94+
if (sz) {
8795
parts.emplace_back(RawFileReader::PartStat{sz, nblPart});
88-
sz = 0;
89-
nblPart = 0;
9096
}
91-
sz += blocks[ibl].size;
92-
nblPart++;
93-
ibl++;
94-
}
95-
if (sz) {
96-
parts.emplace_back(RawFileReader::PartStat{sz, nblPart});
9797
}
9898
return parts.size();
9999
}
@@ -452,6 +452,14 @@ bool RawFileReader::LinkData::preprocessCRUPage(const RDHAny& rdh, bool newSPage
452452
bl.ir = hbIR;
453453
bl.tfID = HBU.getTF(hbIR); // nTimeFrames - 1;
454454
if (newTF) {
455+
if (reader->getTFAutodetect() == FirstTFDetection::Pending) { // impose first TF
456+
if (cruDetector) {
457+
reader->imposeFirstTF(hbIR.orbit, hbIR.bc);
458+
bl.tfID = HBU.getTF(hbIR); // update
459+
} else {
460+
throw std::runtime_error("HBFUtil first orbit/bc autodetection cannot be done with first link from CRORC detector");
461+
}
462+
}
455463
tfStartBlock.emplace_back(nbl, bl.tfID);
456464
nTimeFrames++;
457465
bl.setFlag(LinkBlock::StartTF);
@@ -714,7 +722,7 @@ bool RawFileReader::init()
714722
link.describe(), link.nTimeFrames, mNTimeFrames);
715723
}
716724
}
717-
LOGF(INFO, "First orbit: %d, Last orbit: %d", mOrbitMin, mOrbitMax);
725+
LOGF(INFO, "First orbit: %u, Last orbit: %u", mOrbitMin, mOrbitMax);
718726
LOGF(INFO, "Largest super-page: %zu B, largest TF: %zu B", maxSP, maxTF);
719727
if (!mCheckErrors) {
720728
LOGF(INFO, "Detailed data format check was disabled");
@@ -865,6 +873,19 @@ RawFileReader::InputsMap RawFileReader::parseInput(const std::string& confUri)
865873
return entries;
866874
}
867875

876+
void RawFileReader::imposeFirstTF(uint32_t orbit, uint16_t bc)
877+
{
878+
if (mFirstTFAutodetect != FirstTFDetection::Pending) {
879+
throw std::runtime_error("reader was not expecting imposing first TF");
880+
}
881+
auto& hbu = o2::raw::HBFUtils::Instance();
882+
o2::raw::HBFUtils::setValue("HBFUtils", "orbitFirst", orbit);
883+
o2::raw::HBFUtils::setValue("HBFUtils", "bcFirst", bc);
884+
LOG(INFO) << "Imposed data-driven TF start";
885+
mFirstTFAutodetect = FirstTFDetection::Done;
886+
hbu.printKeyValues();
887+
}
888+
868889
std::string RawFileReader::nochk_opt(RawFileReader::ErrTypes e)
869890
{
870891
std::string opt = ErrCheckDefaults[e] ? "nocheck-" : "check-";

Detectors/Raw/src/RawFileReaderWorkflow.cxx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class RawReaderSpecs : public o2f::Task
4646
{
4747
public:
4848
explicit RawReaderSpecs(const std::string& config, int loop = 1, uint32_t delay_us = 0,
49-
uint32_t errmap = 0xffffffff, uint32_t minTF = 0, uint32_t maxTF = 0xffffffff, bool partPerSP = true, bool cache = false,
49+
uint32_t errmap = 0xffffffff, uint32_t minTF = 0, uint32_t maxTF = 0xffffffff, bool partPerSP = true, bool cache = false, bool autodetectTF0 = false,
5050
size_t spSize = 1024L * 1024L, size_t buffSize = 5 * 1024UL,
5151
const std::string& rawChannelName = "")
5252
: mLoop(loop < 0 ? INT_MAX : (loop < 1 ? 1 : loop)), mDelayUSec(delay_us), mMinTFID(minTF), mMaxTFID(maxTF), mPartPerSP(partPerSP), mReader(std::make_unique<o2::raw::RawFileReader>(config, 0, buffSize)), mRawChannelName(rawChannelName)
@@ -55,6 +55,7 @@ class RawReaderSpecs : public o2f::Task
5555
mReader->setMaxTFToRead(maxTF);
5656
mReader->setNominalSPageSize(spSize);
5757
mReader->setCacheData(cache);
58+
mReader->setTFAutodetect(autodetectTF0 ? RawFileReader::FirstTFDetection::Pending : RawFileReader::FirstTFDetection::Disabled);
5859
LOG(INFO) << "Will preprocess files with buffer size of " << buffSize << " bytes";
5960
LOG(INFO) << "Number of loops over whole data requested: " << mLoop;
6061
for (int i = NTimers; i--;) {
@@ -246,7 +247,7 @@ class RawReaderSpecs : public o2f::Task
246247
};
247248

248249
o2f::DataProcessorSpec getReaderSpec(std::string config, int loop, uint32_t delay_us, uint32_t errmap,
249-
uint32_t minTF, uint32_t maxTF, bool partPerSP, bool cache, size_t spSize, size_t buffSize, const std::string& rawChannelConfig)
250+
uint32_t minTF, uint32_t maxTF, bool partPerSP, bool cache, bool autodetectTF0, size_t spSize, size_t buffSize, const std::string& rawChannelConfig)
250251
{
251252
// check which inputs are present in files to read
252253
o2f::DataProcessorSpec spec;
@@ -277,15 +278,15 @@ o2f::DataProcessorSpec getReaderSpec(std::string config, int loop, uint32_t dela
277278
LOG(INFO) << "Will send output to non-DPL channel " << rawChannelConfig;
278279
}
279280

280-
spec.algorithm = o2f::adaptFromTask<RawReaderSpecs>(config, loop, delay_us, errmap, minTF, maxTF, partPerSP, cache, spSize, buffSize, rawChannelName);
281+
spec.algorithm = o2f::adaptFromTask<RawReaderSpecs>(config, loop, delay_us, errmap, minTF, maxTF, partPerSP, cache, autodetectTF0, spSize, buffSize, rawChannelName);
281282

282283
return spec;
283284
}
284285

285286
o2f::WorkflowSpec o2::raw::getRawFileReaderWorkflow(std::string inifile, int loop, uint32_t delay_us, uint32_t errmap, uint32_t minTF, uint32_t maxTF,
286-
bool partPerSP, bool cache, size_t spSize, size_t buffSize, const std::string& rawChannelConfig)
287+
bool partPerSP, bool cache, bool autodetectTF0, size_t spSize, size_t buffSize, const std::string& rawChannelConfig)
287288
{
288289
o2f::WorkflowSpec specs;
289-
specs.emplace_back(getReaderSpec(inifile, loop, delay_us, errmap, minTF, maxTF, partPerSP, cache, spSize, buffSize, rawChannelConfig));
290+
specs.emplace_back(getReaderSpec(inifile, loop, delay_us, errmap, minTF, maxTF, partPerSP, cache, autodetectTF0, spSize, buffSize, rawChannelConfig));
290291
return specs;
291292
}

Detectors/Raw/src/RawFileReaderWorkflow.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace raw
2222
{
2323

2424
framework::WorkflowSpec getRawFileReaderWorkflow(std::string inifile, int loop = 1, uint32_t delay_us = 0, uint32_t errMap = 0xffffffff,
25-
uint32_t minTF = 0, uint32_t maxTF = 0xffffffff, bool partPerSP = true, bool cache = false,
25+
uint32_t minTF = 0, uint32_t maxTF = 0xffffffff, bool partPerSP = true, bool cache = false, bool autodetectTF0 = false,
2626
size_t spSize = 1024L * 1024L, size_t bufferSize = 1024L * 1024L,
2727
const std::string& rawChannelConfig = "");
2828

Detectors/Raw/src/rawfile-reader-workflow.cxx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ void customize(std::vector<o2::framework::ConfigParamSpec>& workflowOptions)
3333
options.push_back(ConfigParamSpec{"part-per-hbf", VariantType::Bool, false, {"FMQ parts per superpage (default) of HBF"}});
3434
options.push_back(ConfigParamSpec{"raw-channel-config", VariantType::String, "", {"optional raw FMQ channel for non-DPL output"}});
3535
options.push_back(ConfigParamSpec{"cache-data", VariantType::Bool, false, {"cache data at 1st reading, may require excessive memory!!!"}});
36+
options.push_back(ConfigParamSpec{"detect-tf0", VariantType::Bool, false, {"autodetect HBFUtils start Orbit/BC from 1st TF seen"}});
3637
options.push_back(ConfigParamSpec{"configKeyValues", VariantType::String, "", {"semicolon separated key=value strings"}});
3738
// options for error-check suppression
3839

@@ -57,6 +58,7 @@ WorkflowSpec defineDataProcessing(ConfigContext const& configcontext)
5758
uint64_t spSize = uint64_t(configcontext.options().get<int64_t>("super-page-size"));
5859
bool partPerSP = !configcontext.options().get<bool>("part-per-hbf");
5960
bool cache = configcontext.options().get<bool>("cache-data");
61+
bool autodetectTF0 = configcontext.options().get<bool>("detect-tf0");
6062
std::string rawChannelConfig = configcontext.options().get<std::string>("raw-channel-config");
6163
uint32_t errmap = 0;
6264
for (int i = RawFileReader::NErrorsDefined; i--;) {
@@ -69,5 +71,5 @@ WorkflowSpec defineDataProcessing(ConfigContext const& configcontext)
6971
o2::conf::ConfigurableParam::updateFromString(configcontext.options().get<std::string>("configKeyValues"));
7072
uint32_t delay_us = uint32_t(1e6 * configcontext.options().get<float>("delay")); // delay in microseconds
7173

72-
return std::move(o2::raw::getRawFileReaderWorkflow(inifile, loop, delay_us, errmap, minTF, maxTF, partPerSP, cache, spSize, buffSize, rawChannelConfig));
74+
return std::move(o2::raw::getRawFileReaderWorkflow(inifile, loop, delay_us, errmap, minTF, maxTF, partPerSP, cache, autodetectTF0, spSize, buffSize, rawChannelConfig));
7375
}

Detectors/Raw/src/rawfileCheck.cxx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ int main(int argc, char* argv[])
3939
desc_add_option("verbosity,v", bpo::value<int>()->default_value(reader.getVerbosity()), "1: long report, 2 or 3: print or dump all RDH");
4040
desc_add_option("spsize,s", bpo::value<int>()->default_value(reader.getNominalSPageSize()), "nominal super-page size in bytes");
4141
desc_add_option("buffer-size,b", bpo::value<size_t>()->default_value(reader.getNominalSPageSize()), "buffer size for files preprocessing");
42+
desc_add_option("detect-tf0", "autodetect HBFUtils start Orbit/BC from 1st TF seen");
4243
desc_add_option("rorc", "impose RORC as default detector mode");
4344
desc_add_option("configKeyValues", bpo::value(&configKeyValues)->default_value(""), "semicolon separated key=value strings");
4445
for (int i = 0; i < RawFileReader::NErrorsDefined; i++) {
@@ -84,13 +85,14 @@ int main(int argc, char* argv[])
8485
RawFileReader::RDH rdh;
8586
LOG(INFO) << "RawDataHeader v" << int(rdh.version) << " is assumed";
8687

87-
o2::raw::RawFileReader::ReadoutCardType rocard = vm.count("rorc") ? o2::raw::RawFileReader::ReadoutCardType::RORC : o2::raw::RawFileReader::ReadoutCardType::CRU;
88+
RawFileReader::ReadoutCardType rocard = vm.count("rorc") ? o2::raw::RawFileReader::ReadoutCardType::RORC : o2::raw::RawFileReader::ReadoutCardType::CRU;
8889

8990
reader.setVerbosity(vm["verbosity"].as<int>());
9091
reader.setNominalSPageSize(vm["spsize"].as<int>());
9192
reader.setMaxTFToRead(vm["max-tf"].as<uint32_t>());
9293
reader.setBufferSize(vm["buffer-size"].as<size_t>());
9394
reader.setDefaultReadoutCardType(rocard);
95+
reader.setTFAutodetect(vm.count("detect-tf0") ? RawFileReader::FirstTFDetection::Pending : RawFileReader::FirstTFDetection::Disabled);
9496
uint32_t errmap = 0;
9597
for (int i = RawFileReader::NErrorsDefined; i--;) {
9698
auto ei = RawFileReader::ErrTypes(i);

0 commit comments

Comments
 (0)