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