Skip to content

Commit 24a3b24

Browse files
committed
Make HBFUtils singleton (ConfigurableParam)
1 parent 66744f4 commit 24a3b24

12 files changed

Lines changed: 42 additions & 47 deletions

File tree

Detectors/FIT/FT0/simulation/include/FT0Simulation/Digits2Raw.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class Digits2Raw
8888
std::ofstream mFileDest;
8989
std::array<o2::ft0::DataPageWriter, NPMs> mPages;
9090
o2::ft0::RawEventData mRawEventData;
91-
o2::raw::HBFUtils mSampler;
91+
const o2::raw::HBFUtils& mSampler = o2::raw::HBFUtils::Instance();
9292
o2::ft0::Triggers mTriggers;
9393
/////////////////////////////////////////////////
9494

Detectors/ITSMFT/ITS/macros/test/run_digi2rawVarPage_its.C

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,12 @@ void run_digi2rawVarPage_its(std::string outPrefix = "rawits", // prefix o
6161
m2r.setDefaultSinkName(outPrefix + ".raw");
6262
m2r.setMinMaxRUSW(ruSWMin, ruSWMax);
6363

64+
{
65+
// Attention: HBFUtils is a special singleton of ConfigurableParam type, cannot be set by detectors
66+
o2::raw::HBFUtils::updateFromString("HBFUtils.nHBFPerTF=256"); // this is default anyway
67+
}
68+
6469
m2r.getWriter().setSuperPageSize(1024 * 1024); // this is default anyway
65-
m2r.getWriter().getHBFUtils().setNOrbitsPerTF(256); // this is default anyway
6670

6771
m2r.setVerbosity(0);
6872

Detectors/MUON/MID/Raw/include/MIDRaw/Encoder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class Encoder
5858
std::map<uint16_t, LocalBoardRO> mROData{}; /// Map of data per board
5959
std::vector<raw::RawUnit> mBytes{}; /// Vector with encoded information
6060
CrateMapper mCrateMapper{}; /// Crate mapper
61-
o2::raw::HBFUtils mHBFUtils{}; /// Utility for HBF
61+
const o2::raw::HBFUtils& mHBFUtils = o2::raw::HBFUtils::Instance(); /// Utility for HBF
6262
InteractionRecord mLastIR{}; /// Last interaction record
6363
unsigned long int mMaxSuperpageSize{0x1000000}; /// Superpage size
6464
bool mSkipEmptyTFs{false}; /// Skip empty Time Frames

Detectors/MUON/MID/Raw/test/testRaw.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void doTest(const o2::mid::EventType& inEventType, const std::map<uint16_t, std:
7979
BOOST_AUTO_TEST_CASE(RawBuffer)
8080
{
8181
std::vector<o2::InteractionRecord> HBIRVec;
82-
o2::raw::HBFUtils hbfUtils;
82+
const o2::raw::HBFUtils& hbfUtils = o2::raw::HBFUtils::Instance();
8383
o2::InteractionRecord irFrom = hbfUtils.getFirstIR();
8484
o2::InteractionRecord ir(5, 4);
8585
hbfUtils.fillHBIRvector(HBIRVec, irFrom, ir);

Detectors/Raw/include/DetectorsRaw/HBFUtils.h

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#define ALICEO2_HBFSAMPLER_H
1616

1717
#include <Rtypes.h>
18+
#include "CommonUtils/ConfigurableParam.h"
19+
#include "CommonUtils/ConfigurableParamHelper.h"
1820
#include "CommonDataFormat/InteractionRecord.h"
1921
#include "Headers/RAWDataHeader.h"
2022
#include "CommonConstants/Triggers.h"
@@ -39,46 +41,41 @@ namespace raw
3941
using LinkSubSpec_t = uint32_t;
4042

4143
//_____________________________________________________________________
42-
class HBFUtils
43-
{
44+
struct HBFUtils : public o2::conf::ConfigurableParamHelper<HBFUtils> {
4445
using IR = o2::InteractionRecord;
4546

46-
public:
4747
static constexpr int GBTWord = 16; // length of GBT word
4848
static constexpr int MAXCRUPage = 512 * GBTWord;
4949

50-
HBFUtils() = default;
51-
HBFUtils(const IR& ir0) : mFirstIR(ir0) {}
52-
const IR& getFirstIR() const { return mFirstIR; }
53-
IR& getFirstIR() { return mFirstIR; }
50+
IR getFirstIR() const { return {bcFirst, orbitFirst}; }
5451

55-
void setNOrbitsPerTF(int n) { mNHBFPerTF = n > 0 ? n : 1; }
56-
int getNOrbitsPerTF() const { return mNHBFPerTF; }
52+
void setNOrbitsPerTF(int n) { nHBFPerTF = n > 0 ? n : 1; }
53+
int getNOrbitsPerTF() const { return nHBFPerTF; }
5754

5855
///< get IR corresponding to start of the HBF
59-
IR getIRHBF(uint32_t hbf) const { return mFirstIR + int64_t(hbf) * o2::constants::lhc::LHCMaxBunches; }
56+
IR getIRHBF(uint32_t hbf) const { return getFirstIR() + int64_t(hbf) * o2::constants::lhc::LHCMaxBunches; }
6057

6158
///< get IR corresponding to start of the TF
62-
IR getIRTF(uint32_t tf) const { return getIRHBF(tf * mNHBFPerTF); }
59+
IR getIRTF(uint32_t tf) const { return getIRHBF(tf * nHBFPerTF); }
6360

6461
///< get HBF ID corresponding to this IR
65-
int getHBF(const IR& rec) const;
62+
int64_t getHBF(const IR& rec) const;
6663

6764
///< get TF ID corresponding to this IR
68-
int getTF(const IR& rec) const { return getHBF(rec) / mNHBFPerTF; }
65+
int64_t getTF(const IR& rec) const { return getHBF(rec) / nHBFPerTF; }
6966

7067
///< get TF and HB (within TF) for this IR
7168
std::pair<int, int> getTFandHBinTF(const IR& rec) const
7269
{
7370
auto hbf = getHBF(rec);
74-
return std::pair<int, int>(hbf / mNHBFPerTF, hbf % mNHBFPerTF);
71+
return std::pair<int, int>(hbf / nHBFPerTF, hbf % nHBFPerTF);
7572
}
7673

7774
///< get TF and HB (abs) for this IR
7875
std::pair<int, int> getTFandHB(const IR& rec) const
7976
{
8077
auto hbf = getHBF(rec);
81-
return std::pair<int, int>(hbf / mNHBFPerTF, hbf);
78+
return std::pair<int, int>(hbf / nHBFPerTF, hbf);
8279
}
8380

8481
///< create RDH for given IR
@@ -126,7 +123,7 @@ class HBFUtils
126123
//-------------------------------------------------------------------------------------*/
127124
int fillHBIRvector(std::vector<IR>& dst, const IR& fromIR, const IR& toIR) const;
128125

129-
void print() const;
126+
void print() const { printKeyValues(true); }
130127

131128
// some fields of the same meaning have different names in the RDH of different versions
132129
static uint32_t getHBOrbit(const void* rdhP);
@@ -159,22 +156,22 @@ class HBFUtils
159156
static LinkSubSpec_t getSubSpec(const o2::header::RAWDataHeaderV4& rdh) { return getSubSpec(rdh.cruID, rdh.linkID, rdh.endPointID); }
160157
static LinkSubSpec_t getSubSpec(const o2::header::RAWDataHeaderV5& rdh) { return getSubSpec(rdh.cruID, rdh.linkID, rdh.endPointID); }
161158

162-
protected:
163-
int mNHBFPerTF = 1 + 0xff; // number of orbits per BC
164-
IR mFirstIR = {0, 0}; // 1st record of the 1st TF
159+
int nHBFPerTF = 1 + 0xff; // number of orbits per BC
160+
uint16_t bcFirst = 0; ///< BC of 1st TF
161+
uint32_t orbitFirst = 0; ///< orbit of 1st TF
165162

166-
ClassDefNV(HBFUtils, 1);
163+
O2ParamDef(HBFUtils, "HBFUtils");
167164
};
168165

169166
//_________________________________________________
170167
template <>
171168
inline void HBFUtils::updateRDH<o2::header::RAWDataHeaderV5>(o2::header::RAWDataHeaderV5& rdh, const o2::InteractionRecord& rec) const
172169
{
173170
auto tfhb = getTFandHBinTF(rec);
174-
rdh.bunchCrossing = mFirstIR.bc;
171+
rdh.bunchCrossing = bcFirst;
175172
rdh.orbit = rec.orbit;
176173
//
177-
if (rec.bc == mFirstIR.bc) { // if we are starting new HB, set the HB trigger flag
174+
if (rec.bc == bcFirst) { // if we are starting new HB, set the HB trigger flag
178175
rdh.triggerType |= o2::trigger::ORBIT | o2::trigger::HB;
179176
if (tfhb.second == 0) { // if we are starting new TF, set the TF trigger flag
180177
rdh.triggerType |= o2::trigger::TF;
@@ -190,10 +187,10 @@ inline void HBFUtils::updateRDH<o2::header::RAWDataHeaderV4>(o2::header::RAWData
190187
rdh.triggerBC = rec.bc;
191188
rdh.triggerOrbit = rec.orbit;
192189

193-
rdh.heartbeatBC = mFirstIR.bc;
190+
rdh.heartbeatBC = bcFirst;
194191
rdh.heartbeatOrbit = rec.orbit;
195192
//
196-
if (rec.bc == mFirstIR.bc) { // if we are starting new HB, set the HB trigger flag
193+
if (rec.bc == bcFirst) { // if we are starting new HB, set the HB trigger flag
197194
rdh.triggerType |= o2::trigger::ORBIT | o2::trigger::HB;
198195
if (tfhb.second == 0) { // if we are starting new TF, set the TF trigger flag
199196
rdh.triggerType |= o2::trigger::TF;

Detectors/Raw/include/DetectorsRaw/RawFileWriter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ class RawFileWriter
165165
mSuperPageSize = nbytes < 16 * HBFUtils::MAXCRUPage ? HBFUtils::MAXCRUPage : nbytes;
166166
}
167167

168-
HBFUtils& getHBFUtils() { return mHBFUtils; }
168+
const HBFUtils& getHBFUtils() const { return mHBFUtils; }
169169

170170
template <class T>
171171
void setCarryOverCallBack(const T* t)
@@ -242,7 +242,7 @@ class RawFileWriter
242242
Triggered };
243243

244244
IR mIRMax{0, 0}; // highest IR seen
245-
HBFUtils mHBFUtils;
245+
const HBFUtils& mHBFUtils = HBFUtils::Instance();
246246
std::unordered_map<LinkSubSpec_t, LinkData> mSSpec2Link; // mapping from subSpec to link
247247
std::unordered_map<std::string, FILE*> mFName2File; // mapping from filenames to actual files
248248

Detectors/Raw/src/DetectorsRawLinkDef.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@
2020
#pragma link C++ class o2::raw::RawFileWriter::LinkData + ;
2121

2222
#pragma link C++ class o2::raw::HBFUtils + ;
23+
#pragma link C++ class o2::conf::ConfigurableParamHelper < o2::raw::HBFUtils> + ;
2324

2425
#endif

Detectors/Raw/src/HBFUtils.cxx

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@
1717

1818
using namespace o2::raw;
1919

20+
O2ParamImpl(o2::raw::HBFUtils);
21+
2022
//_________________________________________________
21-
int HBFUtils::getHBF(const IR& rec) const
23+
int64_t HBFUtils::getHBF(const IR& rec) const
2224
{
2325
///< get HBF ID corresponding to this IR
24-
auto diff = rec.differenceInBC(mFirstIR);
26+
auto diff = rec.differenceInBC(getFirstIR());
2527
if (diff < 0) {
2628
LOG(ERROR) << "IR " << rec.bc << '/' << rec.orbit << " is ahead of the reference IR "
27-
<< mFirstIR.bc << '/' << mFirstIR.orbit;
29+
<< bcFirst << '/' << orbitFirst;
2830
throw std::runtime_error("Requested IR is ahead of the reference IR");
2931
}
3032
return diff / o2::constants::lhc::LHCMaxBunches;
@@ -37,7 +39,7 @@ int HBFUtils::fillHBIRvector(std::vector<IR>& dst, const IR& fromIR, const IR& t
3739
// BCs between interaction records "fromIR" and "toIR" (inclusive).
3840
dst.clear();
3941
int hb0 = getHBF(fromIR), hb1 = getHBF(toIR);
40-
if (fromIR.bc != mFirstIR.bc) { // unless we are just starting the HBF of fromIR, it was already counted
42+
if (fromIR.bc != bcFirst) { // unless we are just starting the HBF of fromIR, it was already counted
4143
hb0++;
4244
}
4345
for (int ihb = hb0; ihb <= hb1; ihb++) {
@@ -46,13 +48,6 @@ int HBFUtils::fillHBIRvector(std::vector<IR>& dst, const IR& fromIR, const IR& t
4648
return dst.size();
4749
}
4850

49-
//_________________________________________________
50-
void HBFUtils::print() const
51-
{
52-
LOGF(INFO, "%d HBF per TF, starting from ", mNHBFPerTF);
53-
mFirstIR.print();
54-
}
55-
5651
//_________________________________________________
5752
void HBFUtils::printRDH(const o2::header::RAWDataHeaderV4& rdh)
5853
{

Detectors/Raw/test/testHBFUtils.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ BOOST_AUTO_TEST_CASE(HBFUtils)
4343
LOG(INFO) << "Emulate RDHs for raw data between IRs " << irs.front() << " and " << irs.back();
4444

4545
// default sampler with BC filling like in TPC TDR, 50kHz
46-
o2::raw::HBFUtils sampler;
46+
const auto& sampler = o2::raw::HBFUtils::Instance();
4747

4848
uint8_t packetCounter = 0;
4949
std::vector<o2::InteractionRecord> HBIRVec;

Detectors/Raw/test/testRawReaderWriter.cxx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ struct SimpleRawWriter { // simple class to create detector payload for multiple
6161
writer.registerLink((icru << 8) + il, icru, il, 0, outFileName);
6262
}
6363
}
64-
6564
writer.setContinuousReadout(); // in case we want to issue StartOfContinuous trigger in the beginning
6665
writer.setCarryOverCallBack(this); // we want that writer to ask the detector code how to split large payloads
6766
writer.setEmptyPageCallBack(this); // we want the writer to ask the detector code what to put in empty HBFs

0 commit comments

Comments
 (0)