CMS 3D CMS Logo

HcalRawToDigi.cc
Go to the documentation of this file.
11 #include <iostream>
12 #include <unordered_set>
13 
15  unpacker_(conf.getUntrackedParameter<int>("HcalFirstFED",int(FEDNumbering::MINHCALFEDID)),conf.getParameter<int>("firstSample"),conf.getParameter<int>("lastSample")),
16  filter_(conf.getParameter<bool>("FilterDataQuality"),conf.getParameter<bool>("FilterDataQuality"),
17  false,
18  0, 0,
19  -1),
20  fedUnpackList_(conf.getUntrackedParameter<std::vector<int> >("FEDs", std::vector<int>())),
21  firstFED_(conf.getUntrackedParameter<int>("HcalFirstFED",FEDNumbering::MINHCALFEDID)),
22  unpackCalib_(conf.getUntrackedParameter<bool>("UnpackCalib",false)),
23  unpackZDC_(conf.getUntrackedParameter<bool>("UnpackZDC",false)),
24  unpackTTP_(conf.getUntrackedParameter<bool>("UnpackTTP",false)),
25  unpackUMNio_(conf.getUntrackedParameter<bool>("UnpackUMNio",false)),
26  silent_(conf.getUntrackedParameter<bool>("silent",true)),
27  complainEmptyData_(conf.getUntrackedParameter<bool>("ComplainEmptyData",false)),
28  unpackerMode_(conf.getUntrackedParameter<int>("UnpackerMode",0)),
29  expectedOrbitMessageTime_(conf.getUntrackedParameter<int>("ExpectedOrbitMessageTime",-1))
30 {
31  electronicsMapLabel_ = conf.getParameter<std::string>("ElectronicsMap");
32  tok_data_ = consumes<FEDRawDataCollection>(conf.getParameter<edm::InputTag>("InputLabel"));
33 
34  if (fedUnpackList_.empty()) {
35  // VME range for back-compatibility
37  fedUnpackList_.push_back(i);
38 
39  // uTCA range
41  fedUnpackList_.push_back(i);
42  }
43 
46  std::ostringstream ss;
47  for (unsigned int i=0; i<fedUnpackList_.size(); i++)
48  ss << fedUnpackList_[i] << " ";
49  edm::LogInfo("HCAL") << "HcalRawToDigi will unpack FEDs ( " << ss.str() << ")";
50 
51  // products produced...
52  produces<HBHEDigiCollection>();
53  produces<HFDigiCollection>();
54  produces<HODigiCollection>();
55  produces<HcalTrigPrimDigiCollection>();
56  produces<HOTrigPrimDigiCollection>();
57  produces<HcalUnpackerReport>();
58  if (unpackCalib_)
59  produces<HcalCalibDigiCollection>();
60  if (unpackZDC_)
61  produces<ZDCDigiCollection>();
62  if (unpackTTP_)
63  produces<HcalTTPDigiCollection>();
64  if (unpackUMNio_)
65  produces<HcalUMNioDigi>();
66  produces<QIE10DigiCollection>();
67  produces<QIE11DigiCollection>();
68  produces<QIE10DigiCollection>("ZDC");
69 
70  memset(&stats_,0,sizeof(stats_));
71 
72 }
73 
74 // Virtual destructor needed.
76 
79  desc.addUntracked<int>("HcalFirstFED",int(FEDNumbering::MINHCALFEDID));
80  desc.add<int>("firstSample",0);
81  desc.add<int>("lastSample",9);
82  desc.add<bool>("FilterDataQuality",true);
83  desc.addUntracked<std::vector<int>>("FEDs", std::vector<int>());
84  desc.addUntracked<bool>("UnpackZDC",true);
85  desc.addUntracked<bool>("UnpackCalib",true);
86  desc.addUntracked<bool>("UnpackUMNio",true);
87  desc.addUntracked<bool>("UnpackTTP",true);
88  desc.addUntracked<bool>("silent",true);
89  desc.addUntracked<bool>("ComplainEmptyData",false);
90  desc.addUntracked<int>("UnpackerMode",0);
91  desc.addUntracked<int>("ExpectedOrbitMessageTime",-1);
92  desc.add<edm::InputTag>("InputLabel",edm::InputTag("rawDataCollector"));
93  desc.add<std::string>("ElectronicsMap","");
94  descriptions.add("hcalRawToDigi",desc);
95 }
96 
97 
98 // Functions that gets called by framework every event
100 {
101  // Step A: Get Inputs
103  e.getByToken(tok_data_,rawraw);
104  // get the mapping
106  es.get<HcalDbRecord>().get( pSetup );
109  const HcalElectronicsMap* readoutMap = item.product();
110 
111  // Step B: Create empty output : three vectors for three classes...
112  std::vector<HBHEDataFrame> hbhe;
113  std::vector<HODataFrame> ho;
114  std::vector<HFDataFrame> hf;
115  std::vector<HcalTriggerPrimitiveDigi> htp;
116  std::vector<HcalCalibDataFrame> hc;
117  std::vector<ZDCDataFrame> zdc;
118  std::vector<HcalTTPDigi> ttp;
119  std::vector<HOTriggerPrimitiveDigi> hotp;
120  HcalUMNioDigi umnio;
121  auto report = std::make_unique<HcalUnpackerReport>();
122 
123  // Heuristics: use ave+(max-ave)/8
124  if (stats_.max_hbhe>0) hbhe.reserve(stats_.ave_hbhe+(stats_.max_hbhe-stats_.ave_hbhe)/8);
125  if (stats_.max_ho>0) ho.reserve(stats_.ave_ho+(stats_.max_ho-stats_.ave_ho)/8);
126  if (stats_.max_hf>0) hf.reserve(stats_.ave_hf+(stats_.max_hf-stats_.ave_hf)/8);
128  if (stats_.max_tp>0) htp.reserve(stats_.ave_tp+(stats_.max_tp-stats_.ave_tp)/8);
129  if (stats_.max_tpho>0) hotp.reserve(stats_.ave_tpho+(stats_.max_tpho-stats_.ave_tpho)/8);
130 
131  if (unpackZDC_) zdc.reserve(24);
132 
133 
135  colls.hbheCont=&hbhe;
136  colls.hoCont=&ho;
137  colls.hfCont=&hf;
138  colls.tpCont=&htp;
139  colls.tphoCont=&hotp;
140  colls.calibCont=&hc;
141  colls.zdcCont=&zdc;
142  colls.umnio=&umnio;
143  if (unpackTTP_) colls.ttp=&ttp;
144 
145  // Step C: unpack all requested FEDs
146  for (std::vector<int>::const_iterator i=fedUnpackList_.begin(); i!=fedUnpackList_.end(); i++) {
147  const FEDRawData& fed = rawraw->FEDData(*i);
148  if (fed.size()==0) {
149  if (complainEmptyData_) {
150  if (!silent_) edm::LogWarning("EmptyData") << "No data for FED " << *i;
151  report->addError(*i);
152  }
153  } else if (fed.size()<8*3) {
154  if (!silent_) edm::LogWarning("EmptyData") << "Tiny data " << fed.size() << " for FED " << *i;
155  report->addError(*i);
156  } else {
157  try {
158  unpacker_.unpack(fed,*readoutMap,colls, *report,silent_);
159  report->addUnpacked(*i);
160  } catch (cms::Exception& e) {
161  if (!silent_) edm::LogWarning("Unpacking error") << e.what();
162  report->addError(*i);
163  } catch (...) {
164  if (!silent_) edm::LogWarning("Unpacking exception");
165  report->addError(*i);
166  }
167  }
168  }
169 
170 
171  // gather statistics
172  stats_.max_hbhe=std::max(stats_.max_hbhe,(int)hbhe.size());
173  stats_.ave_hbhe=(stats_.ave_hbhe*stats_.n+hbhe.size())/(stats_.n+1);
174  stats_.max_ho=std::max(stats_.max_ho,(int)ho.size());
175  stats_.ave_ho=(stats_.ave_ho*stats_.n+ho.size())/(stats_.n+1);
176  stats_.max_hf=std::max(stats_.max_hf,(int)hf.size());
177  stats_.ave_hf=(stats_.ave_hf*stats_.n+hf.size())/(stats_.n+1);
178  stats_.max_tp=std::max(stats_.max_tp,(int)htp.size());
179  stats_.ave_tp=(stats_.ave_tp*stats_.n+htp.size())/(stats_.n+1);
180  stats_.max_tpho=std::max(stats_.max_tpho,(int)hotp.size());
181  stats_.ave_tpho=(stats_.ave_tpho*stats_.n+hotp.size())/(stats_.n+1);
182  stats_.max_calib=std::max(stats_.max_calib,(int)hc.size());
183  stats_.ave_calib=(stats_.ave_calib*stats_.n+hc.size())/(stats_.n+1);
184 
185 
186  stats_.n++;
187 
188  // check HF duplication
189  std::unordered_set<uint32_t> cacheForHFdup;
190  unsigned int cntHFdup = 0;
191  for( auto & hf_digi : hf ){
192  if( ! cacheForHFdup.insert(hf_digi.id().rawId()).second ) cntHFdup++;
193  }
194  if( cntHFdup ) edm::LogError("HcalRawToDigi") << "Duplicated HF digis found for "<<cntHFdup<<" times"<<std::endl;
195 
196  // Step B: encapsulate vectors in actual collections
197  auto hbhe_prod = std::make_unique<HBHEDigiCollection>();
198  auto hf_prod = std::make_unique<HFDigiCollection>();
199  auto ho_prod = std::make_unique<HODigiCollection>();
200  auto htp_prod = std::make_unique<HcalTrigPrimDigiCollection>();
201  auto hotp_prod = std::make_unique<HOTrigPrimDigiCollection>();
202  if (colls.qie10 == 0) {
203  colls.qie10 = new QIE10DigiCollection();
204  }
205  std::unique_ptr<QIE10DigiCollection> qie10_prod(colls.qie10);
206  if (colls.qie10ZDC == 0) {
207  colls.qie10ZDC = new QIE10DigiCollection();
208  }
209  std::unique_ptr<QIE10DigiCollection> qie10ZDC_prod(colls.qie10ZDC);
210  if (colls.qie11 == 0) {
211  colls.qie11 = new QIE11DigiCollection();
212  }
213  std::unique_ptr<QIE11DigiCollection> qie11_prod(colls.qie11);
214 
215  hbhe_prod->swap_contents(hbhe);
216  if( !cntHFdup ) hf_prod->swap_contents(hf);
217  ho_prod->swap_contents(ho);
218  htp_prod->swap_contents(htp);
219  hotp_prod->swap_contents(hotp);
220 
221  // Step C2: filter FEDs, if required
222  if (filter_.active()) {
223  HBHEDigiCollection filtered_hbhe=filter_.filter(*hbhe_prod,*report);
224  HODigiCollection filtered_ho=filter_.filter(*ho_prod,*report);
225  HFDigiCollection filtered_hf=filter_.filter(*hf_prod,*report);
226 
227  hbhe_prod->swap(filtered_hbhe);
228  ho_prod->swap(filtered_ho);
229  hf_prod->swap(filtered_hf);
230  }
231 
232 
233  // Step D: Put outputs into event
234  // just until the sorting is proven
235  hbhe_prod->sort();
236  ho_prod->sort();
237  hf_prod->sort();
238  htp_prod->sort();
239  hotp_prod->sort();
240  qie10_prod->sort();
241  qie10ZDC_prod->sort();
242  qie11_prod->sort();
243 
244  e.put(std::move(hbhe_prod));
245  e.put(std::move(ho_prod));
246  e.put(std::move(hf_prod));
247  e.put(std::move(htp_prod));
248  e.put(std::move(hotp_prod));
249  e.put(std::move(qie10_prod));
250  e.put(std::move(qie10ZDC_prod),"ZDC");
251  e.put(std::move(qie11_prod));
252 
254  if (unpackCalib_) {
255  auto hc_prod = std::make_unique<HcalCalibDigiCollection>();
256  hc_prod->swap_contents(hc);
257 
258  if (filter_.active()) {
259  HcalCalibDigiCollection filtered_calib=filter_.filter(*hc_prod,*report);
260  hc_prod->swap(filtered_calib);
261  }
262 
263  hc_prod->sort();
264  e.put(std::move(hc_prod));
265  }
266 
268  if (unpackZDC_) {
269  auto prod = std::make_unique<ZDCDigiCollection>();
270  prod->swap_contents(zdc);
271 
272  if (filter_.active()) {
273  ZDCDigiCollection filtered_zdc=filter_.filter(*prod,*report);
274  prod->swap(filtered_zdc);
275  }
276 
277  prod->sort();
278  e.put(std::move(prod));
279  }
280 
281  if (unpackTTP_) {
282  auto prod = std::make_unique<HcalTTPDigiCollection>();
283  prod->swap_contents(ttp);
284 
285  prod->sort();
286  e.put(std::move(prod));
287  }
288  e.put(std::move(report));
290  if (unpackUMNio_) {
291  if(colls.umnio != 0) {
292  e.put(std::make_unique<HcalUMNioDigi>(umnio));
293  }
294 
295  }
296 }
297 
298 
virtual char const * what() const
Definition: Exception.cc:141
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
HcalDataFrameFilter filter_
Definition: HcalRawToDigi.h:39
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
std::vector< HcalTTPDigi > * ttp
Definition: HcalUnpacker.h:33
const bool unpackTTP_
Definition: HcalRawToDigi.h:42
std::vector< HFDataFrame > * hfCont
Definition: HcalUnpacker.h:28
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
HcalUMNioDigi * umnio
Definition: HcalUnpacker.h:37
void swap(SortedCollection &other)
std::vector< HBHEDataFrame > * hbheCont
Definition: HcalUnpacker.h:26
std::vector< HOTriggerPrimitiveDigi > * tphoCont
Definition: HcalUnpacker.h:32
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
virtual void produce(edm::Event &, const edm::EventSetup &) override
HcalDataFrameContainer< QIE10DataFrame > QIE10DigiCollection
U second(std::pair< T, U > const &p)
const int expectedOrbitMessageTime_
Definition: HcalRawToDigi.h:45
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
QIE10DigiCollection * qie10ZDC
Definition: HcalUnpacker.h:35
virtual ~HcalRawToDigi()
const bool complainEmptyData_
Definition: HcalRawToDigi.h:44
std::string electronicsMapLabel_
Definition: HcalRawToDigi.h:46
std::vector< HcalTriggerPrimitiveDigi > * tpCont
Definition: HcalUnpacker.h:31
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:44
void setExpectedOrbitMessageTime(int time)
Definition: HcalUnpacker.h:45
HcalDataFrameContainer< QIE11DataFrame > QIE11DigiCollection
void setMode(int mode)
Definition: HcalUnpacker.h:48
void unpack(const FEDRawData &raw, const HcalElectronicsMap &emap, std::vector< HcalHistogramDigi > &histoDigis)
std::vector< HcalCalibDataFrame > * calibCont
Definition: HcalUnpacker.h:29
std::vector< int > fedUnpackList_
Definition: HcalRawToDigi.h:40
const T & get() const
Definition: EventSetup.h:56
bool active() const
whether any filters are on
std::vector< HODataFrame > * hoCont
Definition: HcalUnpacker.h:27
QIE11DigiCollection * qie11
Definition: HcalUnpacker.h:36
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:45
HcalUnpacker unpacker_
Definition: HcalRawToDigi.h:38
susybsm::HSCParticleCollection hc
Definition: classes.h:25
QIE10DigiCollection * qie10
Definition: HcalUnpacker.h:34
std::vector< ZDCDataFrame > * zdcCont
Definition: HcalUnpacker.h:30
edm::EDGetTokenT< FEDRawDataCollection > tok_data_
Definition: HcalRawToDigi.h:37
T const * product() const
Definition: ESHandle.h:86
def move(src, dest)
Definition: eostools.py:510