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 } // HcalDataIntegrityTask::HcalDataIntegrityTask()
32 
34 
36 {
37  if (debug_>0) std::cout <<"HcalDataIntegrityTask::reset()"<<std::endl;
39  fedEntries_->Reset();
40  fedFatal_->Reset();
42 
43 }
44 
46 {
47  if(dbe_)
48  {
51  }
52 
53 } // void HcalDataIntegrityTask::cleanup()
54 
55 
57 {
58 
59  if (debug_>0) std::cout <<"HcalDataIntegrityTask::beginRun(): task = '"<<subdir_<<"'"<<std::endl;
60 
62  if (mergeRuns_ && tevt_>0) return;
63 
64  if (debug_>1) std::cout<<"\t<HcalDataIntegrityTask::getting eMap..."<<std::endl;
66  c.get<HcalDbRecord>().get( pSetup );
67  readoutMap_=pSetup->getHcalMapping();
68 
69  if (tevt_==0) // create histograms, if they haven't been created already
70  this->setup();
71  // Clear histograms at the start of each run if not merging runs
72  if (mergeRuns_==false)
73  this->reset();
74 
75 } // beginRun(const edm::Run& run, const edm::EventSetup& c)
76 
77 
79 {
80  // Setup Creates all necessary histograms
82 
83  //Initialize phatmap to a vector of vectors of uint64_t 0
84  static size_t iphirange = IPHIMAX - IPHIMIN;
85  static size_t ietarange = IETAMAX - IETAMIN;
86 
87  std::vector<uint64_t> phatv (iphirange + 1, 0);
88 
89  if (debug_>0) std::cout <<"<HcalDataIntegrityTask::setup> Clearing old vectors"<<std::endl;
90  // Clear any old vectors
91  phatmap.clear();
92  HBmap.clear();
93  HEmap.clear();
94  HFmap.clear();
95  HOmap.clear();
96  problemhere.clear();
97  problemHB.clear();
98  problemHE.clear();
99  problemHF.clear();
100  problemHO.clear();
101 
102  // ... nothing goes at ieta=0, so an extra bin goes there.
103  phatmap = std::vector< std::vector < uint64_t> > ( ietarange + 1, phatv);
104  HBmap = std::vector< std::vector < uint64_t> > ( ietarange + 1, phatv);
105  HEmap = std::vector< std::vector < uint64_t> > ( ietarange + 1, phatv);
106  HFmap = std::vector< std::vector < uint64_t> > ( ietarange + 1, phatv);
107  HOmap = std::vector< std::vector < uint64_t> > ( ietarange + 1, phatv);
108  std::vector<bool> probvect (iphirange + 1, 0);
109  // ... nothing goes at ieta=0, so an extra bin goes there.
110  problemhere = std::vector< std::vector <bool> > ( ietarange + 1, probvect);
111  problemHB = std::vector< std::vector <bool> > ( ietarange + 1, probvect);
112  problemHE = std::vector< std::vector <bool> > ( ietarange + 1, probvect);
113  problemHF = std::vector< std::vector <bool> > ( ietarange + 1, probvect);
114  problemHO = std::vector< std::vector <bool> > ( ietarange + 1, probvect);
115 
116 
117 
118  if(debug_>1)
119  std::cout << "About to pushback fedUnpackList_" << std::endl;
120 
121  // Use this in CMSSW_3_0_X and above:
123  for (int i=FEDNumbering::MINHCALFEDID;
125  ++i)
126  {
127  if(debug_>1) std::cout << "[DFMon:]Pushback for fedUnpackList_: " << i <<std::endl;
128  fedUnpackList_.push_back(i);
129  }
130 
131  if ( dbe_ )
132  {
133 
134  if (debug_>1)
135  std::cout <<"\t<HcalDataIntegrityTask> Setting folder to "<<subdir_<<std::endl;
136 
138 
139  fedEntries_ = dbe_->book1D("FEDEntries","# entries per HCAL FED",32,700,732);
140  fedFatal_ = dbe_->book1D("FEDFatal","# fatal errors HCAL FED",32,700,732);
141  fedNonFatal_ = dbe_->book1D("FEDNonFatal","# non-fatal errors HCAL FED",32,700,732);
142  } // if (dbe_)
143 
144  this->reset(); // clear all histograms at start
145  return;
146 }
147 
149 {
150  if (!IsAllowedCalibType()) return;
151  if (LumiInOrder(e.luminosityBlock())==false) return;
152 
153  // Now get the collections we need
154 
156 
157  // Trying new getByLabel
158  if (!(e.getByLabel(inputLabelRawData_,rawraw)))
159  {
160  if (debug_>0) edm::LogWarning("HcalDataIntegrityTask")<<" raw data with label "<<inputLabelRawData_<<" not available";
161  return;
162  }
163 
165  if (!(e.getByLabel(inputLabelReport_,report)))
166  {
167  if (debug_>0) edm::LogWarning("HcalDataIntegrityTask")<<" UnpackerReport with label "<<inputLabelReport_<<" \not available";
168  return;
169  }
170 
171  // Collections were found; increment counters
173 
174  processEvent(*rawraw, *report, *readoutMap_);
175 }
176 
177 
178 
180  const HcalUnpackerReport& report,
181  const HcalElectronicsMap& emap){
182 
183  if(!dbe_)
184  {
185  std::cout<<"HcalDataIntegrityTask::processEvent DQMStore not instantiated!!!"<<std::endl;
186  return;
187  }
188 
189  // Loop over all FEDs reporting the event, unpacking if good.
190  for (std::vector<int>::const_iterator i=fedUnpackList_.begin();i!=fedUnpackList_.end(); i++)
191  {
192  const FEDRawData& fed = rawraw.FEDData(*i);
193  if (fed.size()<12) continue; // Was 16. How do such tiny events even get here?
194  unpack(fed,emap);
195  }
196 
197  return;
198 } //void HcalDataIntegrityTask::processEvent()
199 
200 
201 // Process one FED's worth (one DCC's worth) of the event data.
203  const HcalElectronicsMap& emap){
204  // get the DCC header
205  const HcalDCCHeader* dccHeader=(const HcalDCCHeader*)(raw.data());
206  if(!dccHeader) return;
207 
208  // get the DCC trailer
209  unsigned char* trailer_ptr = (unsigned char*) (raw.data()+raw.size()-sizeof(uint64_t));
210  FEDTrailer trailer = FEDTrailer(trailer_ptr);
211 
212  int dccid=dccHeader->getSourceId();
213 
215  bool CDFProbThisDCC = false;
216  /* 1 */ //There should always be a second CDF header word indicated.
217  if (!dccHeader->thereIsASecondCDFHeaderWord())
218  {
219  CDFProbThisDCC = true;
220  }
221 
222  /* 2 */ //Make sure a reference CDF Version value has been recorded for this dccid
223  CDFvers_it = CDFversionNumber_list.find(dccid);
224  if (CDFvers_it == CDFversionNumber_list.end())
225  {
226  CDFversionNumber_list.insert(std::pair<int,short>
227  (dccid,dccHeader->getCDFversionNumber() ) );
228  CDFvers_it = CDFversionNumber_list.find(dccid);
229  } // then check against it.
230 
231  if (dccHeader->getCDFversionNumber()!= CDFvers_it->second)
232  {
233  CDFProbThisDCC = true;
234  }
235 
236  /* 3 */ //Make sure a reference CDF EventType value has been recorded for this dccid
237  CDFEvT_it = CDFEventType_list.find(dccid);
238  if (CDFEvT_it == CDFEventType_list.end())
239  {
240  CDFEventType_list.insert(std::pair<int,short>
241  (dccid,dccHeader->getCDFEventType() ) );
242  CDFEvT_it = CDFEventType_list.find(dccid);
243  } // then check against it.
244 
245  if (dccHeader->getCDFEventType()!= CDFEvT_it->second)
246  {
247  // On probation until safe against Orbit Gap Calibration Triggers...
248  // CDFProbThisDCC = true;
249  }
250 
251  /* 4 */ //There should always be a '5' in CDF Header word 0, bits [63:60]
252  if (dccHeader->BOEshouldBe5Always()!=5)
253  {
254  CDFProbThisDCC = true;
255  }
256 
257  /* 5 */ //There should never be a third CDF Header word indicated.
258  if (dccHeader->thereIsAThirdCDFHeaderWord())
259  {
260  CDFProbThisDCC = true;
261  }
262 
263  /* 6 */ //Make sure a reference value of Reserved Bits has been recorded for this dccid
264 
267  CDFReservedBits_list.insert(std::pair<int,short>
268  (dccid,dccHeader->getSlink64ReservedBits() ) );
270  } // then check against it.
271 
272  if ((int) dccHeader->getSlink64ReservedBits()!= CDFReservedBits_it->second)
273  {
274  // On probation until safe against Orbit Gap Calibration Triggers...
275  // CDFProbThisDCC = true;
276  }
277 
278  /* 7 */ //There should always be 0x0 in CDF Header word 1, bits [63:60]
279  if (dccHeader->BOEshouldBeZeroAlways() !=0)
280  {
281  CDFProbThisDCC = true;
282  }
283 
284  /* 8 */ //There should only be one trailer
285  if (trailer.moreTrailers())
286  {
287  CDFProbThisDCC = true;
288  }
289  // if trailer.
290 
291  /* 9 */ //CDF Trailer [55:30] should be the # 64-bit words in the EvFragment
292  if ((uint64_t) raw.size() != ( (uint64_t) trailer.lenght()*sizeof(uint64_t)) ) //The function name is a typo! Awesome.
293  {
294  CDFProbThisDCC = true;
295  }
296  /*10 */ //There is a rudimentary sanity check built into the FEDTrailer class
297  if (!trailer.check())
298  {
299  CDFProbThisDCC = true;
300  }
301 
302  if (CDFProbThisDCC)
303  fedFatal_->Fill(dccid);
304  fedEntries_->Fill(dccid);
305 
306  return;
307 } // void HcalDataIntegrityTask::unpack()
308 
310 
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:66
unsigned int getSlink64ReservedBits() const
Definition: HcalDCCHeader.h:50
#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:722
std::vector< std::vector< bool > > problemHE
#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:39
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:59
std::map< int, short > CDFversionNumber_list
bool thereIsAThirdCDFHeaderWord() const
Definition: HcalDCCHeader.h:46
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:49
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:2569
std::vector< std::vector< uint64_t > > HEmap
const HcalElectronicsMap * readoutMap_
std::vector< int > fedUnpackList_
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
std::map< int, short >::iterator CDFReservedBits_it
void analyze(const edm::Event &, const edm::EventSetup &)
unsigned short getCDFEventType() const
Definition: HcalDCCHeader.h:40
int getSourceId() const
Definition: HcalDCCHeader.h:34
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:19
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:52
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:29
MonitorElement * fedNonFatal_
std::vector< std::vector< bool > > problemHO
#define IETAMAX
#define IETAMIN
std::map< int, short > CDFReservedBits_list
std::map< int, short > CDFEventType_list
void unpack(const FEDRawData &raw, const HcalElectronicsMap &emap)
tuple cout
Definition: gather_cfg.py:121
short getCDFversionNumber() const
Definition: HcalDCCHeader.h:32
unsigned short BOEshouldBe5Always() const
Definition: HcalDCCHeader.h:42
virtual void setup(void)
std::vector< std::vector< bool > > problemhere
bool thereIsASecondCDFHeaderWord() const
Definition: HcalDCCHeader.h:30
void Reset(void)
reset ME (ie. contents, errors, etc)
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:434
Definition: Run.h:36