Skip to content

Commit 2bcb3db

Browse files
committed
HMPID CTF added
1 parent dde0975 commit 2bcb3db

File tree

15 files changed

+860
-2
lines changed

15 files changed

+860
-2
lines changed

DataFormats/Detectors/HMPID/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ o2_add_library(DataFormatsHMP
1212
SOURCES src/Digit.cxx
1313
src/Cluster.cxx
1414
src/Trigger.cxx
15+
src/CTF.cxx
1516
PUBLIC_LINK_LIBRARIES O2::ReconstructionDataFormats
1617
O2::HMPIDBase
1718
O2::CommonDataFormat
@@ -22,4 +23,5 @@ o2_target_root_dictionary(DataFormatsHMP
2223
include/DataFormatsHMP/Digit.h
2324
include/DataFormatsHMP/Trigger.h
2425
include/DataFormatsHMP/Cluster.h
25-
include/DataFormatsHMP/Hit.h)
26+
include/DataFormatsHMP/Hit.h
27+
include/DataFormatsHMP/CTF.h)
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
/// \file CTF.h
12+
/// \author ruben.shahoyan@cern.ch
13+
/// \brief Definitions for HMPID CTF data
14+
15+
#ifndef O2_HMP_CTF_H
16+
#define O2_HMP_CTF_H
17+
18+
#include <vector>
19+
#include <Rtypes.h>
20+
#include "DetectorsCommonDataFormats/EncodedBlocks.h"
21+
22+
namespace o2
23+
{
24+
namespace hmpid
25+
{
26+
27+
/// Header for a single CTF
28+
struct CTFHeader {
29+
uint32_t nTriggers = 0; /// number of triggers
30+
uint32_t nDigits = 0; /// number of digits
31+
uint32_t firstOrbit = 0; /// orbit of 1st trigger
32+
uint16_t firstBC = 0; /// bc of 1st trigger
33+
34+
ClassDefNV(CTFHeader, 1);
35+
};
36+
37+
/// wrapper for the Entropy-encoded triggers and cells of the TF
38+
struct CTF : public o2::ctf::EncodedBlocks<CTFHeader, 8, uint32_t> {
39+
40+
static constexpr size_t N = getNBlocks();
41+
enum Slots { BLC_bcIncTrig,
42+
BLC_orbitIncTrig,
43+
BLC_entriesDig,
44+
BLC_ChID, // digits sorted in ChamberID -> 1st entry of trigger keeps abs ChID, then increments
45+
BLC_Q,
46+
BLC_Ph,
47+
BLC_X,
48+
BLC_Y
49+
};
50+
ClassDefNV(CTF, 1);
51+
};
52+
53+
} // namespace hmpid
54+
} // namespace o2
55+
56+
#endif
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
#include <stdexcept>
12+
#include <cstring>
13+
#include "DataFormatsHMP/CTF.h"
14+
15+
using namespace o2::hmpid;

DataFormats/Detectors/HMPID/src/DataFormatsHMPLinkDef.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,8 @@
2323
#pragma link C++ class o2::hmpid::Trigger + ;
2424
#pragma link C++ class vector < o2::hmpid::Trigger> + ;
2525

26+
#pragma link C++ struct o2::hmpid::CTFHeader + ;
27+
#pragma link C++ struct o2::hmpid::CTF + ;
28+
#pragma link C++ class o2::ctf::EncodedBlocks < o2::hmpid::CTFHeader, 8, uint32_t> + ;
29+
2630
#endif

Detectors/HMPID/reconstruction/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ o2_add_library(HMPIDReconstruction
1212
SOURCES src/Clusterer.cxx
1313
src/HmpidDecoder2.cxx
1414
src/HmpidEquipment.cxx
15+
src/CTFHelper.cxx
16+
src/CTFCoder.cxx
1517
PUBLIC_LINK_LIBRARIES O2::HMPIDBase
1618
O2::DataFormatsHMP
1719
O2::HMPIDSimulation)
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
/// \file CTFCoder.h
12+
/// \author ruben.shahoyan@cern.ch
13+
/// \brief class for entropy encoding/decoding of HMPID data
14+
15+
#ifndef O2_HMPID_CTFCODER_H
16+
#define O2_HMPID_CTFCODER_H
17+
18+
#include <algorithm>
19+
#include <iterator>
20+
#include <string>
21+
#include <array>
22+
#include "DataFormatsHMP/CTF.h"
23+
#include "DetectorsCommonDataFormats/DetID.h"
24+
#include "DetectorsBase/CTFCoderBase.h"
25+
#include "rANS/rans.h"
26+
#include "HMPIDReconstruction/CTFHelper.h"
27+
28+
class TTree;
29+
30+
namespace o2
31+
{
32+
namespace hmpid
33+
{
34+
35+
class CTFCoder : public o2::ctf::CTFCoderBase
36+
{
37+
public:
38+
CTFCoder() : o2::ctf::CTFCoderBase(CTF::getNBlocks(), o2::detectors::DetID::HMP) {}
39+
~CTFCoder() = default;
40+
41+
/// entropy-encode data to buffer with CTF
42+
template <typename VEC>
43+
void encode(VEC& buff, const gsl::span<const Trigger>& trigData, const gsl::span<const Digit>& digData);
44+
45+
/// entropy decode data from buffer with CTF
46+
template <typename VTRG, typename VDIG>
47+
void decode(const CTF::base& ec, VTRG& trigVec, VDIG& digVec);
48+
49+
void createCoders(const std::string& dictPath, o2::ctf::CTFCoderBase::OpType op);
50+
51+
private:
52+
void appendToTree(TTree& tree, CTF& ec);
53+
void readFromTree(TTree& tree, int entry, std::vector<Trigger>& trigVec, std::vector<Digit>& digVec);
54+
};
55+
56+
/// entropy-encode digits and to buffer with CTF
57+
template <typename VEC>
58+
void CTFCoder::encode(VEC& buff, const gsl::span<const Trigger>& trigData, const gsl::span<const Digit>& digData)
59+
{
60+
using MD = o2::ctf::Metadata::OptStore;
61+
// what to do which each field: see o2::ctd::Metadata explanation
62+
constexpr MD optField[CTF::getNBlocks()] = {
63+
MD::EENCODE, // BLC_bcIncTrig
64+
MD::EENCODE, // BLC_orbitIncTrig
65+
MD::EENCODE, // BLC_entriesDig
66+
MD::EENCODE, // BLC_ChID
67+
MD::EENCODE, // BLC_Q
68+
MD::EENCODE, // BLC_Ph
69+
MD::EENCODE, // BLC_X
70+
MD::EENCODE // BLC_Y
71+
};
72+
73+
CTFHelper helper(trigData, digData);
74+
75+
// book output size with some margin
76+
auto szIni = sizeof(CTFHeader) + helper.getSize() * 2. / 3; // will be autoexpanded if needed
77+
buff.resize(szIni);
78+
79+
auto ec = CTF::create(buff);
80+
using ECB = CTF::base;
81+
82+
ec->setHeader(helper.createHeader());
83+
ec->getANSHeader().majorVersion = 0;
84+
ec->getANSHeader().minorVersion = 1;
85+
// at every encoding the buffer might be autoexpanded, so we don't work with fixed pointer ec
86+
#define ENCODEHMP(beg, end, slot, bits) CTF::get(buff.data())->encode(beg, end, int(slot), bits, optField[int(slot)], &buff, mCoders[int(slot)].get());
87+
// clang-format off
88+
ENCODEHMP(helper.begin_bcIncTrig(), helper.end_bcIncTrig(), CTF::BLC_bcIncTrig, 0);
89+
ENCODEHMP(helper.begin_orbitIncTrig(), helper.end_orbitIncTrig(), CTF::BLC_orbitIncTrig, 0);
90+
ENCODEHMP(helper.begin_entriesDig(), helper.end_entriesDig(), CTF::BLC_entriesDig, 0);
91+
92+
ENCODEHMP(helper.begin_ChID(), helper.end_ChID(), CTF::BLC_ChID, 0);
93+
ENCODEHMP(helper.begin_Q(), helper.end_Q(), CTF::BLC_Q, 0);
94+
ENCODEHMP(helper.begin_Ph(), helper.end_Ph(), CTF::BLC_Ph, 0);
95+
ENCODEHMP(helper.begin_X(), helper.end_X(), CTF::BLC_X, 0);
96+
ENCODEHMP(helper.begin_Y(), helper.end_Y(), CTF::BLC_Y, 0);
97+
98+
// clang-format on
99+
CTF::get(buff.data())->print(getPrefix());
100+
}
101+
102+
/// decode entropy-encoded data to digits
103+
template <typename VTRG, typename VDIG>
104+
void CTFCoder::decode(const CTF::base& ec, VTRG& trigVec, VDIG& digVec)
105+
{
106+
auto header = ec.getHeader();
107+
ec.print(getPrefix());
108+
std::vector<uint16_t> bcInc, q;
109+
std::vector<uint32_t> orbitInc, entriesDig;
110+
std::vector<uint8_t> chID, ph, x, y;
111+
112+
#define DECODEHMP(part, slot) ec.decode(part, int(slot), mCoders[int(slot)].get())
113+
// clang-format off
114+
DECODEHMP(bcInc, CTF::BLC_bcIncTrig);
115+
DECODEHMP(orbitInc, CTF::BLC_orbitIncTrig);
116+
DECODEHMP(entriesDig, CTF::BLC_entriesDig);
117+
118+
DECODEHMP(chID, CTF::BLC_ChID);
119+
DECODEHMP(q, CTF::BLC_Q);
120+
DECODEHMP(ph, CTF::BLC_Ph);
121+
DECODEHMP(x, CTF::BLC_X);
122+
DECODEHMP(y, CTF::BLC_Y);
123+
// clang-format on
124+
//
125+
trigVec.clear();
126+
digVec.clear();
127+
trigVec.reserve(header.nTriggers);
128+
digVec.reserve(header.nDigits);
129+
130+
uint32_t digCount = 0;
131+
o2::InteractionRecord ir(header.firstBC, header.firstOrbit);
132+
133+
for (uint32_t itrig = 0; itrig < header.nTriggers; itrig++) {
134+
// restore TrigRecord
135+
if (orbitInc[itrig]) { // non-0 increment => new orbit
136+
ir.bc = bcInc[itrig]; // bcInc has absolute meaning
137+
ir.orbit += orbitInc[itrig];
138+
} else {
139+
ir.bc += bcInc[itrig];
140+
}
141+
142+
uint32_t firstEntryDig = digVec.size();
143+
int8_t chid = 0;
144+
for (uint32_t id = 0; id < entriesDig[itrig]; id++) {
145+
chid += chID[digCount]; // 1st digit of trigger was encoded with abs ChID, then increments
146+
auto& dig = digVec.emplace_back(chid, ph[digCount], x[digCount], y[digCount], q[digCount]);
147+
digCount++;
148+
}
149+
150+
trigVec.emplace_back(ir, firstEntryDig, entriesDig[itrig]);
151+
}
152+
assert(digCount == header.nDigits);
153+
}
154+
155+
} // namespace hmpid
156+
} // namespace o2
157+
158+
#endif // O2_HMP_CTFCODER_H

0 commit comments

Comments
 (0)