1616#include " FWCore/MessageLogger/interface/MessageLogger.h"
1717
1818/* *
19- @short this structure holds the indices and types in the readout sequence
20- as the 12 capture blocks may not all be used and the each capture block may also be under-utilized
21- a lookup table is used to hold the compact index
19+ * @short this structure holds the indices and types in the readout sequence
20+ * as the 12 capture blocks may not all be used and the each capture block may also be under-utilized
21+ * a lookup table is used to hold the compact index
2222 */
2323struct HGCalFEDReadoutSequence {
2424 uint32_t id;
25- // /> look-up table (capture block, econd idx) -> internal dense index
25+ // / look-up table (capture block, econd idx) -> internal dense index
2626 std::vector<int > moduleLUT_;
27- // /> dense sequence of modules in the readout: the type is the one in use in the cell mapping
27+ // / dense sequence of modules in the readout: the type is the one in use in the cell mapping
2828 std::vector<int > readoutTypes_;
29- // /> dense sequence of offsets for modules, e-Rx and channel data
29+ // / dense sequence of offsets for modules, e-Rx and channel data
3030 std::vector<uint32_t > modOffsets_, erxOffsets_, chDataOffsets_, enabledErx_;
3131 COND_SERIALIZABLE;
3232};
3333
3434/* *
35- @short utility class to assign dense readout module indexing
36- the class holds the information on the expected readout sequence (module types) per FED and their offset in the SoAs of data
35+ * @short utility class to assign dense readout module indexing
36+ * the class holds the information on the expected readout sequence (module types) per FED and their offset in the SoAs of data
3737 */
3838class HGCalMappingModuleIndexer {
3939public:
@@ -42,10 +42,10 @@ class HGCalMappingModuleIndexer {
4242 ~HGCalMappingModuleIndexer () = default ;
4343
4444 /* *
45- @short for a new module it adds it's type to the readaout sequence vector
46- if the fed id is not yet existing in the mapping it's added
47- a dense indexer is used to create the necessary indices for the new module
48- unused indices will be set with -1
45+ * @short for a new module it adds it's type to the readaout sequence vector
46+ * if the fed id is not yet existing in the mapping it's added
47+ * a dense indexer is used to create the necessary indices for the new module
48+ * unused indices will be set with -1
4949 */
5050 void processNewModule (uint32_t fedid,
5151 uint16_t captureblockIdx,
@@ -56,31 +56,31 @@ class HGCalMappingModuleIndexer {
5656 std::string const &typecode);
5757
5858 /* *
59- @short to be called after all the modules have been processed
59+ * @short to be called after all the modules have been processed
6060 */
6161 void finalize ();
6262
6363 /* *
64- @short decodes silicon or sipm type and cell type for the detector id
65- from the typecode string
64+ * @short decodes silicon or sipm type and cell type for the detector id
65+ * from the typecode string
6666 */
6767 static std::pair<bool , int > convertTypeCode (std::string_view typecode) {
6868 if (typecode.size () < 5 )
6969 throw cms::Exception (" InvalidHGCALTypeCode" ) << typecode << " is invalid for decoding readout cell type" ;
7070 bool isSiPM = {typecode.find (" TM" ) != std::string::npos ? true : false };
7171 int celltype;
7272 if (isSiPM) {
73- celltype = 0 ; // Assign SiPM type coarse or molded with next version of modulelocator
73+ celltype = 0 ; // assign SiPM type coarse or molded with next version of modulelocator
7474 } else {
7575 celltype = {typecode[4 ] == ' 1' ? 0 : typecode[4 ] == ' 2' ? 1 : 2 };
7676 }
7777 return std::pair<bool , bool >(isSiPM, celltype);
7878 }
7979
8080 /* *
81- @short returns the index for the n-th module in the readout sequence of a FED
82- if the index in the readout sequence is unknown alternative methods which take the (capture block, econd idx) are provided
83- which will find first what should be the internal dense index (index in the readout sequence)
81+ * @short returns the index for the n-th module in the readout sequence of a FED
82+ * if the index in the readout sequence is unknown alternative methods which take the (capture block, econd idx) are provided
83+ * which will find first what should be the internal dense index (index in the readout sequence)
8484 */
8585 uint32_t getIndexForModule (uint32_t fedid, uint32_t modid) const {
8686 return fedReadoutSequences_[fedid].modOffsets_ [modid];
@@ -93,8 +93,8 @@ class HGCalMappingModuleIndexer {
9393 // return getIndexForModule(id.localFEDId(),id.captureBlock(),id.econdIdx());
9494 // };
9595 uint32_t getIndexForModule (std::string const &typecode) const {
96- const auto &[fedid, modId ] = getIndexForFedAndModule (typecode); // (fedId,modId)
97- return getIndexForModule (fedid, modId );
96+ const auto &[fedid, modid ] = getIndexForFedAndModule (typecode); // (fedId,modId)
97+ return getIndexForModule (fedid, modid );
9898 };
9999 uint32_t getIndexForModuleErx (uint32_t fedid, uint32_t modid, uint32_t erxidx) const {
100100 return fedReadoutSequences_[fedid].erxOffsets_ [modid] + erxidx;
@@ -116,37 +116,50 @@ class HGCalMappingModuleIndexer {
116116 : getIndexForModuleData (
117117 id.localFEDId (), id.captureBlock (), id.econdIdx (), id.econdeRx (), id.halfrocChannel ());
118118 };
119- uint32_t getIndexForModuleData (std::string typecode) const {
119+ uint32_t getIndexForModuleData (std::string const & typecode) const {
120120 const auto &[fedid, modid] = getIndexForFedAndModule (typecode);
121121 return getIndexForModuleData (fedid, modid, 0 , 0 );
122122 };
123123 std::pair<uint32_t , uint32_t > getIndexForFedAndModule (std::string const &typecode) const ;
124124
125125 /* *
126- @short return number maximum index of FED, ECON-D Module, eRx ROC
126+ * @short return number maximum index of FED, ECON-D Module, eRx ROC
127127 */
128- uint32_t getNFED () const { // return total number of FEDs that actually exist
128+ uint32_t getNumFEDs () const {
129129 return count_if (fedReadoutSequences_.begin (), fedReadoutSequences_.end (), [](auto fedrs) {
130130 return fedrs.readoutTypes_ .size () != 0 ;
131131 });
132- }
133- uint32_t getMaxFEDSize () const { return fedReadoutSequences_.size (); }
132+ } // /< return total number of FEDs that actually exist
133+ uint32_t getMaxFEDSize () const {
134+ return fedReadoutSequences_.size ();
135+ } // /< maximum FED index (fedReadoutSequences_ includes non existing FED IDs)
134136 uint32_t getMaxModuleSize () const {
135137 return maxModulesIdx_;
136- } // total number of ECON-Ds (useful for setting ECON-D SoA size)
137- uint32_t getMaxModuleSize (uint32_t fedid) const { // number of ECON-Ds for given FED id
138+ } // /< total number of ECON-Ds (useful for setting ECON-D SoA size)
139+ uint32_t getNModules (uint32_t fedid) const {
138140 return fedReadoutSequences_[fedid].readoutTypes_ .size ();
139- }
141+ } // /< number of ECON-Ds for given FED id
140142 uint32_t getMaxERxSize () const {
141143 return maxErxIdx_;
142- } // total number of eRx half-ROCs (useful for setting config SoA size)
143- uint32_t getMaxERxSize (uint32_t fedid, uint32_t modid) const { // number of eRx half-ROCs for given FED & ECON-D ids
144+ } // /< total number of eRx half-ROCs (useful for setting config SoA size)
145+ uint32_t getNumERxs (uint32_t fedid, uint32_t modid) const {
144146 auto modtype_val = fedReadoutSequences_[fedid].readoutTypes_ [modid];
145147 return globalTypesNErx_[modtype_val];
146- }
148+ } // /< number of eRx half-ROCs for given FED & ECON-D ids
149+ uint32_t getNumERxs (std::string const &typecode) const {
150+ const auto &[fedid, modid] = getIndexForFedAndModule (typecode);
151+ return getNumERxs (fedid, modid);
152+ } // /< number of eRx half-ROCs for a given ECON-D typecode
147153 uint32_t getMaxDataSize () const {
148154 return maxDataIdx_;
149- } // total number of channels (useful for setting calib SoA size)
155+ } // /< total number of channels (useful for setting calib SoA size)
156+ uint32_t getNumChannels (uint32_t fedid, uint32_t modid) const {
157+ return HGCalMappingCellIndexer::maxChPerErx_ * getNumERxs (fedid, modid);
158+ } // /< total number of channels for given FED & ECON-D ids
159+ uint32_t getNumChannels (std::string const &typecode) const {
160+ const auto &[fedid, modid] = getIndexForFedAndModule (typecode);
161+ return getNumChannels (fedid, modid);
162+ } // /< total number of channels for a given ECON-D typecode
150163
151164 /* *
152165 @short return type ECON-D Module
@@ -160,7 +173,7 @@ class HGCalMappingModuleIndexer {
160173 }
161174
162175 /* *
163- @short getters for private members
176+ * @short getters for private members
164177 */
165178 HGCalDenseIndexerBase const &getFEDIndexer () const { return modFedIndexer_; }
166179 std::vector<HGCalFEDReadoutSequence> const &getFEDReadoutSequences () const { return fedReadoutSequences_; }
@@ -176,27 +189,27 @@ class HGCalMappingModuleIndexer {
176189 uint32_t maxModulesIndex () const { return maxModulesIdx_; }
177190 std::map<std::string, std::pair<uint32_t , uint32_t >> const &getTypecodeMap () const { return typecodeMap_; }
178191
179- // /< max number of main buffers/capture blocks per FED
192+ // / max number of main buffers/capture blocks per FED
180193 constexpr static uint32_t maxCBperFED_ = 10 ;
181- // /< max number of ECON-Ds processed by a main buffer/capture block
194+ // / max number of ECON-Ds processed by a main buffer/capture block
182195 constexpr static uint32_t maxECONDperCB_ = 12 ;
183196
184197private:
185- // /< internal indexer
198+ // / internal indexer
186199 HGCalDenseIndexerBase modFedIndexer_;
187- // /< the sequence of FED readout sequence descriptors
200+ // / the sequence of FED readout sequence descriptors
188201 std::vector<HGCalFEDReadoutSequence> fedReadoutSequences_;
189- // /< global counters for types of modules, number of e-Rx and words
202+ // / global counters for types of modules, number of e-Rx and words
190203 std::vector<uint32_t > globalTypesCounter_, globalTypesNErx_, globalTypesNWords_;
191- // /< base offsets to apply per module type with different granularity : module, e-Rx, channel data
204+ // / base offsets to apply per module type with different granularity : module, e-Rx, channel data
192205 std::vector<uint32_t > moduleOffsets_, erxOffsets_, dataOffsets_;
193- // /< global counters (sizes of vectors)
206+ // / global counters (sizes of vectors)
194207 uint32_t nfeds_, maxDataIdx_, maxErxIdx_, maxModulesIdx_;
195- // /< map from module type code string to (fedIdx,modIdx) pair (implemented to retrieve dense index offset)
208+ // / map from module type code string to (fedIdx,modIdx) pair (implemented to retrieve dense index offset)
196209 std::map<std::string, std::pair<uint32_t , uint32_t >> typecodeMap_;
197210
198211 /* *
199- @short given capture block and econd indices returns the dense indexer
212+ * @short given capture block and econd indices returns the dense indexer
200213 */
201214 uint32_t denseIndexingFor (uint32_t fedid, uint16_t captureblockIdx, uint16_t econdIdx) const {
202215 if (fedid > nfeds_)
@@ -211,12 +224,11 @@ class HGCalMappingModuleIndexer {
211224 }
212225
213226 /* *
214- @short when finalize is called, empty entries are removed and they may need to be re-assigned for the real final number of modules
227+ * @short when finalize is called, empty entries are removed and they may need to be re-assigned for the real final number of modules
215228 */
216229 void reassignTypecodeLocation (uint32_t fedid, uint32_t cur_modIdx, uint32_t new_modIx) {
217230 std::pair<uint32_t , uint32_t > val (fedid, cur_modIdx), newval (fedid, new_modIx);
218-
219- for (auto it : typecodeMap_) {
231+ for (const auto &it : typecodeMap_) {
220232 if (it.second != val)
221233 continue ;
222234 typecodeMap_[it.first ] = newval;
0 commit comments