CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Private Attributes
hgcal::econd::HGCalModuleTreeReader Class Reference

#include <HGCalModuleTreeReader.h>

Inheritance diagram for hgcal::econd::HGCalModuleTreeReader:
hgcal::econd::Emulator

Classes

struct  HGCModuleTreeEvent
 Input tree collections. More...
 

Public Member Functions

 HGCalModuleTreeReader (const EmulatorParameters &, const std::string &tree_name, const std::vector< std::string > &filenames)
 
ECONDInput next () override
 Fetch the next ECON-D event. More...
 
- Public Member Functions inherited from hgcal::econd::Emulator
 Emulator (const EmulatorParameters &params)
 
virtual ~Emulator ()=default
 

Private Attributes

ECONDInputColl data_
 
ECONDInputColl::const_iterator it_data_
 

Additional Inherited Members

- Protected Attributes inherited from hgcal::econd::Emulator
const EmulatorParameters params_
 

Detailed Description

Read out a the relevant raw data produced by a module to memory and returns ECON-D frames on request

Note
The format is as agreed with system tests convenors so that it can be used in integration/beam tests

Definition at line 18 of file HGCalModuleTreeReader.h.

Constructor & Destructor Documentation

◆ HGCalModuleTreeReader()

HGCalModuleTreeReader::HGCalModuleTreeReader ( const EmulatorParameters params,
const std::string &  tree_name,
const std::vector< std::string > &  filenames 
)
explicit
Parameters
[in]tree_nameName of the TB events tree
[in]filenamesList of filenames to loop on
[in]num_channelsChannels multiplicity

Definition at line 20 of file HGCalModuleTreeReader.cc.

References submitPVResolutionJobs::count, data_, edmPickEvents::event, corrVsCorr::filename, amptDefault_cfi::frame, mps_fire::i, it_data_, submitPVResolutionJobs::key, hgcal::econd::EmulatorParameters::num_channels_per_erx, hgcal::econd::Emulator::params_, and siStripShotFilter_cfi::ZeroSuppressed.

23  : Emulator(params) {
24  TChain chain(tree_name.data());
25  for (const auto& filename : filenames)
26  chain.Add(filename.c_str());
27 
28  HGCModuleTreeEvent event;
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 }
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_
key
prepare the HTCondor submission files and eventually submit them
const EmulatorParameters params_
Emulator(const EmulatorParameters &params)
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

Member Function Documentation

◆ next()

ECONDInput HGCalModuleTreeReader::next ( )
overridevirtual

Fetch the next ECON-D event.

Implements hgcal::econd::Emulator.

Definition at line 96 of file HGCalModuleTreeReader.cc.

References data_, and it_data_.

96  {
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 }
ECONDInputColl::const_iterator it_data_
std::pair< EventId, ERxInput > ECONDInput
ECON-D inputs for a given event.
Definition: SlinkTypes.h:32

Member Data Documentation

◆ data_

ECONDInputColl hgcal::econd::HGCalModuleTreeReader::data_
private

Definition at line 36 of file HGCalModuleTreeReader.h.

Referenced by HGCalModuleTreeReader(), and next().

◆ it_data_

ECONDInputColl::const_iterator hgcal::econd::HGCalModuleTreeReader::it_data_
private

Definition at line 37 of file HGCalModuleTreeReader.h.

Referenced by HGCalModuleTreeReader(), and next().