CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalRawToDigi.cc
Go to the documentation of this file.
1 using namespace std;
11 #include <iostream>
12 
14  unpacker_(conf.getUntrackedParameter<int>("HcalFirstFED",int(FEDNumbering::MINHCALFEDID)),conf.getParameter<int>("firstSample"),conf.getParameter<int>("lastSample")),
15  filter_(conf.getParameter<bool>("FilterDataQuality"),conf.getParameter<bool>("FilterDataQuality"),
16  false,
17  0, 0,
18  -1),
19  fedUnpackList_(conf.getUntrackedParameter<std::vector<int> >("FEDs", std::vector<int>())),
20  firstFED_(conf.getUntrackedParameter<int>("HcalFirstFED",FEDNumbering::MINHCALFEDID)),
21  unpackCalib_(conf.getUntrackedParameter<bool>("UnpackCalib",false)),
22  unpackZDC_(conf.getUntrackedParameter<bool>("UnpackZDC",false)),
23  unpackTTP_(conf.getUntrackedParameter<bool>("UnpackTTP",false)),
24  silent_(conf.getUntrackedParameter<bool>("silent",true)),
25  complainEmptyData_(conf.getUntrackedParameter<bool>("ComplainEmptyData",false)),
26  unpackerMode_(conf.getUntrackedParameter<int>("UnpackerMode",0)),
27  expectedOrbitMessageTime_(conf.getUntrackedParameter<int>("ExpectedOrbitMessageTime",-1))
28 {
29  electronicsMapLabel_ = conf.getParameter<std::string>("ElectronicsMap");
30  tok_data_ = consumes<FEDRawDataCollection>(conf.getParameter<edm::InputTag>("InputLabel"));
31 
32  if (fedUnpackList_.empty()) {
34  fedUnpackList_.push_back(i);
35  // HF uTCA
36  fedUnpackList_.push_back(1118);
37  fedUnpackList_.push_back(1120);
38  fedUnpackList_.push_back(1122);
39  }
40 
43  std::ostringstream ss;
44  for (unsigned int i=0; i<fedUnpackList_.size(); i++)
45  ss << fedUnpackList_[i] << " ";
46  edm::LogInfo("HCAL") << "HcalRawToDigi will unpack FEDs ( " << ss.str() << ")";
47 
48  // products produced...
49  produces<HBHEDigiCollection>();
50  produces<HFDigiCollection>();
51  produces<HODigiCollection>();
52  produces<HcalTrigPrimDigiCollection>();
53  produces<HOTrigPrimDigiCollection>();
54  produces<HcalUnpackerReport>();
55  if (unpackCalib_)
56  produces<HcalCalibDigiCollection>();
57  if (unpackZDC_)
58  produces<ZDCDigiCollection>();
59  if (unpackTTP_)
60  produces<HcalTTPDigiCollection>();
61  produces<QIE10DigiCollection>();
62 
63  memset(&stats_,0,sizeof(stats_));
64 
65 }
66 
67 // Virtual destructor needed.
69 
72  desc.addUntracked<int>("HcalFirstFED",int(FEDNumbering::MINHCALFEDID));
73  desc.add<int>("firstSample",0);
74  desc.add<int>("lastSample",9);
75  desc.add<bool>("FilterDataQuality",true);
76  desc.addUntracked<std::vector<int>>("FEDs", std::vector<int>());
77  desc.addUntracked<bool>("UnpackZDC",true);
78  desc.addUntracked<bool>("UnpackCalib",true);
79  desc.addUntracked<bool>("UnpackTTP",true);
80  desc.addUntracked<bool>("silent",true);
81  desc.addUntracked<bool>("ComplainEmptyData",false);
82  desc.addUntracked<int>("UnpackerMode",0);
83  desc.addUntracked<int>("ExpectedOrbitMessageTime",-1);
84  desc.add<edm::InputTag>("InputLabel",edm::InputTag("rawDataCollector"));
85  desc.add<std::string>("ElectronicsMap","");
86  descriptions.add("hcalRawToDigi",desc);
87 }
88 
89 
90 // Functions that gets called by framework every event
92 {
93  // Step A: Get Inputs
95  e.getByToken(tok_data_,rawraw);
96  // get the mapping
98  es.get<HcalDbRecord>().get( pSetup );
101  const HcalElectronicsMap* readoutMap = item.product();
102 
103  // Step B: Create empty output : three vectors for three classes...
104  std::vector<HBHEDataFrame> hbhe;
105  std::vector<HODataFrame> ho;
106  std::vector<HFDataFrame> hf;
107  std::vector<HcalTriggerPrimitiveDigi> htp;
108  std::vector<HcalCalibDataFrame> hc;
109  std::vector<ZDCDataFrame> zdc;
110  std::vector<HcalTTPDigi> ttp;
111  std::vector<HOTriggerPrimitiveDigi> hotp;
112  std::auto_ptr<HcalUnpackerReport> report(new HcalUnpackerReport);
113 
114  // Heuristics: use ave+(max-ave)/8
115  if (stats_.max_hbhe>0) hbhe.reserve(stats_.ave_hbhe+(stats_.max_hbhe-stats_.ave_hbhe)/8);
116  if (stats_.max_ho>0) ho.reserve(stats_.ave_ho+(stats_.max_ho-stats_.ave_ho)/8);
117  if (stats_.max_hf>0) hf.reserve(stats_.ave_hf+(stats_.max_hf-stats_.ave_hf)/8);
119  if (stats_.max_tp>0) htp.reserve(stats_.ave_tp+(stats_.max_tp-stats_.ave_tp)/8);
120  if (stats_.max_tpho>0) hotp.reserve(stats_.ave_tpho+(stats_.max_tpho-stats_.ave_tpho)/8);
121 
122  if (unpackZDC_) zdc.reserve(24);
123 
124 
126  colls.hbheCont=&hbhe;
127  colls.hoCont=&ho;
128  colls.hfCont=&hf;
129  colls.tpCont=&htp;
130  colls.tphoCont=&hotp;
131  colls.calibCont=&hc;
132  colls.zdcCont=&zdc;
133  if (unpackTTP_) colls.ttp=&ttp;
134 
135  // Step C: unpack all requested FEDs
136  for (std::vector<int>::const_iterator i=fedUnpackList_.begin(); i!=fedUnpackList_.end(); i++) {
137  const FEDRawData& fed = rawraw->FEDData(*i);
138  if (fed.size()==0) {
139  if (complainEmptyData_) {
140  if (!silent_) edm::LogWarning("EmptyData") << "No data for FED " << *i;
141  report->addError(*i);
142  }
143  } else if (fed.size()<8*3) {
144  if (!silent_) edm::LogWarning("EmptyData") << "Tiny data " << fed.size() << " for FED " << *i;
145  report->addError(*i);
146  } else {
147  try {
148  unpacker_.unpack(fed,*readoutMap,colls, *report,silent_);
149  report->addUnpacked(*i);
150  } catch (cms::Exception& e) {
151  if (!silent_) edm::LogWarning("Unpacking error") << e.what();
152  report->addError(*i);
153  } catch (...) {
154  if (!silent_) edm::LogWarning("Unpacking exception");
155  report->addError(*i);
156  }
157  }
158  }
159 
160 
161  // gather statistics
162  stats_.max_hbhe=std::max(stats_.max_hbhe,(int)hbhe.size());
163  stats_.ave_hbhe=(stats_.ave_hbhe*stats_.n+hbhe.size())/(stats_.n+1);
164  stats_.max_ho=std::max(stats_.max_ho,(int)ho.size());
165  stats_.ave_ho=(stats_.ave_ho*stats_.n+ho.size())/(stats_.n+1);
166  stats_.max_hf=std::max(stats_.max_hf,(int)hf.size());
167  stats_.ave_hf=(stats_.ave_hf*stats_.n+hf.size())/(stats_.n+1);
168  stats_.max_tp=std::max(stats_.max_tp,(int)htp.size());
169  stats_.ave_tp=(stats_.ave_tp*stats_.n+htp.size())/(stats_.n+1);
170  stats_.max_tpho=std::max(stats_.max_tpho,(int)hotp.size());
171  stats_.ave_tpho=(stats_.ave_tpho*stats_.n+hotp.size())/(stats_.n+1);
172  stats_.max_calib=std::max(stats_.max_calib,(int)hc.size());
173  stats_.ave_calib=(stats_.ave_calib*stats_.n+hc.size())/(stats_.n+1);
174 
175 
176  stats_.n++;
177 
178  // Step B: encapsulate vectors in actual collections
179  std::auto_ptr<HBHEDigiCollection> hbhe_prod(new HBHEDigiCollection());
180  std::auto_ptr<HFDigiCollection> hf_prod(new HFDigiCollection());
181  std::auto_ptr<HODigiCollection> ho_prod(new HODigiCollection());
182  std::auto_ptr<HcalTrigPrimDigiCollection> htp_prod(new HcalTrigPrimDigiCollection());
183  std::auto_ptr<HOTrigPrimDigiCollection> hotp_prod(new HOTrigPrimDigiCollection());
184  if (colls.qie10 == 0) {
185  colls.qie10 = new QIE10DigiCollection();
186  }
187  std::auto_ptr<QIE10DigiCollection> qie10_prod(colls.qie10);
188 
189  hbhe_prod->swap_contents(hbhe);
190  hf_prod->swap_contents(hf);
191  ho_prod->swap_contents(ho);
192  htp_prod->swap_contents(htp);
193  hotp_prod->swap_contents(hotp);
194 
195  // Step C2: filter FEDs, if required
196  if (filter_.active()) {
197  HBHEDigiCollection filtered_hbhe=filter_.filter(*hbhe_prod,*report);
198  HODigiCollection filtered_ho=filter_.filter(*ho_prod,*report);
199  HFDigiCollection filtered_hf=filter_.filter(*hf_prod,*report);
200 
201  hbhe_prod->swap(filtered_hbhe);
202  ho_prod->swap(filtered_ho);
203  hf_prod->swap(filtered_hf);
204  }
205 
206 
207  // Step D: Put outputs into event
208  // just until the sorting is proven
209  hbhe_prod->sort();
210  ho_prod->sort();
211  hf_prod->sort();
212  htp_prod->sort();
213  hotp_prod->sort();
214  qie10_prod->sort();
215 
216  e.put(hbhe_prod);
217  e.put(ho_prod);
218  e.put(hf_prod);
219  e.put(htp_prod);
220  e.put(hotp_prod);
221  e.put(qie10_prod);
222 
224  if (unpackCalib_) {
225  std::auto_ptr<HcalCalibDigiCollection> hc_prod(new HcalCalibDigiCollection());
226  hc_prod->swap_contents(hc);
227 
228  if (filter_.active()) {
229  HcalCalibDigiCollection filtered_calib=filter_.filter(*hc_prod,*report);
230  hc_prod->swap(filtered_calib);
231  }
232 
233  hc_prod->sort();
234  e.put(hc_prod);
235  }
236 
238  if (unpackZDC_) {
239  std::auto_ptr<ZDCDigiCollection> prod(new ZDCDigiCollection());
240  prod->swap_contents(zdc);
241 
242  if (filter_.active()) {
243  ZDCDigiCollection filtered_zdc=filter_.filter(*prod,*report);
244  prod->swap(filtered_zdc);
245  }
246 
247  prod->sort();
248  e.put(prod);
249  }
250 
251  if (unpackTTP_) {
252  std::auto_ptr<HcalTTPDigiCollection> prod(new HcalTTPDigiCollection());
253  prod->swap_contents(ttp);
254 
255  prod->sort();
256  e.put(prod);
257  }
258  e.put(report);
259 
260 
261 }
262 
263 
virtual char const * what() const
Definition: Exception.cc:141
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
HcalDataFrameFilter filter_
Definition: HcalRawToDigi.h:39
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
std::vector< HcalTTPDigi > * ttp
Definition: HcalUnpacker.h:32
edm::SortedCollection< HcalTriggerPrimitiveDigi > HcalTrigPrimDigiCollection
const bool unpackTTP_
Definition: HcalRawToDigi.h:42
std::vector< HFDataFrame > * hfCont
Definition: HcalUnpacker.h:27
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:449
void swap(SortedCollection &other)
std::vector< HBHEDataFrame > * hbheCont
Definition: HcalUnpacker.h:25
std::vector< HOTriggerPrimitiveDigi > * tphoCont
Definition: HcalUnpacker.h:31
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
edm::SortedCollection< HOTriggerPrimitiveDigi > HOTrigPrimDigiCollection
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
edm::SortedCollection< ZDCDataFrame > ZDCDigiCollection
virtual void produce(edm::Event &, const edm::EventSetup &) override
HcalDataFrameContainer< QIE10DataFrame > QIE10DigiCollection
tuple report
Definition: zeeHLT_cff.py:9
const int expectedOrbitMessageTime_
Definition: HcalRawToDigi.h:44
edm::SortedCollection< HODataFrame > HODigiCollection
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
virtual ~HcalRawToDigi()
const bool complainEmptyData_
Definition: HcalRawToDigi.h:43
std::string electronicsMapLabel_
Definition: HcalRawToDigi.h:45
std::vector< HcalTriggerPrimitiveDigi > * tpCont
Definition: HcalUnpacker.h:30
struct HcalRawToDigi::Statistics stats_
const bool unpackZDC_
Definition: HcalRawToDigi.h:42
ParameterDescriptionBase * add(U const &iLabel, T const &value)
const bool unpackCalib_
Definition: HcalRawToDigi.h:42
HcalRawToDigi(const edm::ParameterSet &ps)
const bool silent_
Definition: HcalRawToDigi.h:43
tuple conf
Definition: dbtoconf.py:185
void setExpectedOrbitMessageTime(int time)
Definition: HcalUnpacker.h:40
void setMode(int mode)
Definition: HcalUnpacker.h:43
void unpack(const FEDRawData &raw, const HcalElectronicsMap &emap, std::vector< HcalHistogramDigi > &histoDigis)
edm::SortedCollection< HcalCalibDataFrame > HcalCalibDigiCollection
std::vector< HcalCalibDataFrame > * calibCont
Definition: HcalUnpacker.h:28
std::vector< int > fedUnpackList_
Definition: HcalRawToDigi.h:40
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:86
bool active() const
whether any filters are on
std::vector< HODataFrame > * hoCont
Definition: HcalUnpacker.h:26
void add(std::string const &label, ParameterSetDescription const &psetDescription)
HBHEDigiCollection filter(const HBHEDigiCollection &incol, HcalUnpackerReport &r)
filter HB/HE data frames
const int unpackerMode_
Definition: HcalRawToDigi.h:44
HcalUnpacker unpacker_
Definition: HcalRawToDigi.h:38
edm::SortedCollection< HcalTTPDigi > HcalTTPDigiCollection
susybsm::HSCParticleCollection hc
Definition: classes.h:25
edm::SortedCollection< HFDataFrame > HFDigiCollection
QIE10DigiCollection * qie10
Definition: HcalUnpacker.h:33
std::vector< ZDCDataFrame > * zdcCont
Definition: HcalUnpacker.h:29
edm::EDGetTokenT< FEDRawDataCollection > tok_data_
Definition: HcalRawToDigi.h:37
volatile std::atomic< bool > shutdown_flag false
edm::SortedCollection< HBHEDataFrame > HBHEDigiCollection