CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalTBObjectUnpacker.cc
Go to the documentation of this file.
1 using namespace std;
2 
13 #include <iostream>
14 #include <fstream>
15 
16 
18  triggerFed_(conf.getUntrackedParameter<int>("HcalTriggerFED",-1)),
19  sdFed_(conf.getUntrackedParameter<int>("HcalSlowDataFED",-1)),
20  spdFed_(conf.getUntrackedParameter<int>("HcalSourcePositionFED",-1)),
21  tdcFed_(conf.getUntrackedParameter<int>("HcalTDCFED",-1)),
22  qadcFed_(conf.getUntrackedParameter<int>("HcalQADCFED",-1)),
23  calibFile_(conf.getUntrackedParameter<string>("ConfigurationFile","")),
24  tdcUnpacker_(conf.getUntrackedParameter<bool>("IncludeUnmatchedHits",false)),
25  doRunData_(false),doTriggerData_(false),doEventPosition_(false),doTiming_(false),doSourcePos_(false),doBeamADC_(false)
26  {
27 
28  if (triggerFed_ >=0) {
29  std::cout << "HcalTBObjectUnpacker will unpack Trigger FED ";
30  std::cout << triggerFed_ << endl;
31  doTriggerData_=true;
32  }
33 
34  if (sdFed_ >=0) {
35  std::cout << "HcalTBObjectUnpacker will unpack SlowData FED ";
36  std::cout << sdFed_ << endl;
37  doRunData_=true;
38  doEventPosition_=true; // at least the table
39  }
40 
41  if (tdcFed_ >=0) {
42  std::cout << "HcalTBObjectUnpacker will unpack TDC FED ";
43  std::cout << tdcFed_ << endl;
44  doTiming_=true;
45  doEventPosition_=true; // at least the WC
46  }
47 
48  if (qadcFed_ >=0) {
49  std::cout << "HcalTBObjectUnpacker will unpack QADC FED ";
50  std::cout << qadcFed_ << endl;
51  doBeamADC_=true;
52  }
53 
54  if (spdFed_ >=0) {
55  std::cout << "HcalTBObjectUnpacker will unpack Source Position Data FED ";
56  std::cout << spdFed_ << endl;
57  doSourcePos_=true;
58  }
59 
60 
61  if (tdcFed_ >= 0 || qadcFed_ >=0 ) {
62  calibLines_.clear();
63  if(calibFile_.size()>0){
64  parseCalib();
65  // printf("I got %d lines!\n",calibLines_.size());
66  if(calibLines_.size()==0)
67  throw cms::Exception("Incomplete configuration") <<
68  "HcalTBObjectUnpacker: TDC/QADC/WC configuration file not found or is empty: "<<calibFile_<<endl;
69  }
70  else{
71  throw cms::Exception("Incomplete configuration") <<
72  "HcalTBObjectUnpacker: TDC/QADC/WC configuration file not found: "<<calibFile_<<endl;
73  }
74  }
75 
76 
77  if (doTriggerData_) produces<HcalTBTriggerData>();
78  if (doRunData_) produces<HcalTBRunData>();
79  if (doEventPosition_) produces<HcalTBEventPosition>();
80  if (doTiming_) produces<HcalTBTiming>();
81 // if (doBeamADC_) produces<HcalTBBeamCounters>();
82  if (doBeamADC_) {produces<HcalTBBeamCounters>();qadcUnpacker_.setCalib(calibLines_);}
83 // if (doSourcePos_) produces<HcalSourcePositionData>();
85  }
86 
87  // Virtual destructor needed.
89 
90  // Functions that gets called by framework every event
92  {
93  // Step A: Get Inputs
95  // edm::ProcessNameSelector s("PROD"); // HACK!
96  e.getByType(rawraw);
97 
98  // Step B: Create empty output
99  std::auto_ptr<HcalTBTriggerData>
100  trigd(new HcalTBTriggerData);
101 
102  std::auto_ptr<HcalTBRunData>
103  rund(new HcalTBRunData);
104 
105  std::auto_ptr<HcalTBEventPosition>
106  epd(new HcalTBEventPosition);
107 
108  std::auto_ptr<HcalTBTiming>
109  tmgd(new HcalTBTiming);
110 
111  std::auto_ptr<HcalTBBeamCounters>
112  bcntd(new HcalTBBeamCounters);
113 
114  std::auto_ptr<HcalSourcePositionData>
115  spd(new 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) is04=false;
140  qadcUnpacker_.unpack(fed, *bcntd,is04);
141  }
142 
143  if (spdFed_ >=0) {
144  // Step C: unpack all requested FEDs
145  const FEDRawData& fed = rawraw->FEDData(spdFed_);
146  spdUnpacker_.unpack(fed, *spd);
147  }
148 
149  // Step D: Put outputs into event
150  if (doTriggerData_) e.put(trigd);
151  if (doRunData_) e.put(rund);
152  if (doEventPosition_) e.put(epd);
153  if (doTiming_) e.put(tmgd);
154  if (doBeamADC_) e.put(bcntd);
155  if (doSourcePos_) e.put(spd);
156  }
157 
158 
160 
161  if(calibFile_.size()==0){
162  printf("HcalTBObjectUnpacker cowardly refuses to parse a NULL file...\n");
163  return;
164  }
165 
166  ifstream infile(calibFile_.c_str());
167 
168  char buffer [1024];
169  string tmpStr;
170 
171  while (infile.getline(buffer, 1024)) {
172  if (buffer [0] == '#') continue; //ignore comment
173  if (buffer [0] == '/' && buffer [1] == '/') continue; //ignore comment
174  tmpStr = string(buffer);
175  vector<string> lineVect;
176 
177  int start = 0; bool empty = true;
178  for (unsigned i=0; i<=tmpStr.size(); i++) {
179  if (tmpStr[i] == ' ' || i==tmpStr.size()) {
180  if (!empty) {
181  std::string item(tmpStr, start, i-start);
182  lineVect.push_back(item);
183  empty = true;
184 // printf("Got: %s\n",item.c_str());
185  }
186  start = i+1;
187  }
188  else {
189  if (empty) empty = false;
190  }
191  }
192 
193  if(lineVect.size()>0) calibLines_.push_back(lineVect);
194  }
195 
196  infile.close();
197  return;
198 }
hcaltb::HcalTBTriggerDataUnpacker tdUnpacker_
int i
Definition: DBlmapReader.cc:9
void unpack(const FEDRawData &raw, HcalTBBeamCounters &beamadc, bool is04_=true) const
bool getByType(Handle< PROD > &result) const
Definition: Event.h:403
std::vector< std::vector< std::string > > calibLines_
hcaltb::HcalTBSlowDataUnpacker sdUnpacker_
hcaltb::HcalTBSourcePositionDataUnpacker spdUnpacker_
void unpack(const FEDRawData &raw, HcalTBTriggerData &htbtd)
HcalTBObjectUnpacker(const edm::ParameterSet &ps)
void unpack(const FEDRawData &raw, HcalTBRunData &htbrd, HcalTBEventPosition &htbep)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:84
void unpack(const FEDRawData &raw, HcalSourcePositionData &hspd)
void setCalib(const std::vector< std::vector< std::string > > &calibLines_)
tuple conf
Definition: dbtoconf.py:185
virtual void produce(edm::Event &e, const edm::EventSetup &c)
void unpack(const FEDRawData &raw, HcalTBEventPosition &pos, HcalTBTiming &timing) const
hcaltb::HcalTBTDCUnpacker tdcUnpacker_
void setCalib(const std::vector< std::vector< std::string > > &calibLines_)
list infile
Definition: EdgesToViz.py:90
hcaltb::HcalTBQADCUnpacker qadcUnpacker_
tuple cout
Definition: gather_cfg.py:41