CMS 3D CMS Logo

HGCalMappingCellESProducer.cc
Go to the documentation of this file.
4 
10 
19 
20 #include <string>
21 #include <iostream>
22 #include <fstream>
23 #include <sstream>
24 
26 
27  namespace hgcal {
28 
30  public:
31  //
33  : ESProducer(iConfig), filelist_(iConfig.getParameter<std::vector<std::string> >("filelist")) {
34  auto cc = setWhatProduced(this);
35  cellIndexTkn_ = cc.consumes(iConfig.getParameter<edm::ESInputTag>("cellindexer"));
36  }
37 
38  //
39  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
41  desc.add<std::vector<std::string> >("filelist", std::vector<std::string>({}))
42  ->setComment("list of files with the readout cells of each module");
43  desc.add<edm::ESInputTag>("cellindexer", edm::ESInputTag(""))->setComment("Dense cell index tool");
44  descriptions.addWithDefaultLabel(desc);
45  }
46 
47  //
48  std::optional<HGCalMappingCellParamHostCollection> produce(const HGCalElectronicsMappingRcd& iRecord) {
49  //get cell indexer
50  const HGCalMappingCellIndexer& cellIndexer = iRecord.get(cellIndexTkn_);
51  const uint32_t size = cellIndexer.maxDenseIndex(); // channel-level size
53  for (uint32_t i = 0; i < size; i++)
54  cellParams.view()[i].valid() = false;
55 
56  //loop over cell types and then over cells
57  for (auto url : filelist_) {
59  edm::FileInPath fip(url);
60  pmap.buildFrom(fip.fullPath());
61  auto& entities = pmap.getEntries();
62  for (auto row : entities) {
63  //identify special cases (Si vs SiPM, calib vs normal)
64  std::string typecode = pmap.getAttr("Typecode", row);
65  auto typeidx = cellIndexer.getEnumFromTypecode(typecode);
66  bool isSiPM = typecode.find("TM") != std::string::npos;
67  int rocpin = pmap.getIntAttr("ROCpin", row);
68  int celltype = pmap.getIntAttr("t", row);
69  int i1(0), i2(0), sensorcell(0);
70  bool isHD(false), iscalib(false);
71  uint32_t detid(0);
72  if (isSiPM) {
73  i1 = pmap.getIntAttr("iring", row);
74  i2 = pmap.getIntAttr("iphi", row);
75  } else {
76  i1 = pmap.getIntAttr("iu", row);
77  i2 = pmap.getIntAttr("iv", row);
78  isHD = {typecode.find("MH") != std::string::npos ? true : false};
79  sensorcell = pmap.getIntAttr("SiCell", row);
80  if (celltype == 0) {
81  iscalib = true;
82  std::string rocpinstr = pmap.getAttr("ROCpin", row);
83  rocpin = uint16_t(rocpinstr[rocpinstr.size() - 1]);
84  }
85 
86  //detector id is initiated for a random sub-detector with Si wafers
87  //we only care about the first 10bits where the cell u-v are stored
88  DetId::Detector det(DetId::Detector::HGCalEE);
89  detid = 0x3ff & HGCSiliconDetId(det, 0, 0, 0, 0, 0, i1, i2).rawId();
90  }
91 
92  //fill cell info in the appopriate dense index
93  int chip = pmap.getIntAttr("ROC", row);
94  int half = pmap.getIntAttr("HalfROC", row);
95  int seq = pmap.getIntAttr("Seq", row);
96  int idx = cellIndexer.denseIndex(typecode, chip, half, seq);
97  auto cell = cellParams.view()[idx];
98  cell.valid() = true;
99  cell.isHD() = isHD;
100  cell.iscalib() = iscalib;
101  cell.isSiPM() = isSiPM;
102  cell.typeidx() = typeidx;
103  cell.chip() = chip;
104  cell.half() = half;
105  cell.seq() = seq;
106  cell.rocpin() = rocpin;
107  cell.sensorcell() = sensorcell;
108  cell.triglink() = pmap.getIntAttr("TrLink", row);
109  cell.trigcell() = pmap.getIntAttr("TrCell", row);
110  cell.i1() = i1;
111  cell.i2() = i2;
112  cell.t() = celltype;
113  cell.trace() = pmap.getFloatAttr("trace", row);
114  cell.eleid() = HGCalElectronicsId(false, 0, 0, 0, chip * 2 + half, seq).raw();
115  cell.detid() = detid;
116  } //end loop over entities
117  } //end loop over cell types
118 
119  return cellParams;
120  } // end of produce()
121 
122  private:
124  const std::vector<std::string> filelist_;
125  };
126 
127  } // namespace hgcal
128 
129 } // namespace ALPAKA_ACCELERATOR_NAMESPACE
130 
131 DEFINE_FWK_EVENTSETUP_ALPAKA_MODULE(hgcal::HGCalMappingCellESProducer);
uint32_t raw() const
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:166
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
uint32_t maxDenseIndex() const
returns the max. dense index expected
std::optional< HGCalMappingCellParamHostCollection > produce(const HGCalElectronicsMappingRcd &iRecord)
float getIntAttr(std::string col, HGCalEntityRow &row)
uint32_t cc[maxCellsPerHit]
Definition: gpuFishbone.h:49
uint32_t denseIndex(std::string typecode, uint32_t chip, uint32_t half, uint32_t seq) const
builders for the dense index
const std::vector< HGCalEntityRow > & getEntries()
edm::ESGetToken< HGCalMappingCellIndexer, HGCalElectronicsMappingRcd > cellIndexTkn_
size_t getEnumFromTypecode(std::string typecode) const
gets index given typecode string
HGCalEntityAttr getAttr(std::string col, HGCalEntityRow &row)
gets the attribute corresponding the column col in a row
PRODUCT const & get(ESGetToken< PRODUCT, T > const &iToken) const
bool isSiPM(int ieta, int iphi, int depth)
float getFloatAttr(std::string col, HGCalEntityRow &row)
wrapper for a 32b data word identifying a readout channel in the raw data The format is the following...
alpaka::DevCpu const & host()
Definition: host.h:14
void buildFrom(std::string url)
builds the entity list from a file
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
Detector
Definition: DetId.h:24
utility class to assign dense readout cell indexing
::hgcal::HGCalMappingCellParamHostCollection HGCalMappingCellParamHostCollection
#define DEFINE_FWK_EVENTSETUP_ALPAKA_MODULE(type)
Definition: ModuleFactory.h:17
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const std::string & fullPath() const
Definition: FileInPath.cc:144