CMS 3D CMS Logo

HGCalModuleTreeReader.cc
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * This is a part of HGCAL offline software.
4  * Authors:
5  * Pedro Silva, CERN
6  * Laurent Forthomme, CERN
7  *
8  ****************************************************************************/
9 
15 
16 #include "TChain.h"
17 
18 using namespace hgcal::econd;
19 
21  const std::string& tree_name,
22  const std::vector<std::string>& filenames)
23  : Emulator(params) {
24  TChain chain(tree_name.data());
25  for (const auto& filename : filenames)
26  chain.Add(filename.c_str());
27 
29  chain.SetBranchAddress("event", &event.event);
30  chain.SetBranchAddress("chip", &event.chip);
31  chain.SetBranchAddress("half", &event.half);
32  chain.SetBranchAddress("daqdata", &event.daqdata);
33  chain.SetBranchAddress("bxcounter", &event.bxcounter);
34  chain.SetBranchAddress("eventcounter", &event.eventcounter);
35  chain.SetBranchAddress("orbitcounter", &event.orbitcounter);
36  chain.SetBranchAddress("trigtime", &event.trigtime);
37  chain.SetBranchAddress("trigwidth", &event.trigwidth);
38 
39  for (long long i = 0; i < chain.GetEntries(); ++i) {
40  chain.GetEntry(i);
41 
42  // check if event already exists
43  EventId key{(uint32_t)event.eventcounter, (uint32_t)event.bxcounter, (uint32_t)event.orbitcounter};
44  if (data_.count(key) == 0)
45  data_[key] = ERxInput{};
46 
47  // check if chip already exists
48  ERxId_t erxKey{(uint8_t)event.chip, (uint8_t)event.half};
49  if (data_[key].count(erxKey) == 0)
50  data_[key][erxKey] = ERxData{};
51 
52  // daqdata: header, CM, 37 ch, CRC32, idle
53  if (const auto nwords = event.daqdata->size(); nwords != 41)
54  throw cms::Exception("HGCalModuleTreeReader")
55  << "Invalid number of words retrieved for event {" << event.eventcounter << ":" << event.bxcounter << ":"
56  << event.orbitcounter << "}: should be 41, got " << nwords << ".";
57 
58  // 1st word is the header: discard
59  // 2nd word are the common mode words
60 
61  const uint32_t cmword(event.daqdata->at(1));
62  if (((cmword >> 20) & 0xfff) != 0)
63  throw cms::Exception("HGCalModuleTreeReader")
64  << "Consistency check failed for common mode word: " << ((cmword >> 20) & 0xfff) << " != 0.";
65 
66  data_[key][erxKey].cm1 = cmword & 0x3ff;
67  data_[key][erxKey].cm0 = (cmword >> 10) & 0x3ff;
68 
69  // next 37 words are channel data
70  for (size_t i = 2; i < 2 + params_.num_channels_per_erx; i++) {
72  const auto tctp = static_cast<ToTStatus>(frame.tctp());
73  data_[key][erxKey].tctp.push_back(tctp);
74  data_[key][erxKey].adcm.push_back(frame.adcm1());
75  data_[key][erxKey].adc.push_back(tctp == ToTStatus::ZeroSuppressed ? frame.adc() : 0);
76  data_[key][erxKey].tot.push_back(tctp == ToTStatus::ZeroSuppressed ? frame.rawtot() : 0);
77  data_[key][erxKey].toa.push_back(frame.toa());
78  }
79 
80  // copy CRC32
81  data_[key][erxKey].crc32 = event.daqdata->at(39);
82 
83  // we could assert the idle word from #40 if needed
84 
85  // copy metadata
86  data_[key][erxKey].meta.push_back(event.trigtime);
87  data_[key][erxKey].meta.push_back(event.trigwidth);
88  }
89 
90  edm::LogInfo("HGCalModuleTreeReader") << "read " << data_.size() << " events.";
91 
92  it_data_ = data_.begin();
93 }
94 
95 //
97  if (it_data_ == data_.end())
98  throw cms::Exception("HGCalModuleTreeReader") << "Insufficient number of events were retrieved from input tree to "
99  "proceed with the generation of emulated events.";
100 
101  ++it_data_;
102  return ECONDInput{it_data_->first, it_data_->second};
103 }
std::pair< uint8_t, uint8_t > ERxId_t
chip/half
Definition: SlinkTypes.h:17
std::map< ERxId_t, ERxData > ERxInput
eRx data maps
Definition: SlinkTypes.h:29
parsed e-rx data
Definition: SlinkTypes.h:20
ECONDInputColl::const_iterator it_data_
Pure virtual base class for a ECON-D event emulator implementation.
ECONDInput next() override
Fetch the next ECON-D event.
const EmulatorParameters params_
std::pair< EventId, ERxInput > ECONDInput
ECON-D inputs for a given event.
Definition: SlinkTypes.h:32
Log< level::Info, false > LogInfo
std::tuple< uint32_t, uint32_t, uint32_t > EventId
Event index (L1A/BX/orbit)
Definition: SlinkTypes.h:14
wrapper for a 32b data word from a single channel and its detid The format is always the same: |1b|1b...
Definition: event.py:1
HGCalModuleTreeReader(const EmulatorParameters &, const std::string &tree_name, const std::vector< std::string > &filenames)