CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 // Virtual destructor needed.
97 
98 // Functions that gets called by framework every event
100  // Step A: Get Inputs
102  e.getByToken(tok_raw_, rawraw);
103 
104  // Step B: Create empty output
105  auto trigd = std::make_unique<HcalTBTriggerData>();
106 
107  auto rund = std::make_unique<HcalTBRunData>();
108 
109  auto epd = std::make_unique<HcalTBEventPosition>();
110 
111  auto tmgd = std::make_unique<HcalTBTiming>();
112 
113  auto bcntd = std::make_unique<HcalTBBeamCounters>();
114 
115  auto spd = std::make_unique<HcalSourcePositionData>();
116 
117  if (triggerFed_ >= 0) {
118  // Step C: unpack all requested FEDs
119  const FEDRawData& fed = rawraw->FEDData(triggerFed_);
120  tdUnpacker_.unpack(fed, *trigd);
121  }
122 
123  if (sdFed_ >= 0) {
124  // Step C: unpack all requested FEDs
125  const FEDRawData& fed = rawraw->FEDData(sdFed_);
126  sdUnpacker_.unpack(fed, *rund, *epd);
127  }
128 
129  if (tdcFed_ >= 0) {
130  // Step C: unpack all requested FEDs
131  const FEDRawData& fed = rawraw->FEDData(tdcFed_);
132  tdcUnpacker_.unpack(fed, *epd, *tmgd);
133  }
134 
135  if (qadcFed_ >= 0) {
136  // Step C: unpack all requested FEDs
137  const FEDRawData& fed = rawraw->FEDData(qadcFed_);
138  bool is04 = true;
139  if (qadcFed_ == 8)
140  is04 = false;
141  qadcUnpacker_.unpack(fed, *bcntd, is04);
142  }
143 
144  if (spdFed_ >= 0) {
145  // Step C: unpack all requested FEDs
146  const FEDRawData& fed = rawraw->FEDData(spdFed_);
147  spdUnpacker_.unpack(fed, *spd);
148  }
149 
150  // Step D: Put outputs into event
151  if (doTriggerData_)
152  e.put(std::move(trigd));
153  if (doRunData_)
154  e.put(std::move(rund));
155  if (doEventPosition_)
156  e.put(std::move(epd));
157  if (doTiming_)
158  e.put(std::move(tmgd));
159  if (doBeamADC_)
160  e.put(std::move(bcntd));
161  if (doSourcePos_)
162  e.put(std::move(spd));
163 }
164 
166  if (calibFile_.empty()) {
167  printf("HcalTBObjectUnpacker cowardly refuses to parse a NULL file...\n");
168  return;
169  }
170 
172 
173  ifstream infile(fip.fullPath().c_str());
174 
175  char buffer[1024];
176  string tmpStr;
177 
178  while (infile.getline(buffer, 1024)) {
179  if (buffer[0] == '#')
180  continue; //ignore comment
181  if (buffer[0] == '/' && buffer[1] == '/')
182  continue; //ignore comment
183  tmpStr = string(buffer);
184  vector<string> lineVect;
185 
186  int start = 0;
187  bool empty = true;
188  for (unsigned i = 0; i <= tmpStr.size(); i++) {
189  if (tmpStr[i] == ' ' || i == tmpStr.size()) {
190  if (!empty) {
191  std::string item(tmpStr, start, i - start);
192  lineVect.push_back(item);
193  empty = true;
194  // printf("Got: %s\n",item.c_str());
195  }
196  start = i + 1;
197  } else {
198  if (empty)
199  empty = false;
200  }
201  }
202 
203  if (!lineVect.empty())
204  calibLines_.push_back(lineVect);
205  }
206 
207  infile.close();
208  return;
209 }
210 
213 
hcaltb::HcalTBTriggerDataUnpacker tdUnpacker_
void unpack(const FEDRawData &raw, HcalTBTriggerData &htbtd) const
void produce(edm::Event &e, const edm::EventSetup &c) override
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void unpack(const FEDRawData &raw, HcalTBBeamCounters &beamadc, bool is04_=true) const
std::vector< std::vector< std::string > > calibLines_
void unpack(const FEDRawData &raw, HcalSourcePositionData &hspd) const
hcaltb::HcalTBSlowDataUnpacker sdUnpacker_
hcaltb::HcalTBSourcePositionDataUnpacker spdUnpacker_
HcalTBObjectUnpacker(const edm::ParameterSet &ps)
printf("params %d %f %f %f\n", minT, eps, errmax, chi2max)
def move
Definition: eostools.py:511
void setCalib(const std::vector< std::vector< std::string > > &calibLines_)
edm::EDGetTokenT< FEDRawDataCollection > tok_raw_
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void unpack(const FEDRawData &raw, HcalTBRunData &htbrd, HcalTBEventPosition &htbep) const
void unpack(const FEDRawData &raw, HcalTBEventPosition &pos, HcalTBTiming &timing) const
hcaltb::HcalTBTDCUnpacker tdcUnpacker_
void setCalib(const std::vector< std::vector< std::string > > &calibLines_)
hcaltb::HcalTBQADCUnpacker qadcUnpacker_
std::string fullPath() const
Definition: FileInPath.cc:161
tuple cout
Definition: gather_cfg.py:144