CMS 3D CMS Logo

HcalTBObjectUnpacker.cc
Go to the documentation of this file.
1 
10 #include <iostream>
11 #include <fstream>
12 using namespace std;
13 
15  : triggerFed_(conf.getUntrackedParameter<int>("HcalTriggerFED", -1)),
16  sdFed_(conf.getUntrackedParameter<int>("HcalSlowDataFED", -1)),
17  spdFed_(conf.getUntrackedParameter<int>("HcalSourcePositionFED", -1)),
18  tdcFed_(conf.getUntrackedParameter<int>("HcalTDCFED", -1)),
19  qadcFed_(conf.getUntrackedParameter<int>("HcalQADCFED", -1)),
20  calibFile_(conf.getUntrackedParameter<string>("ConfigurationFile", "")),
21  tdcUnpacker_(conf.getUntrackedParameter<bool>("IncludeUnmatchedHits", false)),
22  doRunData_(false),
23  doTriggerData_(false),
24  doEventPosition_(false),
25  doTiming_(false),
26  doSourcePos_(false),
27  doBeamADC_(false) {
28  tok_raw_ = consumes<FEDRawDataCollection>(conf.getParameter<edm::InputTag>("fedRawDataCollectionTag"));
29 
30  if (triggerFed_ >= 0) {
31  std::cout << "HcalTBObjectUnpacker will unpack Trigger FED ";
32  std::cout << triggerFed_ << endl;
33  doTriggerData_ = true;
34  }
35 
36  if (sdFed_ >= 0) {
37  std::cout << "HcalTBObjectUnpacker will unpack SlowData FED ";
38  std::cout << sdFed_ << endl;
39  doRunData_ = true;
40  doEventPosition_ = true; // at least the table
41  }
42 
43  if (tdcFed_ >= 0) {
44  std::cout << "HcalTBObjectUnpacker will unpack TDC FED ";
45  std::cout << tdcFed_ << endl;
46  doTiming_ = true;
47  doEventPosition_ = true; // at least the WC
48  }
49 
50  if (qadcFed_ >= 0) {
51  std::cout << "HcalTBObjectUnpacker will unpack QADC FED ";
52  std::cout << qadcFed_ << endl;
53  doBeamADC_ = true;
54  }
55 
56  if (spdFed_ >= 0) {
57  std::cout << "HcalTBObjectUnpacker will unpack Source Position Data FED ";
58  std::cout << spdFed_ << endl;
59  doSourcePos_ = true;
60  }
61 
62  if (tdcFed_ >= 0 || qadcFed_ >= 0) {
63  calibLines_.clear();
64  if (!calibFile_.empty()) {
65  parseCalib();
66  // printf("I got %d lines!\n",calibLines_.size());
67  if (calibLines_.empty())
68  throw cms::Exception("Incomplete configuration")
69  << "HcalTBObjectUnpacker: TDC/QADC/WC configuration file not found or is empty: " << calibFile_ << endl;
70  } else {
71  throw cms::Exception("Incomplete configuration")
72  << "HcalTBObjectUnpacker: TDC/QADC/WC configuration file not found: " << calibFile_ << endl;
73  }
74  }
75 
76  if (doTriggerData_)
77  produces<HcalTBTriggerData>();
78  if (doRunData_)
79  produces<HcalTBRunData>();
80  if (doEventPosition_)
81  produces<HcalTBEventPosition>();
82  if (doTiming_)
83  produces<HcalTBTiming>();
84  // if (doBeamADC_) produces<HcalTBBeamCounters>();
85  if (doBeamADC_) {
86  produces<HcalTBBeamCounters>();
88  }
89  if (doSourcePos_)
90  produces<HcalSourcePositionData>();
93 }
94 
95 // Functions that gets called by framework every event
97  // Step A: Get Inputs
99  e.getByToken(tok_raw_, rawraw);
100 
101  // Step B: Create empty output
102  auto trigd = std::make_unique<HcalTBTriggerData>();
103 
104  auto rund = std::make_unique<HcalTBRunData>();
105 
106  auto epd = std::make_unique<HcalTBEventPosition>();
107 
108  auto tmgd = std::make_unique<HcalTBTiming>();
109 
110  auto bcntd = std::make_unique<HcalTBBeamCounters>();
111 
112  auto spd = std::make_unique<HcalSourcePositionData>();
113 
114  if (triggerFed_ >= 0) {
115  // Step C: unpack all requested FEDs
116  const FEDRawData& fed = rawraw->FEDData(triggerFed_);
117  tdUnpacker_.unpack(fed, *trigd);
118  }
119 
120  if (sdFed_ >= 0) {
121  // Step C: unpack all requested FEDs
122  const FEDRawData& fed = rawraw->FEDData(sdFed_);
123  sdUnpacker_.unpack(fed, *rund, *epd);
124  }
125 
126  if (tdcFed_ >= 0) {
127  // Step C: unpack all requested FEDs
128  const FEDRawData& fed = rawraw->FEDData(tdcFed_);
129  tdcUnpacker_.unpack(fed, *epd, *tmgd);
130  }
131 
132  if (qadcFed_ >= 0) {
133  // Step C: unpack all requested FEDs
134  const FEDRawData& fed = rawraw->FEDData(qadcFed_);
135  bool is04 = true;
136  if (qadcFed_ == 8)
137  is04 = false;
138  qadcUnpacker_.unpack(fed, *bcntd, is04);
139  }
140 
141  if (spdFed_ >= 0) {
142  // Step C: unpack all requested FEDs
143  const FEDRawData& fed = rawraw->FEDData(spdFed_);
144  spdUnpacker_.unpack(fed, *spd);
145  }
146 
147  // Step D: Put outputs into event
148  if (doTriggerData_)
149  e.put(std::move(trigd));
150  if (doRunData_)
151  e.put(std::move(rund));
152  if (doEventPosition_)
153  e.put(std::move(epd));
154  if (doTiming_)
155  e.put(std::move(tmgd));
156  if (doBeamADC_)
157  e.put(std::move(bcntd));
158  if (doSourcePos_)
159  e.put(std::move(spd));
160 }
161 
163  if (calibFile_.empty()) {
164  printf("HcalTBObjectUnpacker cowardly refuses to parse a NULL file...\n");
165  return;
166  }
167 
169 
170  ifstream infile(fip.fullPath().c_str());
171 
172  char buffer[1024];
173  string tmpStr;
174 
175  while (infile.getline(buffer, 1024)) {
176  if (buffer[0] == '#')
177  continue; //ignore comment
178  if (buffer[0] == '/' && buffer[1] == '/')
179  continue; //ignore comment
180  tmpStr = string(buffer);
181  vector<string> lineVect;
182 
183  int start = 0;
184  bool empty = true;
185  for (unsigned i = 0; i <= tmpStr.size(); i++) {
186  if (tmpStr[i] == ' ' || i == tmpStr.size()) {
187  if (!empty) {
188  std::string item(tmpStr, start, i - start);
189  lineVect.push_back(item);
190  empty = true;
191  // printf("Got: %s\n",item.c_str());
192  }
193  start = i + 1;
194  } else {
195  if (empty)
196  empty = false;
197  }
198  }
199 
200  if (!lineVect.empty())
201  calibLines_.push_back(lineVect);
202  }
203 
204  infile.close();
205  return;
206 }
207 
210 
Definition: start.py:1
hcaltb::HcalTBTriggerDataUnpacker tdUnpacker_
void produce(edm::Event &e, const edm::EventSetup &c) override
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
std::string fullPath() const
Definition: FileInPath.cc:161
std::vector< std::vector< std::string > > calibLines_
hcaltb::HcalTBSlowDataUnpacker sdUnpacker_
hcaltb::HcalTBSourcePositionDataUnpacker spdUnpacker_
HcalTBObjectUnpacker(const edm::ParameterSet &ps)
void unpack(const FEDRawData &raw, HcalTBRunData &htbrd, HcalTBEventPosition &htbep) const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void setCalib(const std::vector< std::vector< std::string > > &calibLines_)
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
void unpack(const FEDRawData &raw, HcalTBTriggerData &htbtd) const
edm::EDGetTokenT< FEDRawDataCollection > tok_raw_
void unpack(const FEDRawData &raw, HcalSourcePositionData &hspd) const
hcaltb::HcalTBTDCUnpacker tdcUnpacker_
void unpack(const FEDRawData &raw, HcalTBBeamCounters &beamadc, bool is04_=true) const
void setCalib(const std::vector< std::vector< std::string > > &calibLines_)
hcaltb::HcalTBQADCUnpacker qadcUnpacker_
void unpack(const FEDRawData &raw, HcalTBEventPosition &pos, HcalTBTiming &timing) const
def move(src, dest)
Definition: eostools.py:511