CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalDataIntegrityTask.cc
Go to the documentation of this file.
6 #include <iostream>
7 
9 {
10 
11  Online_ = ps.getUntrackedParameter<bool>("online",false);
12  mergeRuns_ = ps.getUntrackedParameter<bool>("mergeRuns",false);
13  enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup",false);
14  debug_ = ps.getUntrackedParameter<int>("debug",0);
15  prefixME_ = ps.getUntrackedParameter<std::string>("subSystemFolder","Hcal");
16  if (prefixME_.substr(prefixME_.size()-1,prefixME_.size())!="/")
17  prefixME_.append("/");
18  subdir_ = ps.getUntrackedParameter<std::string>("TaskFolder","HcalDataIntegrityTask");
19  if (subdir_.size()>0 && subdir_.substr(subdir_.size()-1,subdir_.size())!="/")
20  subdir_.append("/");
21  subdir_=prefixME_+subdir_;
22  AllowedCalibTypes_ = ps.getUntrackedParameter<std::vector<int> > ("AllowedCalibTypes");
23  skipOutOfOrderLS_ = ps.getUntrackedParameter<bool>("skipOutOfOrderLS",false);
24  NLumiBlocks_ = ps.getUntrackedParameter<int>("NLumiBlocks",4000);
25  makeDiagnostics_ = ps.getUntrackedParameter<bool>("makeDiagnostics",false);
26 
27  // Specific Data Integrity Task parameters
29  inputLabelReport_ = ps.getUntrackedParameter<edm::InputTag>("UnpackerReportLabel",edm::InputTag("hcalDigis"));
30 
31 
32  // register for data access
33  tok_raw_ = consumes<FEDRawDataCollection>(inputLabelRawData_);
34  tok_report_ = consumes<HcalUnpackerReport>(inputLabelReport_);
35 
36 } // HcalDataIntegrityTask::HcalDataIntegrityTask()
37 
39 
41 {
42  if (debug_>0) std::cout <<"HcalDataIntegrityTask::reset()"<<std::endl;
44  fedEntries_->Reset();
45  fedFatal_->Reset();
47 
48 }
49 
51 {
52  if(dbe_)
53  {
56  }
57 
58 } // void HcalDataIntegrityTask::cleanup()
59 
60 
62 {
63 
64  if (debug_>0) std::cout <<"HcalDataIntegrityTask::beginRun(): task = '"<<subdir_<<"'"<<std::endl;
65 
67  if (mergeRuns_ && tevt_>0) return;
68 
69  if (debug_>1) std::cout<<"\t<HcalDataIntegrityTask::getting eMap..."<<std::endl;
71  c.get<HcalDbRecord>().get( pSetup );
72  readoutMap_=pSetup->getHcalMapping();
73 
74  if (tevt_==0) // create histograms, if they haven't been created already
75  this->setup();
76  // Clear histograms at the start of each run if not merging runs
77  if (mergeRuns_==false)
78  this->reset();
79 
80 } // beginRun(const edm::Run& run, const edm::EventSetup& c)
81 
82 
84 {
85  // Setup Creates all necessary histograms
87 
88  //Initialize phatmap to a vector of vectors of uint64_t 0
89  static size_t iphirange = IPHIMAX - IPHIMIN;
90  static size_t ietarange = IETAMAX - IETAMIN;
91 
92  std::vector<uint64_t> phatv (iphirange + 1, 0);
93 
94  if (debug_>0) std::cout <<"<HcalDataIntegrityTask::setup> Clearing old vectors"<<std::endl;
95  // Clear any old vectors
96  phatmap.clear();
97  HBmap.clear();
98  HEmap.clear();
99  HFmap.clear();
100  HOmap.clear();
101  problemhere.clear();
102  problemHB.clear();
103  problemHE.clear();
104  problemHF.clear();
105  problemHO.clear();
106 
107  // ... nothing goes at ieta=0, so an extra bin goes there.
108  phatmap = std::vector< std::vector < uint64_t> > ( ietarange + 1, phatv);
109  HBmap = std::vector< std::vector < uint64_t> > ( ietarange + 1, phatv);
110  HEmap = std::vector< std::vector < uint64_t> > ( ietarange + 1, phatv);
111  HFmap = std::vector< std::vector < uint64_t> > ( ietarange + 1, phatv);
112  HOmap = std::vector< std::vector < uint64_t> > ( ietarange + 1, phatv);
113  std::vector<bool> probvect (iphirange + 1, 0);
114  // ... nothing goes at ieta=0, so an extra bin goes there.
115  problemhere = std::vector< std::vector <bool> > ( ietarange + 1, probvect);
116  problemHB = std::vector< std::vector <bool> > ( ietarange + 1, probvect);
117  problemHE = std::vector< std::vector <bool> > ( ietarange + 1, probvect);
118  problemHF = std::vector< std::vector <bool> > ( ietarange + 1, probvect);
119  problemHO = std::vector< std::vector <bool> > ( ietarange + 1, probvect);
120 
121 
122 
123  if(debug_>1)
124  std::cout << "About to pushback fedUnpackList_" << std::endl;
125 
126  // Use this in CMSSW_3_0_X and above:
128  for (int i=FEDNumbering::MINHCALFEDID;
130  ++i)
131  {
132  if(debug_>1) std::cout << "[DFMon:]Pushback for fedUnpackList_: " << i <<std::endl;
133  fedUnpackList_.push_back(i);
134  }
135 
136  if ( dbe_ )
137  {
138 
139  if (debug_>1)
140  std::cout <<"\t<HcalDataIntegrityTask> Setting folder to "<<subdir_<<std::endl;
141 
143 
144  fedEntries_ = dbe_->book1D("FEDEntries","# entries per HCAL FED",32,700,732);
145  fedFatal_ = dbe_->book1D("FEDFatal","# fatal errors HCAL FED",32,700,732);
146  fedNonFatal_ = dbe_->book1D("FEDNonFatal","# non-fatal errors HCAL FED",32,700,732);
147  } // if (dbe_)
148 
149  this->reset(); // clear all histograms at start
150  return;
151 }
152 
154 {
155  if (!IsAllowedCalibType()) return;
156  if (LumiInOrder(e.luminosityBlock())==false) return;
157 
158  // Now get the collections we need
159 
161 
162  if (!(e.getByToken(tok_raw_,rawraw)))
163  {
164  if (debug_>0) edm::LogWarning("HcalDataIntegrityTask")<<" raw data with label "<<inputLabelRawData_<<" not available";
165  return;
166  }
167 
169  if (!(e.getByToken(tok_report_,report)))
170  {
171  if (debug_>0) edm::LogWarning("HcalDataIntegrityTask")<<" UnpackerReport with label "<<inputLabelReport_<<" \not available";
172  return;
173  }
174 
175  // Collections were found; increment counters
177 
178  processEvent(*rawraw, *report, *readoutMap_);
179 }
180 
181 
182 
184  const HcalUnpackerReport& report,
185  const HcalElectronicsMap& emap){
186 
187  if(!dbe_)
188  {
189  std::cout<<"HcalDataIntegrityTask::processEvent DQMStore not instantiated!!!"<<std::endl;
190  return;
191  }
192 
193  // Loop over all FEDs reporting the event, unpacking if good.
194  for (std::vector<int>::const_iterator i=fedUnpackList_.begin();i!=fedUnpackList_.end(); i++)
195  {
196  const FEDRawData& fed = rawraw.FEDData(*i);
197  if (fed.size()<12) continue; // Was 16. How do such tiny events even get here?
198  unpack(fed,emap);
199  }
200 
201  return;
202 } //void HcalDataIntegrityTask::processEvent()
203 
204 
205 // Process one FED's worth (one DCC's worth) of the event data.
207  const HcalElectronicsMap& emap){
208  // get the DCC header
209  const HcalDCCHeader* dccHeader=(const HcalDCCHeader*)(raw.data());
210  if(!dccHeader) return;
211 
212  // get the DCC trailer
213  unsigned char* trailer_ptr = (unsigned char*) (raw.data()+raw.size()-sizeof(uint64_t));
214  FEDTrailer trailer = FEDTrailer(trailer_ptr);
215 
216  int dccid=dccHeader->getSourceId();
217 
219  bool CDFProbThisDCC = false;
220  /* 1 */ //There should always be a second CDF header word indicated.
221  if (!dccHeader->thereIsASecondCDFHeaderWord())
222  {
223  CDFProbThisDCC = true;
224  }
225 
226  /* 2 */ //Make sure a reference CDF Version value has been recorded for this dccid
227  CDFvers_it = CDFversionNumber_list.find(dccid);
228  if (CDFvers_it == CDFversionNumber_list.end())
229  {
230  CDFversionNumber_list.insert(std::pair<int,short>
231  (dccid,dccHeader->getCDFversionNumber() ) );
232  CDFvers_it = CDFversionNumber_list.find(dccid);
233  } // then check against it.
234 
235  if (dccHeader->getCDFversionNumber()!= CDFvers_it->second)
236  {
237  CDFProbThisDCC = true;
238  }
239 
240  /* 3 */ //Make sure a reference CDF EventType value has been recorded for this dccid
241  CDFEvT_it = CDFEventType_list.find(dccid);
242  if (CDFEvT_it == CDFEventType_list.end())
243  {
244  CDFEventType_list.insert(std::pair<int,short>
245  (dccid,dccHeader->getCDFEventType() ) );
246  CDFEvT_it = CDFEventType_list.find(dccid);
247  } // then check against it.
248 
249  if (dccHeader->getCDFEventType()!= CDFEvT_it->second)
250  {
251  // On probation until safe against Orbit Gap Calibration Triggers...
252  // CDFProbThisDCC = true;
253  }
254 
255  /* 4 */ //There should always be a '5' in CDF Header word 0, bits [63:60]
256  if (dccHeader->BOEshouldBe5Always()!=5)
257  {
258  CDFProbThisDCC = true;
259  }
260 
261  /* 5 */ //There should never be a third CDF Header word indicated.
262  if (dccHeader->thereIsAThirdCDFHeaderWord())
263  {
264  CDFProbThisDCC = true;
265  }
266 
267  /* 6 */ //Make sure a reference value of Reserved Bits has been recorded for this dccid
268 
271  CDFReservedBits_list.insert(std::pair<int,short>
272  (dccid,dccHeader->getSlink64ReservedBits() ) );
274  } // then check against it.
275 
276  if ((int) dccHeader->getSlink64ReservedBits()!= CDFReservedBits_it->second)
277  {
278  // On probation until safe against Orbit Gap Calibration Triggers...
279  // CDFProbThisDCC = true;
280  }
281 
282  /* 7 */ //There should always be 0x0 in CDF Header word 1, bits [63:60]
283  if (dccHeader->BOEshouldBeZeroAlways() !=0)
284  {
285  CDFProbThisDCC = true;
286  }
287 
288  /* 8 */ //There should only be one trailer
289  if (trailer.moreTrailers())
290  {
291  CDFProbThisDCC = true;
292  }
293  // if trailer.
294 
295  /* 9 */ //CDF Trailer [55:30] should be the # 64-bit words in the EvFragment
296  if ((uint64_t) raw.size() != ( (uint64_t) trailer.lenght()*sizeof(uint64_t)) ) //The function name is a typo! Awesome.
297  {
298  CDFProbThisDCC = true;
299  }
300  /*10 */ //There is a rudimentary sanity check built into the FEDTrailer class
301  if (!trailer.check())
302  {
303  CDFProbThisDCC = true;
304  }
305 
306  if (CDFProbThisDCC)
307  fedFatal_->Fill(dccid);
308  fedEntries_->Fill(dccid);
309 
310  return;
311 } // void HcalDataIntegrityTask::unpack()
312 
314 
void beginRun(const edm::Run &run, const edm::EventSetup &c)
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
bool LumiInOrder(int lumisec)
bool check()
Definition: FEDTrailer.cc:64
unsigned int getSlink64ReservedBits() const
Definition: HcalDCCHeader.h:48
#define IPHIMIN
virtual void analyze(const edm::Event &e, const edm::EventSetup &c)
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:942
std::vector< std::vector< bool > > problemHE
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
edm::EDGetTokenT< FEDRawDataCollection > tok_raw_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< int > AllowedCalibTypes_
std::vector< std::vector< uint64_t > > HFmap
bool moreTrailers()
Definition: FEDTrailer.cc:37
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:59
std::map< int, short > CDFversionNumber_list
bool thereIsAThirdCDFHeaderWord() const
Definition: HcalDCCHeader.h:44
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
HcalDataIntegrityTask(const edm::ParameterSet &ps)
std::vector< std::vector< uint64_t > > phatmap
void Fill(long long x)
tuple report
Definition: zeeHLT_cff.py:9
std::map< int, short >::iterator CDFvers_it
virtual void beginRun(const edm::Run &run, const edm::EventSetup &c)
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
void removeContents(void)
erase all monitoring elements in current directory (not including subfolders);
Definition: DQMStore.cc:3080
std::vector< std::vector< uint64_t > > HEmap
const HcalElectronicsMap * readoutMap_
std::vector< int > fedUnpackList_
std::map< int, short >::iterator CDFReservedBits_it
void analyze(const edm::Event &, const edm::EventSetup &)
unsigned short getCDFEventType() const
Definition: HcalDCCHeader.h:38
int getSourceId() const
Definition: HcalDCCHeader.h:32
MonitorElement * fedEntries_
std::vector< std::vector< bool > > problemHF
unsigned long long uint64_t
Definition: Time.h:15
std::map< int, short >::iterator CDFEvT_it
int lenght()
The length of the event fragment counted in 64-bit words including header and trailer.
Definition: FEDTrailer.cc:17
const T & get() const
Definition: EventSetup.h:55
std::vector< std::vector< uint64_t > > HOmap
virtual void reset(void)
short BOEshouldBeZeroAlways() const
Definition: HcalDCCHeader.h:50
std::vector< std::vector< bool > > problemHB
void processEvent(const FEDRawDataCollection &rawraw, const HcalUnpackerReport &report, const HcalElectronicsMap &emap)
#define IPHIMAX
std::vector< std::vector< uint64_t > > HBmap
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
MonitorElement * fedNonFatal_
std::vector< std::vector< bool > > problemHO
#define IETAMAX
#define IETAMIN
std::map< int, short > CDFReservedBits_list
std::map< int, short > CDFEventType_list
string fed
Definition: rpc-layouts.py:7
void unpack(const FEDRawData &raw, const HcalElectronicsMap &emap)
tuple cout
Definition: gather_cfg.py:121
short getCDFversionNumber() const
Definition: HcalDCCHeader.h:30
unsigned short BOEshouldBe5Always() const
Definition: HcalDCCHeader.h:40
virtual void setup(void)
edm::EDGetTokenT< HcalUnpackerReport > tok_report_
std::vector< std::vector< bool > > problemhere
bool thereIsASecondCDFHeaderWord() const
Definition: HcalDCCHeader.h:28
void Reset(void)
reset ME (ie. contents, errors, etc)
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:655
Definition: Run.h:41