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 #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  silent_(conf.getUntrackedParameter<bool>("silent",true)),
26  complainEmptyData_(conf.getUntrackedParameter<bool>("ComplainEmptyData",false)),
27  unpackerMode_(conf.getUntrackedParameter<int>("UnpackerMode",0)),
28  expectedOrbitMessageTime_(conf.getUntrackedParameter<int>("ExpectedOrbitMessageTime",-1))
29 {
30  electronicsMapLabel_ = conf.getParameter<std::string>("ElectronicsMap");
31  tok_data_ = consumes<FEDRawDataCollection>(conf.getParameter<edm::InputTag>("InputLabel"));
32 
33  if (fedUnpackList_.empty()) {
35  fedUnpackList_.push_back(i);
36  // HF uTCA
37  fedUnpackList_.push_back(1118);
38  fedUnpackList_.push_back(1120);
39  fedUnpackList_.push_back(1122);
40  }
41 
44  std::ostringstream ss;
45  for (unsigned int i=0; i<fedUnpackList_.size(); i++)
46  ss << fedUnpackList_[i] << " ";
47  edm::LogInfo("HCAL") << "HcalRawToDigi will unpack FEDs ( " << ss.str() << ")";
48 
49  // products produced...
50  produces<HBHEDigiCollection>();
51  produces<HFDigiCollection>();
52  produces<HODigiCollection>();
53  produces<HcalTrigPrimDigiCollection>();
54  produces<HOTrigPrimDigiCollection>();
55  produces<HcalUnpackerReport>();
56  if (unpackCalib_)
57  produces<HcalCalibDigiCollection>();
58  if (unpackZDC_)
59  produces<ZDCDigiCollection>();
60  if (unpackTTP_)
61  produces<HcalTTPDigiCollection>();
62  produces<QIE10DigiCollection>();
63 
64  memset(&stats_,0,sizeof(stats_));
65 
66 }
67 
68 // Virtual destructor needed.
70 
73  desc.addUntracked<int>("HcalFirstFED",int(FEDNumbering::MINHCALFEDID));
74  desc.add<int>("firstSample",0);
75  desc.add<int>("lastSample",9);
76  desc.add<bool>("FilterDataQuality",true);
77  desc.addUntracked<std::vector<int>>("FEDs", std::vector<int>());
78  desc.addUntracked<bool>("UnpackZDC",true);
79  desc.addUntracked<bool>("UnpackCalib",true);
80  desc.addUntracked<bool>("UnpackTTP",true);
81  desc.addUntracked<bool>("silent",true);
82  desc.addUntracked<bool>("ComplainEmptyData",false);
83  desc.addUntracked<int>("UnpackerMode",0);
84  desc.addUntracked<int>("ExpectedOrbitMessageTime",-1);
85  desc.add<edm::InputTag>("InputLabel",edm::InputTag("rawDataCollector"));
86  desc.add<std::string>("ElectronicsMap","");
87  descriptions.add("hcalRawToDigi",desc);
88 }
89 
90 
91 // Functions that gets called by framework every event
93 {
94  // Step A: Get Inputs
96  e.getByToken(tok_data_,rawraw);
97  // get the mapping
99  es.get<HcalDbRecord>().get( pSetup );
102  const HcalElectronicsMap* readoutMap = item.product();
103 
104  // Step B: Create empty output : three vectors for three classes...
105  std::vector<HBHEDataFrame> hbhe;
106  std::vector<HODataFrame> ho;
107  std::vector<HFDataFrame> hf;
108  std::vector<HcalTriggerPrimitiveDigi> htp;
109  std::vector<HcalCalibDataFrame> hc;
110  std::vector<ZDCDataFrame> zdc;
111  std::vector<HcalTTPDigi> ttp;
112  std::vector<HOTriggerPrimitiveDigi> hotp;
113  std::auto_ptr<HcalUnpackerReport> report(new HcalUnpackerReport);
114 
115  // Heuristics: use ave+(max-ave)/8
116  if (stats_.max_hbhe>0) hbhe.reserve(stats_.ave_hbhe+(stats_.max_hbhe-stats_.ave_hbhe)/8);
117  if (stats_.max_ho>0) ho.reserve(stats_.ave_ho+(stats_.max_ho-stats_.ave_ho)/8);
118  if (stats_.max_hf>0) hf.reserve(stats_.ave_hf+(stats_.max_hf-stats_.ave_hf)/8);
120  if (stats_.max_tp>0) htp.reserve(stats_.ave_tp+(stats_.max_tp-stats_.ave_tp)/8);
121  if (stats_.max_tpho>0) hotp.reserve(stats_.ave_tpho+(stats_.max_tpho-stats_.ave_tpho)/8);
122 
123  if (unpackZDC_) zdc.reserve(24);
124 
125 
127  colls.hbheCont=&hbhe;
128  colls.hoCont=&ho;
129  colls.hfCont=&hf;
130  colls.tpCont=&htp;
131  colls.tphoCont=&hotp;
132  colls.calibCont=&hc;
133  colls.zdcCont=&zdc;
134  if (unpackTTP_) colls.ttp=&ttp;
135 
136  // Step C: unpack all requested FEDs
137  for (std::vector<int>::const_iterator i=fedUnpackList_.begin(); i!=fedUnpackList_.end(); i++) {
138  const FEDRawData& fed = rawraw->FEDData(*i);
139  if (fed.size()==0) {
140  if (complainEmptyData_) {
141  if (!silent_) edm::LogWarning("EmptyData") << "No data for FED " << *i;
142  report->addError(*i);
143  }
144  } else if (fed.size()<8*3) {
145  if (!silent_) edm::LogWarning("EmptyData") << "Tiny data " << fed.size() << " for FED " << *i;
146  report->addError(*i);
147  } else {
148  try {
149  unpacker_.unpack(fed,*readoutMap,colls, *report,silent_);
150  report->addUnpacked(*i);
151  } catch (cms::Exception& e) {
152  if (!silent_) edm::LogWarning("Unpacking error") << e.what();
153  report->addError(*i);
154  } catch (...) {
155  if (!silent_) edm::LogWarning("Unpacking exception");
156  report->addError(*i);
157  }
158  }
159  }
160 
161 
162  // gather statistics
163  stats_.max_hbhe=std::max(stats_.max_hbhe,(int)hbhe.size());
164  stats_.ave_hbhe=(stats_.ave_hbhe*stats_.n+hbhe.size())/(stats_.n+1);
165  stats_.max_ho=std::max(stats_.max_ho,(int)ho.size());
166  stats_.ave_ho=(stats_.ave_ho*stats_.n+ho.size())/(stats_.n+1);
167  stats_.max_hf=std::max(stats_.max_hf,(int)hf.size());
168  stats_.ave_hf=(stats_.ave_hf*stats_.n+hf.size())/(stats_.n+1);
169  stats_.max_tp=std::max(stats_.max_tp,(int)htp.size());
170  stats_.ave_tp=(stats_.ave_tp*stats_.n+htp.size())/(stats_.n+1);
171  stats_.max_tpho=std::max(stats_.max_tpho,(int)hotp.size());
172  stats_.ave_tpho=(stats_.ave_tpho*stats_.n+hotp.size())/(stats_.n+1);
173  stats_.max_calib=std::max(stats_.max_calib,(int)hc.size());
174  stats_.ave_calib=(stats_.ave_calib*stats_.n+hc.size())/(stats_.n+1);
175 
176 
177  stats_.n++;
178 
179  // check HF duplication
180  std::unordered_set<uint32_t> cacheForHFdup;
181  unsigned int cntHFdup = 0;
182  for( auto & hf_digi : hf ){
183  if( ! cacheForHFdup.insert(hf_digi.id().rawId()).second ) cntHFdup++;
184  }
185  if( cntHFdup ) edm::LogError("HcalRawToDigi") << "Duplicated HF digis found for "<<cntHFdup<<" times"<<std::endl;
186 
187  // Step B: encapsulate vectors in actual collections
188  std::auto_ptr<HBHEDigiCollection> hbhe_prod(new HBHEDigiCollection());
189  std::auto_ptr<HFDigiCollection> hf_prod(new HFDigiCollection());
190  std::auto_ptr<HODigiCollection> ho_prod(new HODigiCollection());
191  std::auto_ptr<HcalTrigPrimDigiCollection> htp_prod(new HcalTrigPrimDigiCollection());
192  std::auto_ptr<HOTrigPrimDigiCollection> hotp_prod(new HOTrigPrimDigiCollection());
193  if (colls.qie10 == 0) {
194  colls.qie10 = new QIE10DigiCollection();
195  }
196  std::auto_ptr<QIE10DigiCollection> qie10_prod(colls.qie10);
197 
198  hbhe_prod->swap_contents(hbhe);
199  if( !cntHFdup ) hf_prod->swap_contents(hf);
200  ho_prod->swap_contents(ho);
201  htp_prod->swap_contents(htp);
202  hotp_prod->swap_contents(hotp);
203 
204  // Step C2: filter FEDs, if required
205  if (filter_.active()) {
206  HBHEDigiCollection filtered_hbhe=filter_.filter(*hbhe_prod,*report);
207  HODigiCollection filtered_ho=filter_.filter(*ho_prod,*report);
208  HFDigiCollection filtered_hf=filter_.filter(*hf_prod,*report);
209 
210  hbhe_prod->swap(filtered_hbhe);
211  ho_prod->swap(filtered_ho);
212  hf_prod->swap(filtered_hf);
213  }
214 
215 
216  // Step D: Put outputs into event
217  // just until the sorting is proven
218  hbhe_prod->sort();
219  ho_prod->sort();
220  hf_prod->sort();
221  htp_prod->sort();
222  hotp_prod->sort();
223  qie10_prod->sort();
224 
225  e.put(hbhe_prod);
226  e.put(ho_prod);
227  e.put(hf_prod);
228  e.put(htp_prod);
229  e.put(hotp_prod);
230  e.put(qie10_prod);
231 
233  if (unpackCalib_) {
234  std::auto_ptr<HcalCalibDigiCollection> hc_prod(new HcalCalibDigiCollection());
235  hc_prod->swap_contents(hc);
236 
237  if (filter_.active()) {
238  HcalCalibDigiCollection filtered_calib=filter_.filter(*hc_prod,*report);
239  hc_prod->swap(filtered_calib);
240  }
241 
242  hc_prod->sort();
243  e.put(hc_prod);
244  }
245 
247  if (unpackZDC_) {
248  std::auto_ptr<ZDCDigiCollection> prod(new ZDCDigiCollection());
249  prod->swap_contents(zdc);
250 
251  if (filter_.active()) {
252  ZDCDigiCollection filtered_zdc=filter_.filter(*prod,*report);
253  prod->swap(filtered_zdc);
254  }
255 
256  prod->sort();
257  e.put(prod);
258  }
259 
260  if (unpackTTP_) {
261  std::auto_ptr<HcalTTPDigiCollection> prod(new HcalTTPDigiCollection());
262  prod->swap_contents(ttp);
263 
264  prod->sort();
265  e.put(prod);
266  }
267  e.put(report);
268 
269 
270 }
271 
272 
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:457
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
U second(std::pair< T, U > const &p)
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:115
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