Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CondFormats/HGCalObjects/interface/HGCalDenseIndexerBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class HGCalDenseIndexerBase {
return codes;
}

uint32_t getMaxIndex() const { return maxIdx_; }
uint32_t maxIndex() const { return maxIdx_; }

~HGCalDenseIndexerBase() = default;

Expand Down
25 changes: 11 additions & 14 deletions CondFormats/HGCalObjects/interface/HGCalMappingCellIndexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ class HGCalMappingCellIndexer {
HGCalMappingCellIndexer() = default;

/**
adds to map of type codes (= module types) to handle and updatest the max. number of eRx
adds to map of type codes (= module types) to handle and updatest the max. number of eRx
*/
void processNewCell(std::string typecode, uint16_t chip, uint16_t half) {
void processNewCell(std::string const& typecode, uint16_t chip, uint16_t half) {
//assign index to this typecode and resize the max e-Rx vector
if (typeCodeIndexer_.count(typecode) == 0) {
typeCodeIndexer_[typecode] = typeCodeIndexer_.size();
Expand All @@ -44,17 +44,14 @@ class HGCalMappingCellIndexer {
uint16_t nerx = maxErx_[idx];
di_[idx].updateRanges({{nerx, maxChPerErx_}});
if (idx < n - 1)
offsets_[idx + 1] = di_[idx].getMaxIndex();
offsets_[idx + 1] = di_[idx].maxIndex() + offsets_[idx];
}

//accumulate the offsets in the array
std::partial_sum(offsets_.begin(), offsets_.end(), offsets_.begin());
}

/**
@short gets index given typecode string
*/
size_t getEnumFromTypecode(std::string typecode) const {
size_t getEnumFromTypecode(std::string const& typecode) const {
auto it = typeCodeIndexer_.find(typecode);
if (it == typeCodeIndexer_.end())
throw cms::Exception("ValueError") << " unable to find typecode=" << typecode << " in cell indexer";
Expand All @@ -74,7 +71,7 @@ class HGCalMappingCellIndexer {
/**
@short returns the dense indexer for a typecode
*/
HGCalDenseIndexerBase getDenseIndexFor(std::string typecode) const {
HGCalDenseIndexerBase getDenseIndexFor(std::string const& typecode) const {
return getDenseIndexerFor(getEnumFromTypecode(typecode));
}

Expand All @@ -91,10 +88,10 @@ class HGCalMappingCellIndexer {
/**
@short builders for the dense index
*/
uint32_t denseIndex(std::string typecode, uint32_t chip, uint32_t half, uint32_t seq) const {
uint32_t denseIndex(std::string const& typecode, uint32_t chip, uint32_t half, uint32_t seq) const {
return denseIndex(getEnumFromTypecode(typecode), chip, half, seq);
}
uint32_t denseIndex(std::string typecode, uint32_t erx, uint32_t seq) const {
uint32_t denseIndex(std::string const& typecode, uint32_t erx, uint32_t seq) const {
return denseIndex(getEnumFromTypecode(typecode), erx, seq);
}
uint32_t denseIndex(size_t idx, uint32_t chip, uint32_t half, uint32_t seq) const {
Expand All @@ -108,7 +105,7 @@ class HGCalMappingCellIndexer {
/**
@short decodes the dense index code
*/
uint32_t elecIdFromIndex(uint32_t rtn, std::string typecode) const {
uint32_t elecIdFromIndex(uint32_t rtn, std::string const& typecode) const {
return elecIdFromIndex(rtn, getEnumFromTypecode(typecode));
}
uint32_t elecIdFromIndex(uint32_t rtn, size_t idx) const {
Expand All @@ -133,7 +130,7 @@ class HGCalMappingCellIndexer {
/**
@short gets the number of words for a given typecode
*/
size_t getNWordsExpectedFor(std::string typecode) const {
size_t getNWordsExpectedFor(std::string const& typecode) const {
auto it = getEnumFromTypecode(typecode);
return getNWordsExpectedFor(it);
}
Expand All @@ -142,7 +139,7 @@ class HGCalMappingCellIndexer {
/**
@short gets the number of e-Rx for a given typecode
*/
size_t getNErxExpectedFor(std::string typecode) const {
size_t getNErxExpectedFor(std::string const& typecode) const {
auto it = getEnumFromTypecode(typecode);
return getNErxExpectedFor(it);
}
Expand All @@ -151,7 +148,7 @@ class HGCalMappingCellIndexer {
constexpr static char maxHalfPerROC_ = 2;
constexpr static uint16_t maxChPerErx_ = 37; //36 channels + 1 calib

std::map<std::string, size_t> typeCodeIndexer_;
std::unordered_map<std::string, size_t> typeCodeIndexer_;
std::vector<uint16_t> maxErx_;
std::vector<uint32_t> offsets_;
std::vector<HGCalDenseIndexerBase> di_;
Expand Down
156 changes: 156 additions & 0 deletions CondFormats/HGCalObjects/interface/HGCalMappingCellIndexerTrigger.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
#ifndef CondFormats_HGCalObjects_interface_HGCalMappingCellIndexerTrigger_h
#define CondFormats_HGCalObjects_interface_HGCalMappingCellIndexerTrigger_h

#include <iostream>
#include <cstdint>
#include <vector>
#include <numeric>
#include "CondFormats/Serialization/interface/Serializable.h"
#include "CondFormats/HGCalObjects/interface/HGCalDenseIndexerBase.h"

/**
@short utility class to assign dense readout trigger cell indexing
*/
class HGCalMappingCellIndexerTrigger {
public:
// typedef HGCalDenseIndexerBase WaferDenseIndexerBase;

HGCalMappingCellIndexerTrigger() = default;

/**
adds to map of type codes (= module types) to handle and updatest the max. number of eRx
*/
void processNewCell(std::string const& typecode, uint16_t ROC, uint16_t trLink, uint16_t trCell) {
// Skip if trLink, trCell not connected
if (trLink == uint16_t(-1) || trCell == uint16_t(-1))
return;
//assign index to this typecode and resize the max vectors
if (typeCodeIndexer_.count(typecode) == 0) {
typeCodeIndexer_[typecode] = typeCodeIndexer_.size();
maxROC_.resize(typeCodeIndexer_.size(), 0);
maxTrLink_.resize(typeCodeIndexer_.size(), 0);
maxTCPerLink_.resize(typeCodeIndexer_.size(), 0);
}

size_t idx = typeCodeIndexer_[typecode];

/*High density modules have links {0, 2} and low {0, 1, 2, 3} so to make it work I need to divide by 2*/
if (typecode[1] == 'H')
trLink /= 2;
/*SiPM tiles have trCells indexed from 1 instead from 0*/
if (typecode[0] == 'T')
trCell--;
maxROC_[idx] = std::max(maxROC_[idx], static_cast<uint16_t>(ROC + 1));
maxTrLink_[idx] = std::max(maxTrLink_[idx], static_cast<uint16_t>(trLink + 1));
maxTCPerLink_[idx] = std::max(maxTCPerLink_[idx], static_cast<uint16_t>(trCell + 1));
}

/**
@short process the current list of type codes handled and updates the dense indexers
*/
void update() {
uint32_t n = typeCodeIndexer_.size();
offsets_ = std::vector<uint32_t>(n, 0);
di_ = std::vector<HGCalDenseIndexerBase>(n, HGCalDenseIndexerBase(3)); /* The indices are {ROC, trLink, TC}*/
for (uint32_t idx = 0; idx < n; idx++) {
uint16_t maxROCs = maxROC_[idx];
uint16_t maxLinks = maxTrLink_[idx];
uint16_t maxTCPerLink = maxTCPerLink_[idx];
di_[idx].updateRanges({{maxROCs, maxLinks, maxTCPerLink}});
if (idx < n - 1)
offsets_[idx + 1] = di_[idx].maxIndex() + offsets_[idx];
}
}

/**
@short gets index given typecode string
*/
size_t getEnumFromTypecode(std::string const& typecode) const {
auto it = typeCodeIndexer_.find(typecode);
if (it == typeCodeIndexer_.end())
throw cms::Exception("ValueError") << " unable to find typecode=" << typecode << " in cell indexer";
return it->second;
}

/**
@short checks if there is a typecode corresponding to an index
*/
std::string getTypecodeFromEnum(size_t idx) const {
for (const auto& it : typeCodeIndexer_)
if (it.second == idx)
return it.first;
throw cms::Exception("ValueError") << " unable to find typecode corresponding to idx=" << idx;
}

/**
@short returns the dense indexer for a typecode
*/
HGCalDenseIndexerBase getDenseIndexFor(std::string const& typecode) const {
return getDenseIndexerFor(getEnumFromTypecode(typecode));
}

/**
@short returns the dense indexer for a given internal index
*/
HGCalDenseIndexerBase getDenseIndexerFor(size_t idx) const {
if (idx >= di_.size())
throw cms::Exception("ValueError") << " index requested for cell dense indexer (i=" << idx
<< ") is larger than allocated";
return di_[idx];
}

/**
@short builders for the dense index
*/
uint16_t denseIndex(std::string const& typecode, uint32_t ROC, uint32_t trLink, uint32_t trCell) const {
return denseIndex(getEnumFromTypecode(typecode), ROC, trLink, trCell);
}
uint32_t denseIndex(size_t idx, uint32_t ROC, uint32_t trLink, uint32_t trCell) const {
return di_[idx].denseIndex({{ROC, trLink, trCell}}) + offsets_[idx];
}

/**
@short returns the max. dense index expected
*/
uint32_t maxDenseIndex() const {
size_t i = maxTrLink_.size();
if (i == 0)
return 0;
return offsets_.back() + maxROC_.back() * maxTrLink_.back() * maxTCPerLink_.back();
}

/**
@short gets the number of words (cells) for a given typecode
Note : some partials are rounded to the closest multiplie of 16 or 8 depending on the density
That is done because not all the TrigLinks,TrgCells possible are assigned in practice
e.g.: ML-T has 22 TCs but this will return 32 or MH-T has 19 but it will return 24
It results in a small mem overhead over the totall memory needed to be allocated
*/
size_t getNWordsExpectedFor(std::string const& typecode) const {
auto it = getEnumFromTypecode(typecode);
return getNWordsExpectedFor(it);
}
size_t getNWordsExpectedFor(size_t typecodeidx) const { return getDenseIndexerFor(typecodeidx).maxIndex(); }

/**
@short gets the number of Trigger Links for a given typecode
*/
size_t getNTrLinkExpectedFor(std::string const& typecode) const {
auto it = getEnumFromTypecode(typecode);
return getNTrLinkExpectedFor(it);
}
size_t getNTrLinkExpectedFor(size_t typecodeidx) const { return maxTrLink_[typecodeidx] * maxROC_[typecodeidx]; }

std::unordered_map<std::string, size_t> typeCodeIndexer_;
std::vector<uint16_t> maxROC_;
std::vector<uint16_t> maxTrLink_;
std::vector<uint16_t> maxTCPerLink_;
std::vector<uint32_t> offsets_;
std::vector<HGCalDenseIndexerBase> di_;

~HGCalMappingCellIndexerTrigger() = default;

COND_SERIALIZABLE;
};

#endif
30 changes: 15 additions & 15 deletions CondFormats/HGCalObjects/interface/HGCalMappingModuleIndexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class HGCalMappingModuleIndexer {
void finalize();

/**
* @short decode silicon or sipm type and cell type for the detector id
* @short decode silicon or sipm type and cell type for the detector id
* from the typecode string: "M[LH]-X[123]X-*" for Si, "T[LH]-L*S*[PN]" for SiPm
*/
static std::pair<bool, int8_t> getCellType(std::string_view typecode);
Expand Down Expand Up @@ -115,21 +115,21 @@ class HGCalMappingModuleIndexer {
/**
* @short return number maximum index of FED, ECON-D Module, eRx ROC
*/
uint32_t getNumFEDs() const {
uint32_t numFEDs() const {
return count_if(fedReadoutSequences_.begin(), fedReadoutSequences_.end(), [](auto fedrs) {
return fedrs.readoutTypes_.size() != 0;
});
} ///< return total number of FEDs that actually exist
uint32_t getMaxFEDSize() const {
uint32_t maxFEDSize() const {
return fedReadoutSequences_.size();
} ///< maximum FED index (fedReadoutSequences_ includes non existing FED IDs)
uint32_t getMaxModuleSize() const {
uint32_t maxModuleSize() const {
return maxModulesIdx_;
} ///< total number of ECON-Ds (useful for setting ECON-D SoA size)
uint32_t getNumModules(uint32_t fedid) const {
return fedReadoutSequences_[fedid].readoutTypes_.size();
} ///< number of ECON-Ds for given FED id
uint32_t getMaxERxSize() const {
uint32_t maxERxSize() const {
return maxErxIdx_;
} ///< total number of eRx half-ROCs (useful for setting config SoA size)
uint32_t getNumERxs(uint32_t fedid, uint32_t modid) const {
Expand All @@ -140,7 +140,7 @@ class HGCalMappingModuleIndexer {
const auto &[fedid, modid] = getIndexForFedAndModule(typecode);
return getNumERxs(fedid, modid);
} ///< number of eRx half-ROCs for a given ECON-D typecode
uint32_t getMaxDataSize() const {
uint32_t maxDataSize() const {
return maxDataIdx_;
} ///< total number of channels (useful for setting calib SoA size)
uint32_t getNumChannels(uint32_t fedid, uint32_t modid) const {
Expand All @@ -165,19 +165,19 @@ class HGCalMappingModuleIndexer {
/**
* @short getters for private members
*/
HGCalDenseIndexerBase const &getFEDIndexer() const { return modFedIndexer_; }
std::vector<HGCalFEDReadoutSequence> const &getFEDReadoutSequences() const { return fedReadoutSequences_; }
std::vector<uint32_t> const &getGlobalTypesCounter() const { return globalTypesCounter_; }
std::vector<uint32_t> const &getGlobalTypesNErx() const { return globalTypesNErx_; }
std::vector<uint32_t> const &getGlobalTypesNWords() const { return globalTypesNWords_; }
std::vector<uint32_t> const &getModuleOffsets() const { return moduleOffsets_; }
std::vector<uint32_t> const &getErxOffsets() const { return erxOffsets_; }
std::vector<uint32_t> const &getDataOffsets() const { return dataOffsets_; }
HGCalDenseIndexerBase const &fedIndexer() const { return modFedIndexer_; }
std::vector<HGCalFEDReadoutSequence> const &fedReadoutSequences() const { return fedReadoutSequences_; }
std::vector<uint32_t> const &globalTypesCounter() const { return globalTypesCounter_; }
std::vector<uint32_t> const &globalTypesNErx() const { return globalTypesNErx_; }
std::vector<uint32_t> const &globalTypesNWords() const { return globalTypesNWords_; }
std::vector<uint32_t> const &moduleOffsets() const { return moduleOffsets_; }
std::vector<uint32_t> const &erxOffsets() const { return erxOffsets_; }
std::vector<uint32_t> const &dataOffsets() const { return dataOffsets_; }
uint32_t fedCount() const { return nfeds_; }
uint32_t maxDataIndex() const { return maxDataIdx_; }
uint32_t maxErxIndex() const { return maxErxIdx_; }
uint32_t maxModulesIndex() const { return maxModulesIdx_; }
std::map<std::string, std::pair<uint32_t, uint32_t>> const &getTypecodeMap() const { return typecodeMap_; }
std::map<std::string, std::pair<uint32_t, uint32_t>> const &typecodeMap() const { return typecodeMap_; }

/// max number of main buffers/capture blocks per FED
constexpr static uint32_t maxCBperFED_ = 10;
Expand Down
Loading