Skip to content

Commit f58ec5e

Browse files
committed
Opt.to detect TF from orbit and SOX info instead of TType
1 parent d623bb0 commit f58ec5e

8 files changed

Lines changed: 152 additions & 92 deletions

File tree

Detectors/Raw/README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,8 @@ o2-raw-file-reader-workflow
318318
--part-per-hbf FMQ parts per superpage (default) of HBF
319319
--raw-channel-config arg optional raw FMQ channel for non-DPL output
320320
--cache-data cache data at 1st reading, may require excessive memory!!!
321-
--detect-tf0 autodetect HBFUtils start Orbit/BC from 1st TF seen
321+
--detect-tf0 autodetect HBFUtils start Orbit/BC from 1st TF seen (at SOX)
322+
--calculate-tf-start calculate TF start from orbit instead of using TType
322323
--configKeyValues arg semicolon separated key=value strings
323324

324325
# to suppress various error checks / reporting
@@ -331,6 +332,9 @@ o2-raw-file-reader-workflow
331332
--nocheck-tf-per-link ignore /Number of TFs is less than expected/
332333
--nocheck-hbf-jump ignore /Wrong HBF orbit increment/
333334
--nocheck-no-spage-for-tf ignore /TF does not start by new superpage/
335+
--nocheck-no-sox ignore /No SOX found on 1st page/
336+
--nocheck-tf-start-mismatch ignore /Mismatch between TType-flagged and calculated new TF start/
337+
334338
```
335339
336340
The workflow takes an input from the configuration file (as described in `RawFileReader` section), reads the data and sends them as DPL messages
@@ -369,6 +373,7 @@ Options:
369373
-v [ --verbosity ] arg (=0) 1: long report, 2 or 3: print or dump all RDH
370374
-s [ --spsize ] arg (=1048576) nominal super-page size in bytes
371375
--detect-tf0 autodetect HBFUtils start Orbit/BC from 1st TF seen
376+
--calculate-tf-start calculate TF start from orbit instead of using TType
372377
--rorc impose RORC as default detector mode
373378
--configKeyValues arg semicolon separated key=value strings
374379
--nocheck-packet-increment ignore /Wrong RDH.packetCounter increment/
@@ -380,6 +385,8 @@ Options:
380385
--nocheck-tf-per-link ignore /Number of TFs is less than expected/
381386
--nocheck-hbf-jump ignore /Wrong HBF orbit increment/
382387
--nocheck-no-spage-for-tf ignore /TF does not start by new superpage/
388+
--nocheck-no-sox ignore /No SOX found on 1st page/
389+
--nocheck-tf-start-mismatch ignore /Mismatch between TType-flagged and calculated new TF start/
383390
(input files are optional if config file was provided)
384391
```
385392

Detectors/Raw/include/DetectorsRaw/RawFileReader.h

Lines changed: 66 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,22 @@ namespace raw
3434

3535
using IR = o2::InteractionRecord;
3636

37+
struct ReaderInp {
38+
std::string inifile{};
39+
std::string rawChannelConfig{};
40+
size_t spSize = 1024L * 1024L;
41+
size_t bufferSize = 1024L * 1024L;
42+
int loop = 1;
43+
uint32_t delay_us = 0;
44+
uint32_t errMap = 0xffffffff;
45+
uint32_t minTF = 0;
46+
uint32_t maxTF = 0xffffffff;
47+
bool partPerSP = true;
48+
bool cache = false;
49+
bool autodetectTF0 = false;
50+
bool preferCalcTF = false;
51+
};
52+
3753
class RawFileReader
3854
{
3955
using LinkSpec_t = uint64_t; // = (origin<<32) | LinkSubSpec
@@ -52,6 +68,8 @@ class RawFileReader
5268
ErrWrongNumberOfTF,
5369
ErrHBFJump,
5470
ErrNoSuperPageForTF,
71+
ErrNoSOX,
72+
ErrMismatchTF,
5573
NErrorsDefined
5674
};
5775

@@ -61,15 +79,17 @@ class RawFileReader
6179

6280
static constexpr std::string_view ErrNames[] = {
6381
// long names for error codes
64-
"Wrong RDH.packetCounter increment", // ErrWrongPacketCounterIncrement
65-
"Wrong RDH.pageCnt increment", // ErrWrongPageCounterIncrement
66-
"RDH.stop set of 1st HBF page", // ErrHBFStopOnFirstPage
67-
"New HBF starts w/o closing old one", // ErrHBFNoStop
68-
"Data does not start with TF/HBF", // ErrWrongFirstPage
69-
"Number of HBFs per TF not as expected", // ErrWrongHBFsPerTF
70-
"Number of TFs is less than expected", // ErrWrongNumberOfTF
71-
"Wrong HBF orbit increment", // ErrHBFJump
72-
"TF does not start by new superpage" // ErrNoSuperPageForTF
82+
"Wrong RDH.packetCounter increment", // ErrWrongPacketCounterIncrement
83+
"Wrong RDH.pageCnt increment", // ErrWrongPageCounterIncrement
84+
"RDH.stop set of 1st HBF page", // ErrHBFStopOnFirstPage
85+
"New HBF starts w/o closing old one", // ErrHBFNoStop
86+
"Data does not start with TF/HBF", // ErrWrongFirstPage
87+
"Number of HBFs per TF not as expected", // ErrWrongHBFsPerTF
88+
"Number of TFs is less than expected", // ErrWrongNumberOfTF
89+
"Wrong HBF orbit increment", // ErrHBFJump
90+
"TF does not start by new superpage", // ErrNoSuperPageForTF
91+
"No SOX found on 1st page", // ErrNoSOX
92+
"Mismatch between flagged and calculated new TF start" // ErrMismatchTF
7393
};
7494
static constexpr std::string_view ErrNamesShort[] = {
7595
// short names for error codes
@@ -81,7 +101,9 @@ class RawFileReader
81101
"hbf-per-tf", // ErrWrongHBFsPerTF
82102
"tf-per-link", // ErrWrongNumberOfTF
83103
"hbf-jump", // ErrHBFJump
84-
"no-spage-for-tf" // ErrNoSuperPageForTF
104+
"no-spage-for-tf", // ErrNoSuperPageForTF
105+
"no-sox", // ErrNoSOX
106+
"tf-start-mismatch" // ErrMismatchTF
85107
};
86108
static constexpr bool ErrCheckDefaults[] = {
87109
true, // ErrWrongPacketCounterIncrement
@@ -92,7 +114,9 @@ class RawFileReader
92114
true, // ErrWrongHBFsPerTF
93115
true, // ErrWrongNumberOfTF
94116
true, // ErrHBFJump
95-
false // ErrNoSuperPageForTF
117+
false, // ErrNoSuperPageForTF
118+
true, // ErrNoSOX
119+
true, // ErrMismatchTF
96120
};
97121
//================================================================================
98122

@@ -115,12 +139,12 @@ class RawFileReader
115139
StartHB = 0x1 << 1,
116140
StartSP = 0x1 << 2,
117141
EndHB = 0x1 << 3 };
118-
size_t offset = 0; //! where data of the block starts
119-
uint32_t size = 0; //! block size
120-
uint32_t tfID = 0; //! tf counter (from 0)
121-
IR ir = 0; //! ir starting the block
122-
uint16_t fileID = 0; //! file id where the block is located
123-
uint8_t flags = 0; //! different flags
142+
size_t offset = 0; //! where data of the block starts
143+
uint32_t size = 0; //! block size
144+
uint32_t tfID = 0; //! tf counter (from 0)
145+
IR ir = 0; //! ir starting the block
146+
uint16_t fileID = 0; //! file id where the block is located
147+
uint8_t flags = 0; //! different flags
124148
std::unique_ptr<char[]> dataCache; //! optional cache for fast access
125149
LinkBlock() = default;
126150
LinkBlock(int fid, size_t offs) : offset(offs), fileID(fid) {}
@@ -138,7 +162,8 @@ class RawFileReader
138162

139163
//=====================================================================================
140164
struct LinkData {
141-
RDHAny rdhl; //! RDH with the running info of the last RDH seen
165+
RDHAny rdhl; //! RDH with the running info of the last RDH seen
166+
o2::InteractionRecord irOfSOX{};
142167
LinkSpec_t spec = 0; //! Link subspec augmented by its origin
143168
LinkSubSpec_t subspec = 0; //! subspec according to DataDistribution
144169
uint32_t nTimeFrames = 0; //!
@@ -244,8 +269,11 @@ class RawFileReader
244269

245270
void imposeFirstTF(uint32_t orbit, uint16_t bc);
246271
void setTFAutodetect(FirstTFDetection v) { mFirstTFAutodetect = v; }
272+
void setPreferCalculatedTFStart(bool v) { mPreferCalculatedTFStart = v; }
247273
FirstTFDetection getTFAutodetect() const { return mFirstTFAutodetect; }
248274

275+
void setIROfSOX(const o2::InteractionRecord& ir);
276+
249277
static o2::header::DataOrigin getDataOrigin(const std::string& ors);
250278
static o2::header::DataDescription getDataDescription(const std::string& ors);
251279
static InputsMap parseInput(const std::string& confUri);
@@ -260,38 +288,36 @@ class RawFileReader
260288
static constexpr o2::header::DataOrigin DEFDataOrigin = o2::header::gDataOriginFLP;
261289
static constexpr o2::header::DataDescription DEFDataDescription = o2::header::gDataDescriptionRawData;
262290
static constexpr ReadoutCardType DEFCardType = CRU;
263-
264291
o2::header::DataOrigin mDefDataOrigin = DEFDataOrigin; //!
265292
o2::header::DataDescription mDefDataDescription = DEFDataDescription; //!
266293
ReadoutCardType mDefCardType = CRU; //!
267-
268-
std::vector<std::string> mFileNames; //! input file names
269-
std::vector<FILE*> mFiles; //! input file handlers
270-
std::vector<std::unique_ptr<char[]>> mFileBuffers; //! buffers for input files
271-
std::vector<OrigDescCard> mDataSpecs; //! data origin and description for every input file + readout card type
294+
std::vector<std::string> mFileNames; //! input file names
295+
std::vector<FILE*> mFiles; //! input file handlers
296+
std::vector<std::unique_ptr<char[]>> mFileBuffers; //! buffers for input files
297+
std::vector<OrigDescCard> mDataSpecs; //! data origin and description for every input file + readout card type
272298
bool mInitDone = false;
273299
bool mEmpty = true;
274-
std::unordered_map<LinkSpec_t, int> mLinkEntries; //! mapping between RDH specs and link entry in the mLinksData
275-
std::vector<LinkData> mLinksData; //! info on links data in the files
276-
std::vector<int> mOrderedIDs; //! links entries ordered in Specs
277-
uint32_t mMaxTFToRead = 0xffffffff; //! max TFs to process
278-
uint32_t mNTimeFrames = 0; //! total number of time frames
279-
uint32_t mNextTF2Read = 0; //! next TF to read
280-
uint32_t mOrbitMin = 0xffffffff; //! lowest orbit seen by any link
281-
uint32_t mOrbitMax = 0; //! highest orbit seen by any link
282-
size_t mBufferSize = 5 * 1024UL; //! size of the buffer for files reading
283-
int mNominalSPageSize = 0x1 << 20; //! expected super-page size in B
284-
int mCurrentFileID = 0; //! current file being processed
285-
long int mPosInFile = 0; //! current position in the file
286-
bool mMultiLinkFile = false; //! was > than 1 link seen in the file?
287-
bool mCacheData = false; //! cache data to block after 1st scan (may require excessive memory, use with care)
288-
uint32_t mCheckErrors = 0; //! mask for errors to check
300+
std::unordered_map<LinkSpec_t, int> mLinkEntries; //! mapping between RDH specs and link entry in the mLinksData
301+
std::vector<LinkData> mLinksData; //! info on links data in the files
302+
std::vector<int> mOrderedIDs; //! links entries ordered in Specs
303+
uint32_t mMaxTFToRead = 0xffffffff; //! max TFs to process
304+
uint32_t mNTimeFrames = 0; //! total number of time frames
305+
uint32_t mNextTF2Read = 0; //! next TF to read
306+
uint32_t mOrbitMin = 0xffffffff; //! lowest orbit seen by any link
307+
uint32_t mOrbitMax = 0; //! highest orbit seen by any link
308+
size_t mBufferSize = 5 * 1024UL; //! size of the buffer for files reading
309+
int mNominalSPageSize = 0x1 << 20; //! expected super-page size in B
310+
int mCurrentFileID = 0; //! current file being processed
311+
long int mPosInFile = 0; //! current position in the file
312+
bool mMultiLinkFile = false; //! was > than 1 link seen in the file?
313+
bool mCacheData = false; //! cache data to block after 1st scan (may require excessive memory, use with care)
314+
uint32_t mCheckErrors = 0; //! mask for errors to check
289315
FirstTFDetection mFirstTFAutodetect = FirstTFDetection::Disabled; //!
316+
bool mPreferCalculatedTFStart = false; //! prefer TFstart calculated via HBFUtils
290317
int mVerbosity = 0; //!
291318
ClassDefNV(RawFileReader, 1);
292319
};
293320

294-
295321
} // namespace raw
296322
} // namespace o2
297323

Detectors/Raw/src/RawFileReader.cxx

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -354,24 +354,50 @@ bool RawFileReader::LinkData::preprocessCRUPage(const RDHAny& rdh, bool newSPage
354354
ok = false;
355355
nErrors++;
356356
}
357-
357+
auto ir = RDHUtils::getTriggerIR(rdh);
358358
auto pageCnt = RDHUtils::getPageCounter(rdh);
359+
359360
if (pageCnt == 0) {
360-
if (cruDetector) {
361-
auto triggerType = RDHUtils::getTriggerType(rdh);
362-
newTF = (triggerType & o2::trigger::TF);
363-
newHB = (triggerType & (o2::trigger::ORBIT | o2::trigger::HB)) == (o2::trigger::ORBIT | o2::trigger::HB);
361+
auto triggerType = RDHUtils::getTriggerType(rdh);
362+
if (!nCRUPages) { // 1st page, expect SOX
364363
if (triggerType & o2::trigger::SOC) {
365364
continuousRO = true;
365+
irOfSOX = ir;
366366
} else if (triggerType & o2::trigger::SOT) {
367367
continuousRO = false;
368+
irOfSOX = ir;
369+
} else {
370+
if (reader->mCheckErrors & (0x1 << ErrNoSOX)) {
371+
LOG(ERROR) << ErrNames[ErrNoSOX];
372+
ok = false;
373+
nErrors++;
374+
}
375+
}
376+
if (!irOfSOX.isDummy() && reader->getTFAutodetect() == FirstTFDetection::Pending) {
377+
reader->imposeFirstTF(irOfSOX.orbit, irOfSOX.bc);
378+
}
379+
}
380+
auto newTFCalc = blocks.empty() || HBU.getTF(blocks.back().ir) < HBU.getTF(ir);
381+
if (cruDetector) {
382+
newTF = (triggerType & o2::trigger::TF);
383+
newHB = (triggerType & (o2::trigger::ORBIT | o2::trigger::HB)) == (o2::trigger::ORBIT | o2::trigger::HB);
384+
if (newTFCalc != newTF && (reader->mCheckErrors & (0x1 << ErrMismatchTF))) {
385+
LOG(ERROR) << ErrNames[ErrMismatchTF];
386+
ok = false;
387+
nErrors++;
388+
}
389+
if (reader->mPreferCalculatedTFStart) {
390+
newTF = newTFCalc;
391+
if (newTF) {
392+
newHB = true;
393+
}
368394
}
369395
} else {
370396
newHB = true; // in RORC detectors treat each trigger as a HBF
371-
if (blocks.empty() || HBU.getTF(blocks.back().ir) < HBU.getTF(RDHUtils::getTriggerIR(rdh))) {
397+
if (newTFCalc) {
372398
newTF = true;
399+
// continuousRO = false;
373400
}
374-
continuousRO = false;
375401
}
376402
} else if (reader->mCheckErrors & (0x1 << ErrWrongPageCounterIncrement)) {
377403
// check increasing pageCnt
@@ -687,7 +713,7 @@ bool RawFileReader::init()
687713
}
688714
}
689715
std::sort(mOrderedIDs.begin(), mOrderedIDs.end(),
690-
[& links = mLinksData](int a, int b) { return links[a].spec < links[b].spec; });
716+
[&links = mLinksData](int a, int b) { return links[a].spec < links[b].spec; });
691717

692718
size_t maxSP = 0, maxTF = 0;
693719

Detectors/Raw/src/RawFileReaderWorkflow.cxx

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,16 @@ namespace o2h = o2::header;
4545
class RawReaderSpecs : public o2f::Task
4646
{
4747
public:
48-
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, bool autodetectTF0 = false,
50-
size_t spSize = 1024L * 1024L, size_t buffSize = 5 * 1024UL,
51-
const std::string& rawChannelName = "")
52-
: 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)
48+
explicit RawReaderSpecs(const ReaderInp& rinp)
49+
: mLoop(rinp.loop < 0 ? INT_MAX : (rinp.loop < 1 ? 1 : rinp.loop)), mDelayUSec(rinp.delay_us), mMinTFID(rinp.minTF), mMaxTFID(rinp.maxTF), mPartPerSP(rinp.partPerSP), mReader(std::make_unique<o2::raw::RawFileReader>(rinp.inifile, 0, rinp.bufferSize)), mRawChannelName(rinp.rawChannelConfig)
5350
{
54-
mReader->setCheckErrors(errmap);
55-
mReader->setMaxTFToRead(maxTF);
56-
mReader->setNominalSPageSize(spSize);
57-
mReader->setCacheData(cache);
58-
mReader->setTFAutodetect(autodetectTF0 ? RawFileReader::FirstTFDetection::Pending : RawFileReader::FirstTFDetection::Disabled);
59-
LOG(INFO) << "Will preprocess files with buffer size of " << buffSize << " bytes";
51+
mReader->setCheckErrors(rinp.errMap);
52+
mReader->setMaxTFToRead(rinp.maxTF);
53+
mReader->setNominalSPageSize(rinp.spSize);
54+
mReader->setCacheData(rinp.cache);
55+
mReader->setTFAutodetect(rinp.autodetectTF0 ? RawFileReader::FirstTFDetection::Pending : RawFileReader::FirstTFDetection::Disabled);
56+
mReader->setPreferCalculatedTFStart(rinp.preferCalcTF);
57+
LOG(INFO) << "Will preprocess files with buffer size of " << rinp.bufferSize << " bytes";
6058
LOG(INFO) << "Number of loops over whole data requested: " << mLoop;
6159
for (int i = NTimers; i--;) {
6260
mTimer[i].Stop();
@@ -245,16 +243,15 @@ class RawReaderSpecs : public o2f::Task
245243
TStopwatch mTimer[NTimers];
246244
};
247245

248-
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, bool autodetectTF0, size_t spSize, size_t buffSize, const std::string& rawChannelConfig)
246+
o2f::DataProcessorSpec getReaderSpec(const ReaderInp& rinp)
250247
{
251248
// check which inputs are present in files to read
252249
o2f::DataProcessorSpec spec;
253250
spec.name = "raw-file-reader";
254251
std::string rawChannelName = "";
255-
if (rawChannelConfig.empty()) {
256-
if (!config.empty()) {
257-
auto conf = o2::raw::RawFileReader::parseInput(config);
252+
if (rinp.rawChannelConfig.empty()) {
253+
if (!rinp.inifile.empty()) {
254+
auto conf = o2::raw::RawFileReader::parseInput(rinp.inifile);
258255
for (const auto& entry : conf) {
259256
const auto& ordescard = entry.first;
260257
if (!entry.second.empty()) { // origin and decription for files to process
@@ -263,29 +260,28 @@ o2f::DataProcessorSpec getReaderSpec(std::string config, int loop, uint32_t dela
263260
}
264261
}
265262
} else {
266-
auto nameStart = rawChannelConfig.find("name=");
263+
auto nameStart = rinp.rawChannelConfig.find("name=");
267264
if (nameStart == std::string::npos) {
268265
throw std::runtime_error("raw channel name is not provided");
269266
}
270267
nameStart += strlen("name=");
271-
auto nameEnd = rawChannelConfig.find(",", nameStart + 1);
268+
auto nameEnd = rinp.rawChannelConfig.find(",", nameStart + 1);
272269
if (nameEnd == std::string::npos) {
273-
nameEnd = rawChannelConfig.size();
270+
nameEnd = rinp.rawChannelConfig.size();
274271
}
275-
rawChannelName = rawChannelConfig.substr(nameStart, nameEnd - nameStart);
276-
spec.options = {o2f::ConfigParamSpec{"channel-config", o2f::VariantType::String, rawChannelConfig, {"Out-of-band channel config"}}};
277-
LOG(INFO) << "Will send output to non-DPL channel " << rawChannelConfig;
272+
rawChannelName = rinp.rawChannelConfig.substr(nameStart, nameEnd - nameStart);
273+
spec.options = {o2f::ConfigParamSpec{"channel-config", o2f::VariantType::String, rinp.rawChannelConfig, {"Out-of-band channel config"}}};
274+
LOG(INFO) << "Will send output to non-DPL channel " << rinp.rawChannelConfig;
278275
}
279276

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

282279
return spec;
283280
}
284281

285-
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, bool autodetectTF0, size_t spSize, size_t buffSize, const std::string& rawChannelConfig)
282+
o2f::WorkflowSpec o2::raw::getRawFileReaderWorkflow(const ReaderInp& rinp)
287283
{
288284
o2f::WorkflowSpec specs;
289-
specs.emplace_back(getReaderSpec(inifile, loop, delay_us, errmap, minTF, maxTF, partPerSP, cache, autodetectTF0, spSize, buffSize, rawChannelConfig));
285+
specs.emplace_back(getReaderSpec(rinp));
290286
return specs;
291287
}

0 commit comments

Comments
 (0)