Skip to content

Commit 0b4cc5b

Browse files
authored
Merge pull request #48137 from CMS-HGCAL/dev/hackathon_clean_config_15X
[HGCAL] Clean HGCal configuration & calibration
2 parents 0e4cb56 + bcd62e2 commit 0b4cc5b

19 files changed

+394
-405
lines changed

CondFormats/HGCalObjects/interface/HGCalCalibrationParameterHost.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,13 @@
33

44
#include "DataFormats/Portable/interface/PortableHostCollection.h"
55
#include "CondFormats/HGCalObjects/interface/HGCalCalibParamSoA.h"
6-
#include "CondFormats/HGCalObjects/interface/HGCalConfigParamSoA.h"
76

87
namespace hgcalrechit {
98

109
// SoA with channel-level calibration parameters in host memory:
1110
// pedestal, CM_slope, CM_ped, BXm1_kappa
1211
using HGCalCalibParamHost = PortableHostCollection<HGCalCalibParamSoA>;
1312

14-
// SoA with ROC-level configuration parameters in host memory:
15-
// gain
16-
using HGCalConfigParamHost = PortableHostCollection<HGCalConfigParamSoA>;
17-
1813
} // namespace hgcalrechit
1914

2015
#endif // CondFormats_HGCalObjects_interface_HGCalCalibrationParameterHost_h

CondFormats/HGCalObjects/interface/HGCalConfigParamSoA.h

Lines changed: 0 additions & 23 deletions
This file was deleted.

CondFormats/HGCalObjects/interface/HGCalConfiguration.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,13 @@
1010
// @short configuration for ECON eRX (one half of HGROC)
1111
struct HGCalROCConfig {
1212
uint32_t charMode; // characterization mode; determines data fields in ROC dataframe
13-
uint8_t gain; // pre-amp gain used (1: 80 fC, 2: 160 fC, 4: 320 fC)
14-
//uint32_t clockPhase; // fine adjustment of the phase within the 40 MHz
15-
//uint32_t L1AcceptOffset; // coarse adjustment to get the peak in the right place
16-
//uint32_t injChannels; // injected channels for injection scan: 2b word to identify if connected or not+info no capacitor chosen
17-
//uint32_t injCharge; // injected charge for injection scan: convert it to a float in units of fC offline (DAC setting?)
1813
COND_SERIALIZABLE;
1914
};
2015

2116
// @short configuration for ECON-D module
2217
struct HGCalECONDConfig {
2318
//std::string typecode;
2419
uint32_t headerMarker; // begin of event marker/identifier for ECON-D
25-
uint32_t passThrough; //pass through mode (this is just as check as it'll be in the ECON-D header anyway)
2620
std::vector<HGCalROCConfig> rocs;
2721
COND_SERIALIZABLE;
2822
};
@@ -32,15 +26,14 @@ struct HGCalFedConfig {
3226
bool mismatchPassthroughMode; // ignore ECON-D packet mismatches
3327
uint32_t cbHeaderMarker; // begin of event marker/identifier for capture block
3428
uint32_t slinkHeaderMarker; // begin of event marker/identifier for S-link
35-
//uint32_t delay; // delay
3629
std::vector<HGCalECONDConfig> econds;
3730
COND_SERIALIZABLE;
3831
};
3932

4033
/**
4134
* @short Main HGCal configuration with a tree structure of vectors of
4235
* HGCalFedConfig/HGCalECONDConfig/HGCalROCConfig structs as follows:
43-
% config.feds[dense_fed_idx].econds[dense_econd_idx].rocs[dense_eRx_idx]
36+
* config.feds[dense_fed_idx].econds[dense_econd_idx].rocs[dense_eRx_idx]
4437
**/
4538
class HGCalConfiguration {
4639
public:

CondFormats/HGCalObjects/interface/HGCalMappingModuleIndexer.h

Lines changed: 58 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,24 @@
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
*/
2323
struct 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
*/
3838
class HGCalMappingModuleIndexer {
3939
public:
@@ -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

184197
private:
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;

CondFormats/HGCalObjects/interface/alpaka/HGCalCalibrationParameterDevice.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include "HeterogeneousCore/AlpakaInterface/interface/config.h"
66
#include "HeterogeneousCore/AlpakaInterface/interface/memory.h"
77
#include "CondFormats/HGCalObjects/interface/HGCalCalibParamSoA.h"
8-
#include "CondFormats/HGCalObjects/interface/HGCalConfigParamSoA.h"
98
#include "CondFormats/HGCalObjects/interface/HGCalCalibrationParameterHost.h"
109

1110
namespace ALPAKA_ACCELERATOR_NAMESPACE {
@@ -14,7 +13,6 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
1413

1514
using namespace ::hgcalrechit;
1615
using HGCalCalibParamDevice = PortableCollection<HGCalCalibParamSoA>;
17-
using HGCalConfigParamDevice = PortableCollection<HGCalConfigParamSoA>;
1816

1917
} // namespace hgcalrechit
2018

CondFormats/HGCalObjects/src/T_EventSetup_HGCalCalibrationParameterHost.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@
22
#include "CondFormats/HGCalObjects/interface/HGCalCalibrationParameterHost.h"
33

44
TYPELOOKUP_DATA_REG(hgcalrechit::HGCalCalibParamHost);
5-
TYPELOOKUP_DATA_REG(hgcalrechit::HGCalConfigParamHost);

CondFormats/HGCalObjects/src/alpaka/T_EventSetup_HGCalCalibrationParameterDevice.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@
22
#include "CondFormats/HGCalObjects/interface/alpaka/HGCalCalibrationParameterDevice.h"
33

44
TYPELOOKUP_ALPAKA_DATA_REG(hgcalrechit::HGCalCalibParamDevice);
5-
TYPELOOKUP_ALPAKA_DATA_REG(hgcalrechit::HGCalConfigParamDevice);

CondFormats/HGCalObjects/src/classes_def.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@
4343

4444
<class name="HGCalROCConfig" class_version="0">
4545
<field name="charMode" mapping="blob"/>
46-
<field name="clockPhase" mapping="blob"/>
47-
<field name="L1AcceptOffset" mapping="blob"/>
48-
<field name="injChannels" mapping="blob"/>
49-
<field name="injCharge" mapping="blob"/>
5046
</class>
5147

5248
<class name="HGCalDenseIndexerBase" class_version="0">

RecoLocalCalo/HGCalRecAlgos/BuildFile.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<use name="clhep"/>
22
<use name="root"/>
3+
<use name="json"/>
34
<use name="rootminuit"/>
45
<use name="DataFormats/HGCRecHit"/>
56
<use name="DataFormats/ParticleFlowReco"/>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#ifndef RecoLocalCalo_HGCalRecAlgos_HGCalESProducerTools_h
2+
#define RecoLocalCalo_HGCalRecAlgos_HGCalESProducerTools_h
3+
4+
#include <string>
5+
#include <nlohmann/json.hpp>
6+
using json = nlohmann::ordered_json; // ordered_json preserves key insertion order
7+
8+
namespace hgcal {
9+
10+
std::string search_modkey(const std::string& module, const json& data, const std::string& name);
11+
std::string search_fedkey(const int& fedid, const json& data, const std::string& name);
12+
bool check_keys(const json& data,
13+
const std::string& firstkey,
14+
const std::vector<std::string>& keys,
15+
const std::string& fname);
16+
17+
} // namespace hgcal
18+
19+
#endif

0 commit comments

Comments
 (0)