Skip to content

Commit 9bd0c17

Browse files
authored
Merge pull request #48648 from CMS-HGCAL/dev/hgcalmapping_trigger
[HGCAL] Add ECON-T indexer for reading out TPG data
2 parents c323def + a83e892 commit 9bd0c17

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1644
-126
lines changed

CondFormats/HGCalObjects/interface/HGCalDenseIndexerBase.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class HGCalDenseIndexerBase {
4545
return codes;
4646
}
4747

48-
uint32_t getMaxIndex() const { return maxIdx_; }
48+
uint32_t maxIndex() const { return maxIdx_; }
4949

5050
~HGCalDenseIndexerBase() = default;
5151

CondFormats/HGCalObjects/interface/HGCalMappingCellIndexer.h

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ class HGCalMappingCellIndexer {
1919
HGCalMappingCellIndexer() = default;
2020

2121
/**
22-
adds to map of type codes (= module types) to handle and updatest the max. number of eRx
22+
adds to map of type codes (= module types) to handle and updatest the max. number of eRx
2323
*/
24-
void processNewCell(std::string typecode, uint16_t chip, uint16_t half) {
24+
void processNewCell(std::string const& typecode, uint16_t chip, uint16_t half) {
2525
//assign index to this typecode and resize the max e-Rx vector
2626
if (typeCodeIndexer_.count(typecode) == 0) {
2727
typeCodeIndexer_[typecode] = typeCodeIndexer_.size();
@@ -44,17 +44,14 @@ class HGCalMappingCellIndexer {
4444
uint16_t nerx = maxErx_[idx];
4545
di_[idx].updateRanges({{nerx, maxChPerErx_}});
4646
if (idx < n - 1)
47-
offsets_[idx + 1] = di_[idx].getMaxIndex();
47+
offsets_[idx + 1] = di_[idx].maxIndex() + offsets_[idx];
4848
}
49-
50-
//accumulate the offsets in the array
51-
std::partial_sum(offsets_.begin(), offsets_.end(), offsets_.begin());
5249
}
5350

5451
/**
5552
@short gets index given typecode string
5653
*/
57-
size_t getEnumFromTypecode(std::string typecode) const {
54+
size_t getEnumFromTypecode(std::string const& typecode) const {
5855
auto it = typeCodeIndexer_.find(typecode);
5956
if (it == typeCodeIndexer_.end())
6057
throw cms::Exception("ValueError") << " unable to find typecode=" << typecode << " in cell indexer";
@@ -74,7 +71,7 @@ class HGCalMappingCellIndexer {
7471
/**
7572
@short returns the dense indexer for a typecode
7673
*/
77-
HGCalDenseIndexerBase getDenseIndexFor(std::string typecode) const {
74+
HGCalDenseIndexerBase getDenseIndexFor(std::string const& typecode) const {
7875
return getDenseIndexerFor(getEnumFromTypecode(typecode));
7976
}
8077

@@ -91,10 +88,10 @@ class HGCalMappingCellIndexer {
9188
/**
9289
@short builders for the dense index
9390
*/
94-
uint32_t denseIndex(std::string typecode, uint32_t chip, uint32_t half, uint32_t seq) const {
91+
uint32_t denseIndex(std::string const& typecode, uint32_t chip, uint32_t half, uint32_t seq) const {
9592
return denseIndex(getEnumFromTypecode(typecode), chip, half, seq);
9693
}
97-
uint32_t denseIndex(std::string typecode, uint32_t erx, uint32_t seq) const {
94+
uint32_t denseIndex(std::string const& typecode, uint32_t erx, uint32_t seq) const {
9895
return denseIndex(getEnumFromTypecode(typecode), erx, seq);
9996
}
10097
uint32_t denseIndex(size_t idx, uint32_t chip, uint32_t half, uint32_t seq) const {
@@ -108,7 +105,7 @@ class HGCalMappingCellIndexer {
108105
/**
109106
@short decodes the dense index code
110107
*/
111-
uint32_t elecIdFromIndex(uint32_t rtn, std::string typecode) const {
108+
uint32_t elecIdFromIndex(uint32_t rtn, std::string const& typecode) const {
112109
return elecIdFromIndex(rtn, getEnumFromTypecode(typecode));
113110
}
114111
uint32_t elecIdFromIndex(uint32_t rtn, size_t idx) const {
@@ -133,7 +130,7 @@ class HGCalMappingCellIndexer {
133130
/**
134131
@short gets the number of words for a given typecode
135132
*/
136-
size_t getNWordsExpectedFor(std::string typecode) const {
133+
size_t getNWordsExpectedFor(std::string const& typecode) const {
137134
auto it = getEnumFromTypecode(typecode);
138135
return getNWordsExpectedFor(it);
139136
}
@@ -142,7 +139,7 @@ class HGCalMappingCellIndexer {
142139
/**
143140
@short gets the number of e-Rx for a given typecode
144141
*/
145-
size_t getNErxExpectedFor(std::string typecode) const {
142+
size_t getNErxExpectedFor(std::string const& typecode) const {
146143
auto it = getEnumFromTypecode(typecode);
147144
return getNErxExpectedFor(it);
148145
}
@@ -151,7 +148,7 @@ class HGCalMappingCellIndexer {
151148
constexpr static char maxHalfPerROC_ = 2;
152149
constexpr static uint16_t maxChPerErx_ = 37; //36 channels + 1 calib
153150

154-
std::map<std::string, size_t> typeCodeIndexer_;
151+
std::unordered_map<std::string, size_t> typeCodeIndexer_;
155152
std::vector<uint16_t> maxErx_;
156153
std::vector<uint32_t> offsets_;
157154
std::vector<HGCalDenseIndexerBase> di_;
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
#ifndef CondFormats_HGCalObjects_interface_HGCalMappingCellIndexerTrigger_h
2+
#define CondFormats_HGCalObjects_interface_HGCalMappingCellIndexerTrigger_h
3+
4+
#include <iostream>
5+
#include <cstdint>
6+
#include <vector>
7+
#include <numeric>
8+
#include "CondFormats/Serialization/interface/Serializable.h"
9+
#include "CondFormats/HGCalObjects/interface/HGCalDenseIndexerBase.h"
10+
11+
/**
12+
@short utility class to assign dense readout trigger cell indexing
13+
*/
14+
class HGCalMappingCellIndexerTrigger {
15+
public:
16+
// typedef HGCalDenseIndexerBase WaferDenseIndexerBase;
17+
18+
HGCalMappingCellIndexerTrigger() = default;
19+
20+
/**
21+
adds to map of type codes (= module types) to handle and updatest the max. number of eRx
22+
*/
23+
void processNewCell(std::string const& typecode, uint16_t ROC, uint16_t trLink, uint16_t trCell) {
24+
// Skip if trLink, trCell not connected
25+
if (trLink == uint16_t(-1) || trCell == uint16_t(-1))
26+
return;
27+
//assign index to this typecode and resize the max vectors
28+
if (typeCodeIndexer_.count(typecode) == 0) {
29+
typeCodeIndexer_[typecode] = typeCodeIndexer_.size();
30+
maxROC_.resize(typeCodeIndexer_.size(), 0);
31+
maxTrLink_.resize(typeCodeIndexer_.size(), 0);
32+
maxTCPerLink_.resize(typeCodeIndexer_.size(), 0);
33+
}
34+
35+
size_t idx = typeCodeIndexer_[typecode];
36+
37+
/*High density modules have links {0, 2} and low {0, 1, 2, 3} so to make it work I need to divide by 2*/
38+
if (typecode[1] == 'H')
39+
trLink /= 2;
40+
/*SiPM tiles have trCells indexed from 1 instead from 0*/
41+
if (typecode[0] == 'T')
42+
trCell--;
43+
maxROC_[idx] = std::max(maxROC_[idx], static_cast<uint16_t>(ROC + 1));
44+
maxTrLink_[idx] = std::max(maxTrLink_[idx], static_cast<uint16_t>(trLink + 1));
45+
maxTCPerLink_[idx] = std::max(maxTCPerLink_[idx], static_cast<uint16_t>(trCell + 1));
46+
}
47+
48+
/**
49+
@short process the current list of type codes handled and updates the dense indexers
50+
*/
51+
void update() {
52+
uint32_t n = typeCodeIndexer_.size();
53+
offsets_ = std::vector<uint32_t>(n, 0);
54+
di_ = std::vector<HGCalDenseIndexerBase>(n, HGCalDenseIndexerBase(3)); /* The indices are {ROC, trLink, TC}*/
55+
for (uint32_t idx = 0; idx < n; idx++) {
56+
uint16_t maxROCs = maxROC_[idx];
57+
uint16_t maxLinks = maxTrLink_[idx];
58+
uint16_t maxTCPerLink = maxTCPerLink_[idx];
59+
di_[idx].updateRanges({{maxROCs, maxLinks, maxTCPerLink}});
60+
if (idx < n - 1)
61+
offsets_[idx + 1] = di_[idx].maxIndex() + offsets_[idx];
62+
}
63+
}
64+
65+
/**
66+
@short gets index given typecode string
67+
*/
68+
size_t getEnumFromTypecode(std::string const& typecode) const {
69+
auto it = typeCodeIndexer_.find(typecode);
70+
if (it == typeCodeIndexer_.end())
71+
throw cms::Exception("ValueError") << " unable to find typecode=" << typecode << " in cell indexer";
72+
return it->second;
73+
}
74+
75+
/**
76+
@short checks if there is a typecode corresponding to an index
77+
*/
78+
std::string getTypecodeFromEnum(size_t idx) const {
79+
for (const auto& it : typeCodeIndexer_)
80+
if (it.second == idx)
81+
return it.first;
82+
throw cms::Exception("ValueError") << " unable to find typecode corresponding to idx=" << idx;
83+
}
84+
85+
/**
86+
@short returns the dense indexer for a typecode
87+
*/
88+
HGCalDenseIndexerBase getDenseIndexFor(std::string const& typecode) const {
89+
return getDenseIndexerFor(getEnumFromTypecode(typecode));
90+
}
91+
92+
/**
93+
@short returns the dense indexer for a given internal index
94+
*/
95+
HGCalDenseIndexerBase getDenseIndexerFor(size_t idx) const {
96+
if (idx >= di_.size())
97+
throw cms::Exception("ValueError") << " index requested for cell dense indexer (i=" << idx
98+
<< ") is larger than allocated";
99+
return di_[idx];
100+
}
101+
102+
/**
103+
@short builders for the dense index
104+
*/
105+
uint16_t denseIndex(std::string const& typecode, uint32_t ROC, uint32_t trLink, uint32_t trCell) const {
106+
return denseIndex(getEnumFromTypecode(typecode), ROC, trLink, trCell);
107+
}
108+
uint32_t denseIndex(size_t idx, uint32_t ROC, uint32_t trLink, uint32_t trCell) const {
109+
return di_[idx].denseIndex({{ROC, trLink, trCell}}) + offsets_[idx];
110+
}
111+
112+
/**
113+
@short returns the max. dense index expected
114+
*/
115+
uint32_t maxDenseIndex() const {
116+
size_t i = maxTrLink_.size();
117+
if (i == 0)
118+
return 0;
119+
return offsets_.back() + maxROC_.back() * maxTrLink_.back() * maxTCPerLink_.back();
120+
}
121+
122+
/**
123+
@short gets the number of words (cells) for a given typecode
124+
Note : some partials are rounded to the closest multiplie of 16 or 8 depending on the density
125+
That is done because not all the TrigLinks,TrgCells possible are assigned in practice
126+
e.g.: ML-T has 22 TCs but this will return 32 or MH-T has 19 but it will return 24
127+
It results in a small mem overhead over the totall memory needed to be allocated
128+
*/
129+
size_t getNWordsExpectedFor(std::string const& typecode) const {
130+
auto it = getEnumFromTypecode(typecode);
131+
return getNWordsExpectedFor(it);
132+
}
133+
size_t getNWordsExpectedFor(size_t typecodeidx) const { return getDenseIndexerFor(typecodeidx).maxIndex(); }
134+
135+
/**
136+
@short gets the number of Trigger Links for a given typecode
137+
*/
138+
size_t getNTrLinkExpectedFor(std::string const& typecode) const {
139+
auto it = getEnumFromTypecode(typecode);
140+
return getNTrLinkExpectedFor(it);
141+
}
142+
size_t getNTrLinkExpectedFor(size_t typecodeidx) const { return maxTrLink_[typecodeidx] * maxROC_[typecodeidx]; }
143+
144+
std::unordered_map<std::string, size_t> typeCodeIndexer_;
145+
std::vector<uint16_t> maxROC_;
146+
std::vector<uint16_t> maxTrLink_;
147+
std::vector<uint16_t> maxTCPerLink_;
148+
std::vector<uint32_t> offsets_;
149+
std::vector<HGCalDenseIndexerBase> di_;
150+
151+
~HGCalMappingCellIndexerTrigger() = default;
152+
153+
COND_SERIALIZABLE;
154+
};
155+
156+
#endif

CondFormats/HGCalObjects/interface/HGCalMappingModuleIndexer.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class HGCalMappingModuleIndexer {
6262
void finalize();
6363

6464
/**
65-
* @short decode silicon or sipm type and cell type for the detector id
65+
* @short decode silicon or sipm type and cell type for the detector id
6666
* from the typecode string: "M[LH]-X[123]X-*" for Si, "T[LH]-L*S*[PN]" for SiPm
6767
*/
6868
static std::pair<bool, int8_t> getCellType(std::string_view typecode);
@@ -115,21 +115,21 @@ class HGCalMappingModuleIndexer {
115115
/**
116116
* @short return number maximum index of FED, ECON-D Module, eRx ROC
117117
*/
118-
uint32_t getNumFEDs() const {
118+
uint32_t numFEDs() const {
119119
return count_if(fedReadoutSequences_.begin(), fedReadoutSequences_.end(), [](auto fedrs) {
120120
return fedrs.readoutTypes_.size() != 0;
121121
});
122122
} ///< return total number of FEDs that actually exist
123-
uint32_t getMaxFEDSize() const {
123+
uint32_t maxFEDSize() const {
124124
return fedReadoutSequences_.size();
125125
} ///< maximum FED index (fedReadoutSequences_ includes non existing FED IDs)
126-
uint32_t getMaxModuleSize() const {
126+
uint32_t maxModuleSize() const {
127127
return maxModulesIdx_;
128128
} ///< total number of ECON-Ds (useful for setting ECON-D SoA size)
129129
uint32_t getNumModules(uint32_t fedid) const {
130130
return fedReadoutSequences_[fedid].readoutTypes_.size();
131131
} ///< number of ECON-Ds for given FED id
132-
uint32_t getMaxERxSize() const {
132+
uint32_t maxERxSize() const {
133133
return maxErxIdx_;
134134
} ///< total number of eRx half-ROCs (useful for setting config SoA size)
135135
uint32_t getNumERxs(uint32_t fedid, uint32_t modid) const {
@@ -140,7 +140,7 @@ class HGCalMappingModuleIndexer {
140140
const auto &[fedid, modid] = getIndexForFedAndModule(typecode);
141141
return getNumERxs(fedid, modid);
142142
} ///< number of eRx half-ROCs for a given ECON-D typecode
143-
uint32_t getMaxDataSize() const {
143+
uint32_t maxDataSize() const {
144144
return maxDataIdx_;
145145
} ///< total number of channels (useful for setting calib SoA size)
146146
uint32_t getNumChannels(uint32_t fedid, uint32_t modid) const {
@@ -165,19 +165,19 @@ class HGCalMappingModuleIndexer {
165165
/**
166166
* @short getters for private members
167167
*/
168-
HGCalDenseIndexerBase const &getFEDIndexer() const { return modFedIndexer_; }
169-
std::vector<HGCalFEDReadoutSequence> const &getFEDReadoutSequences() const { return fedReadoutSequences_; }
170-
std::vector<uint32_t> const &getGlobalTypesCounter() const { return globalTypesCounter_; }
171-
std::vector<uint32_t> const &getGlobalTypesNErx() const { return globalTypesNErx_; }
172-
std::vector<uint32_t> const &getGlobalTypesNWords() const { return globalTypesNWords_; }
173-
std::vector<uint32_t> const &getModuleOffsets() const { return moduleOffsets_; }
174-
std::vector<uint32_t> const &getErxOffsets() const { return erxOffsets_; }
175-
std::vector<uint32_t> const &getDataOffsets() const { return dataOffsets_; }
168+
HGCalDenseIndexerBase const &fedIndexer() const { return modFedIndexer_; }
169+
std::vector<HGCalFEDReadoutSequence> const &fedReadoutSequences() const { return fedReadoutSequences_; }
170+
std::vector<uint32_t> const &globalTypesCounter() const { return globalTypesCounter_; }
171+
std::vector<uint32_t> const &globalTypesNErx() const { return globalTypesNErx_; }
172+
std::vector<uint32_t> const &globalTypesNWords() const { return globalTypesNWords_; }
173+
std::vector<uint32_t> const &moduleOffsets() const { return moduleOffsets_; }
174+
std::vector<uint32_t> const &erxOffsets() const { return erxOffsets_; }
175+
std::vector<uint32_t> const &dataOffsets() const { return dataOffsets_; }
176176
uint32_t fedCount() const { return nfeds_; }
177177
uint32_t maxDataIndex() const { return maxDataIdx_; }
178178
uint32_t maxErxIndex() const { return maxErxIdx_; }
179179
uint32_t maxModulesIndex() const { return maxModulesIdx_; }
180-
std::map<std::string, std::pair<uint32_t, uint32_t>> const &getTypecodeMap() const { return typecodeMap_; }
180+
std::map<std::string, std::pair<uint32_t, uint32_t>> const &typecodeMap() const { return typecodeMap_; }
181181

182182
/// max number of main buffers/capture blocks per FED
183183
constexpr static uint32_t maxCBperFED_ = 10;

0 commit comments

Comments
 (0)