Skip to content

Commit 1c3a90b

Browse files
committed
CTFCoderBase will hold detectorID
1 parent a6be9bf commit 1c3a90b

13 files changed

Lines changed: 55 additions & 50 deletions

File tree

Detectors/Base/include/DetectorsBase/CTFCoderBase.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,18 @@ class CTFCoderBase
4040
Decoder };
4141

4242
CTFCoderBase() = delete;
43-
CTFCoderBase(int n) : mCoders(n) {}
43+
CTFCoderBase(int n, DetID det) : mCoders(n), mDet(det) {}
4444

45-
std::unique_ptr<TFile> loadDictionaryTreeFile(const std::string& dictPath, DetID det, bool mayFail = false);
45+
std::unique_ptr<TFile> loadDictionaryTreeFile(const std::string& dictPath, bool mayFail = false);
4646

4747
template <typename CTF>
48-
std::vector<char> readDictionaryFromFile(const std::string& dictPath, DetID det, bool mayFail = false)
48+
std::vector<char> readDictionaryFromFile(const std::string& dictPath, bool mayFail = false)
4949
{
5050
std::vector<char> bufVec;
51-
auto fileDict = loadDictionaryTreeFile(dictPath, det, mayFail);
51+
auto fileDict = loadDictionaryTreeFile(dictPath, mayFail);
5252
if (fileDict) {
5353
std::unique_ptr<TTree> tree((TTree*)fileDict->Get(std::string(o2::base::NameConf::CTFDICT).c_str()));
54-
CTF::readFromTree(bufVec, *tree.get(), det.getName());
54+
CTF::readFromTree(bufVec, *tree.get(), mDet.getName());
5555
}
5656
return bufVec;
5757
}
@@ -74,7 +74,10 @@ class CTFCoderBase
7474
}
7575

7676
protected:
77+
std::string getPrefix() const { return o2::utils::concat_string(mDet.getName(), "_CTF: "); }
78+
7779
std::vector<std::shared_ptr<void>> mCoders; // encoders/decoders
80+
DetID mDet;
7881

7982
ClassDefNV(CTFCoderBase, 1);
8083
};

Detectors/Base/src/CTFCoderBase.cxx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@ bool readFromTree(TTree& tree, const std::string brname, T& dest, int ev = 0)
3131
return false;
3232
}
3333

34-
std::unique_ptr<TFile> CTFCoderBase::loadDictionaryTreeFile(const std::string& dictPath, DetID det, bool mayFail)
34+
std::unique_ptr<TFile> CTFCoderBase::loadDictionaryTreeFile(const std::string& dictPath, bool mayFail)
3535
{
3636
TDirectory* curd = gDirectory;
3737
std::unique_ptr<TFile> fileDict(TFile::Open(dictPath.c_str()));
3838
if (!fileDict || fileDict->IsZombie()) {
3939
if (mayFail) {
40-
LOG(INFO) << "CTF dictionary file " << dictPath << " for detector " << det.getName() << " is absent, will use dictionaries stored in CTF";
40+
LOG(INFO) << "CTF dictionary file " << dictPath << " for detector " << mDet.getName() << " is absent, will use dictionaries stored in CTF";
4141
fileDict.reset();
4242
return std::move(fileDict);
4343
}
44-
LOG(ERROR) << "Failed to open CTF dictionary file " << dictPath << " for detector " << det.getName();
44+
LOG(ERROR) << "Failed to open CTF dictionary file " << dictPath << " for detector " << mDet.getName();
4545
throw std::runtime_error("Failed to open dictionary file");
4646
}
4747
auto tnm = std::string(o2::base::NameConf::CTFDICT);
@@ -52,15 +52,15 @@ std::unique_ptr<TFile> CTFCoderBase::loadDictionaryTreeFile(const std::string& d
5252
throw std::runtime_error("Did not fine CTF dictionary tree in the file");
5353
}
5454
CTFHeader ctfHeader;
55-
if (!readFromTree(*tree.get(), "CTFHeader", ctfHeader) || !ctfHeader.detectors[det]) {
55+
if (!readFromTree(*tree.get(), "CTFHeader", ctfHeader) || !ctfHeader.detectors[mDet]) {
5656
tree.reset();
5757
fileDict.reset();
58-
LOG(ERROR) << "Did not find CTF dictionary header or Detector " << det.getName() << " in it";
58+
LOG(ERROR) << "Did not find CTF dictionary header or Detector " << mDet.getName() << " in it";
5959
if (!mayFail) {
6060
throw std::runtime_error("did not find CTFHeader with needed detector");
6161
}
6262
} else {
63-
LOG(INFO) << "Found CTF dictionary for " << det.getName() << " in " << dictPath;
63+
LOG(INFO) << "Found CTF dictionary for " << mDet.getName() << " in " << dictPath;
6464
}
6565
return fileDict;
6666
}

Detectors/CTF/test/test_ctf_io_itsmft.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ BOOST_AUTO_TEST_CASE(CompressedClustersTest)
7070
sw.Start();
7171
std::vector<o2::ctf::BufferType> vec;
7272
{
73-
CTFCoder coder;
73+
CTFCoder coder(o2::detectors::DetID::ITS);
7474
coder.encode(vec, rofRecVec, cclusVec, pattVec); // compress
7575
}
7676
sw.Stop();
@@ -107,7 +107,7 @@ BOOST_AUTO_TEST_CASE(CompressedClustersTest)
107107
sw.Start();
108108
const auto ctfImage = o2::itsmft::CTF::getImage(vec.data());
109109
{
110-
CTFCoder coder;
110+
CTFCoder coder(o2::detectors::DetID::ITS);
111111
coder.decode(ctfImage, rofRecVecD, cclusVecD, pattVecD); // decompress
112112
}
113113
sw.Stop();

Detectors/FIT/FT0/reconstruction/include/FT0Reconstruction/CTFCoder.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace ft0
3636
class CTFCoder : public o2::ctf::CTFCoderBase
3737
{
3838
public:
39-
CTFCoder() : o2::ctf::CTFCoderBase(CTF::getNBlocks()) {}
39+
CTFCoder() : o2::ctf::CTFCoderBase(CTF::getNBlocks(), o2::detectors::DetID::FT0) {}
4040
~CTFCoder() = default;
4141

4242
/// entropy-encode digits to buffer with CTF
@@ -101,7 +101,7 @@ void CTFCoder::encode(VEC& buff, const gsl::span<const Digit>& digitVec, const g
101101
ENCODEFT0(cd.cfdTime, CTF::BLC_cfdTime, o2::rans::ProbabilityBits16Bit);
102102
ENCODEFT0(cd.qtcAmpl, CTF::BLC_qtcAmpl, o2::rans::ProbabilityBits25Bit);
103103
// clang-format on
104-
CTF::get(buff.data())->print("FT0 done: ");
104+
CTF::get(buff.data())->print(getPrefix());
105105
}
106106

107107
/// decode entropy-encoded clusters to standard compact clusters
@@ -110,6 +110,7 @@ void CTFCoder::decode(const CTF::base& ec, VDIG& digitVec, VCHAN& channelVec)
110110
{
111111
CompressedDigits cd;
112112
cd.header = ec.getHeader();
113+
ec.print(getPrefix());
113114
#define DECODEFT0(part, slot) ec.decode(part, int(slot), mCoders[int(slot)].get())
114115
// clang-format off
115116
DECODEFT0(cd.trigger, CTF::BLC_trigger);

Detectors/FIT/FT0/reconstruction/src/CTFCoder.cxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ using namespace o2::ft0;
2222
// Register encoded data in the tree (Fill is not called, will be done by caller)
2323
void CTFCoder::appendToTree(TTree& tree, CTF& ec)
2424
{
25-
ec.appendToTree(tree, o2::detectors::DetID::getName(o2::detectors::DetID::FT0));
25+
ec.appendToTree(tree, mDet.getName());
2626
}
2727

2828
///___________________________________________________________________________________
@@ -32,7 +32,7 @@ void CTFCoder::readFromTree(TTree& tree, int entry,
3232
{
3333
assert(entry >= 0 && entry < tree.GetEntries());
3434
CTF ec;
35-
ec.readFromTree(tree, o2::detectors::DetID::getName(o2::detectors::DetID::FT0), entry);
35+
ec.readFromTree(tree, mDet.getName(), entry);
3636
decode(ec, digitVec, channelVec);
3737
}
3838

@@ -100,7 +100,7 @@ void CTFCoder::compress(CompressedDigits& cd, const gsl::span<const Digit>& digi
100100
void CTFCoder::createCoders(const std::string& dictPath, o2::ctf::CTFCoderBase::OpType op)
101101
{
102102
bool mayFail = true; // RS FIXME if the dictionary file is not there, do not produce exception
103-
auto buff = readDictionaryFromFile<CTF>(dictPath, o2::detectors::DetID::FT0, mayFail);
103+
auto buff = readDictionaryFromFile<CTF>(dictPath, mayFail);
104104
if (!buff.size()) {
105105
if (mayFail) {
106106
return;

Detectors/ITSMFT/common/reconstruction/include/ITSMFTReconstruction/CTFCoder.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ namespace itsmft
3535
class CTFCoder : public o2::ctf::CTFCoderBase
3636
{
3737
public:
38-
CTFCoder() : o2::ctf::CTFCoderBase(CTF::getNBlocks()) {}
38+
CTFCoder(o2::detectors::DetID det) : o2::ctf::CTFCoderBase(CTF::getNBlocks(), det) {}
3939
~CTFCoder() = default;
4040

4141
/// entropy-encode clusters to buffer with CTF
@@ -46,7 +46,7 @@ class CTFCoder : public o2::ctf::CTFCoderBase
4646
template <typename VROF, typename VCLUS, typename VPAT>
4747
void decode(const CTF::base& ec, VROF& rofRecVec, VCLUS& cclusVec, VPAT& pattVec);
4848

49-
void createCoders(const std::string& dictPath, o2::detectors::DetID det, o2::ctf::CTFCoderBase::OpType op);
49+
void createCoders(const std::string& dictPath, o2::ctf::CTFCoderBase::OpType op);
5050

5151
private:
5252
/// compres compact clusters to CompressedClusters
@@ -56,8 +56,8 @@ class CTFCoder : public o2::ctf::CTFCoderBase
5656
template <typename VROF, typename VCLUS, typename VPAT>
5757
void decompress(const CompressedClusters& cc, VROF& rofRecVec, VCLUS& cclusVec, VPAT& pattVec);
5858

59-
void appendToTree(TTree& tree, o2::detectors::DetID id, CTF& ec);
60-
void readFromTree(TTree& tree, int entry, o2::detectors::DetID id, std::vector<ROFRecord>& rofRecVec, std::vector<CompClusterExt>& cclusVec, std::vector<unsigned char>& pattVec);
59+
void appendToTree(TTree& tree, CTF& ec);
60+
void readFromTree(TTree& tree, int entry, std::vector<ROFRecord>& rofRecVec, std::vector<CompClusterExt>& cclusVec, std::vector<unsigned char>& pattVec);
6161

6262
protected:
6363
ClassDefNV(CTFCoder, 1);
@@ -104,7 +104,7 @@ void CTFCoder::encode(VEC& buff, const gsl::span<const ROFRecord>& rofRecVec, co
104104
ENCODEITSMFT(cc.pattID, CTF::BLCpattID, o2::rans::ProbabilityBits16Bit);
105105
ENCODEITSMFT(cc.pattMap, CTF::BLCpattMap, o2::rans::ProbabilityBits16Bit);
106106
// clang-format on
107-
CTF::get(buff.data())->print("ITS done: ");
107+
CTF::get(buff.data())->print(getPrefix());
108108
}
109109

110110
/// decode entropy-encoded clusters to standard compact clusters
@@ -113,6 +113,7 @@ void CTFCoder::decode(const CTF::base& ec, VROF& rofRecVec, VCLUS& cclusVec, VPA
113113
{
114114
CompressedClusters cc;
115115
cc.header = ec.getHeader();
116+
ec.print(getPrefix());
116117
#define DECODEITSMFT(part, slot) ec.decode(part, int(slot), mCoders[int(slot)].get())
117118
// clang-format off
118119
DECODEITSMFT(cc.firstChipROF, CTF::BLCfirstChipROF);

Detectors/ITSMFT/common/reconstruction/src/CTFCoder.cxx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,18 @@ using namespace o2::itsmft;
2020

2121
///___________________________________________________________________________________
2222
// Register encoded data in the tree (Fill is not called, will be done by caller)
23-
void CTFCoder::appendToTree(TTree& tree, o2::detectors::DetID id, CTF& ec)
23+
void CTFCoder::appendToTree(TTree& tree, CTF& ec)
2424
{
25-
ec.appendToTree(tree, id.getName());
25+
ec.appendToTree(tree, mDet.getName());
2626
}
2727

2828
///___________________________________________________________________________________
2929
// extract and decode data from the tree
30-
void CTFCoder::readFromTree(TTree& tree, int entry, o2::detectors::DetID id,
31-
std::vector<ROFRecord>& rofRecVec, std::vector<CompClusterExt>& cclusVec, std::vector<unsigned char>& pattVec)
30+
void CTFCoder::readFromTree(TTree& tree, int entry, std::vector<ROFRecord>& rofRecVec, std::vector<CompClusterExt>& cclusVec, std::vector<unsigned char>& pattVec)
3231
{
3332
assert(entry >= 0 && entry < tree.GetEntries());
3433
CTF ec;
35-
ec.readFromTree(tree, id.getName(), entry);
34+
ec.readFromTree(tree, mDet.getName(), entry);
3635
decode(ec, rofRecVec, cclusVec, pattVec);
3736
}
3837

@@ -121,10 +120,10 @@ void CTFCoder::compress(CompressedClusters& cc,
121120
}
122121

123122
///________________________________
124-
void CTFCoder::createCoders(const std::string& dictPath, o2::detectors::DetID det, o2::ctf::CTFCoderBase::OpType op)
123+
void CTFCoder::createCoders(const std::string& dictPath, o2::ctf::CTFCoderBase::OpType op)
125124
{
126125
bool mayFail = true; // RS FIXME if the dictionary file is not there, do not produce exception
127-
auto buff = readDictionaryFromFile<CTF>(dictPath, det, mayFail);
126+
auto buff = readDictionaryFromFile<CTF>(dictPath, mayFail);
128127
if (!buff.size()) {
129128
if (mayFail) {
130129
return;

Detectors/ITSMFT/common/workflow/src/EntropyDecoderSpec.cxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ namespace o2
2424
namespace itsmft
2525
{
2626

27-
EntropyDecoderSpec::EntropyDecoderSpec(o2::header::DataOrigin orig) : mOrigin(orig)
27+
EntropyDecoderSpec::EntropyDecoderSpec(o2::header::DataOrigin orig)
28+
: mOrigin(orig), mCTFCoder(orig == o2::header::gDataOriginITS ? o2::detectors::DetID::ITS : o2::detectors::DetID::MFT)
2829
{
2930
assert(orig == o2::header::gDataOriginITS || orig == o2::header::gDataOriginMFT);
3031
mTimer.Stop();
@@ -35,8 +36,7 @@ void EntropyDecoderSpec::init(o2::framework::InitContext& ic)
3536
{
3637
std::string dictPath = ic.options().get<std::string>((mOrigin == o2::header::gDataOriginITS) ? "its-ctf-dictionary" : "mft-ctf-dictionary");
3738
if (!dictPath.empty() && dictPath != "none") {
38-
mCTFCoder.createCoders(dictPath, mOrigin == o2::header::gDataOriginITS ? o2::detectors::DetID::ITS : o2::detectors::DetID::MFT,
39-
o2::ctf::CTFCoderBase::OpType::Decoder);
39+
mCTFCoder.createCoders(dictPath, o2::ctf::CTFCoderBase::OpType::Decoder);
4040
}
4141
}
4242

Detectors/ITSMFT/common/workflow/src/EntropyEncoderSpec.cxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ namespace o2
2525
namespace itsmft
2626
{
2727

28-
EntropyEncoderSpec::EntropyEncoderSpec(o2::header::DataOrigin orig) : mOrigin(orig)
28+
EntropyEncoderSpec::EntropyEncoderSpec(o2::header::DataOrigin orig)
29+
: mOrigin(orig), mCTFCoder(orig == o2::header::gDataOriginITS ? o2::detectors::DetID::ITS : o2::detectors::DetID::MFT)
2930
{
3031
assert(orig == o2::header::gDataOriginITS || orig == o2::header::gDataOriginMFT);
3132
mTimer.Stop();
@@ -36,8 +37,7 @@ void EntropyEncoderSpec::init(o2::framework::InitContext& ic)
3637
{
3738
std::string dictPath = ic.options().get<std::string>((mOrigin == o2::header::gDataOriginITS) ? "its-ctf-dictionary" : "mft-ctf-dictionary");
3839
if (!dictPath.empty() && dictPath != "none") {
39-
mCTFCoder.createCoders(dictPath, mOrigin == o2::header::gDataOriginITS ? o2::detectors::DetID::ITS : o2::detectors::DetID::MFT,
40-
o2::ctf::CTFCoderBase::OpType::Encoder);
40+
mCTFCoder.createCoders(dictPath, o2::ctf::CTFCoderBase::OpType::Encoder);
4141
}
4242
}
4343

Detectors/TOF/reconstruction/include/TOFReconstruction/CTFCoder.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ namespace tof
3434
class CTFCoder : public o2::ctf::CTFCoderBase
3535
{
3636
public:
37-
CTFCoder() : o2::ctf::CTFCoderBase(CTF::getNBlocks()) {}
37+
CTFCoder() : o2::ctf::CTFCoderBase(CTF::getNBlocks(), o2::detectors::DetID::TOF) {}
3838
~CTFCoder() = default;
3939

4040
/// entropy-encode clusters to buffer with CTF
@@ -55,8 +55,8 @@ class CTFCoder : public o2::ctf::CTFCoderBase
5555
template <typename VROF, typename VDIG, typename VPAT>
5656
void decompress(const CompressedInfos& cc, VROF& rofRecVec, VDIG& cdigVec, VPAT& pattVec);
5757

58-
void appendToTree(TTree& tree, o2::detectors::DetID id, CTF& ec);
59-
void readFromTree(TTree& tree, int entry, o2::detectors::DetID id, std::vector<ReadoutWindowData>& rofRecVec, std::vector<Digit>& cdigVec, std::vector<uint32_t>& pattVec);
58+
void appendToTree(TTree& tree, CTF& ec);
59+
void readFromTree(TTree& tree, int entry, std::vector<ReadoutWindowData>& rofRecVec, std::vector<Digit>& cdigVec, std::vector<uint32_t>& pattVec);
6060

6161
protected:
6262
ClassDefNV(CTFCoder, 1);
@@ -103,14 +103,16 @@ void CTFCoder::encode(VEC& buff, const gsl::span<const ReadoutWindowData>& rofRe
103103
ENCODETOF(cc.tot, CTF::BLCtot, o2::rans::ProbabilityBits16Bit);
104104
ENCODETOF(cc.pattMap, CTF::BLCpattMap, o2::rans::ProbabilityBits16Bit);
105105
// clang-format on
106-
CTF::get(buff.data())->print("TOF done: ");
106+
CTF::get(buff.data())->print(getPrefix());
107107
}
108+
108109
///___________________________________________________________________________________
109110
/// decode entropy-encoded digits to standard compact digits
110111
template <typename VROF, typename VDIG, typename VPAT>
111112
void CTFCoder::decode(const CTF::base& ec, VROF& rofRecVec, VDIG& cdigVec, VPAT& pattVec)
112113
{
113114
CompressedInfos cc;
115+
ec.print(getPrefix());
114116
cc.header = ec.getHeader();
115117
#define DECODETOF(part, slot) ec.decode(part, int(slot), mCoders[int(slot)].get())
116118
// clang-format off

0 commit comments

Comments
 (0)