CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CastorDataIntegrityMonitor.cc
Go to the documentation of this file.
8 
11 #include <iostream>
12 
13 //****************************************************//
14 //********** CastorDataIntegrityMonitor ******************//
15 //********** Author: Dmytro Volyanskyy *************//
16 //********** Date : 16.03.2011 (first version) ******//
17 //****************************************************//
20 
21 
22 //==================================================================//
23 //======================= Constructor ==============================//
24 //==================================================================//
26 }
27 
28 
29 //==================================================================//
30 //======================= Destructor ===============================//
31 //==================================================================//
33 }
34 
35 
36 //==================================================================//
37 //=========================== reset ===============================//
38 //==================================================================//
40 
41 }
42 
43 //==================================================================//
44 //=========================== cleanup =============================//
45 //==================================================================//
46 
48 
49 }
50 
51 //==================================================================//
52 //=========================== setup ==============================//
53 //==================================================================//
54 
56 {
57 
58  if(fVerbosity>0) std::cout << "CastorDataIntegrityMonitor::setup (start)" << std::endl;
60  baseFolder_ = rootFolder_+"CastorDataIntegrityMonitor";
61  ievt_=0;
62  spigotStatus=-99;
63  statusSpigotDCC=-99;
64  CDFProbThisDCC = false;
65 
66 
68  for (int row=0; row<15; row++)
69  for (int col=0; col<3; col++)
70  problemsSpigot[row][col] = 0;
71 
72 
73 
76  fedUnpackList_.push_back(i);
77 
78  if(fVerbosity>0) std::cout << "CastorDataIntegrityMonitor::setup (end)" << std::endl;
79 
80  return;
81 
82 }
83 
84 
85 //=================================================================//
86 //========================== beginRun =============================//
87 //=================================================================//
89 
90  if(fVerbosity>0) std::cout << "CastorDataIntegrityMonitor::beginRun (start)" << std::endl;
91 
92  if ( m_dbe !=NULL ) {
95  meEVT_ = m_dbe->bookInt("Digi Task Event Number");
96  fedEntries = m_dbe->book1D("FEDEntries_CASTOR" ,"Number of Entries per CASTOR FED",3,690,693); //-- FED 693 take out for the time being
97  fedFatal = m_dbe->book1D("CASTOR FEDFatal errors" ,"Number of Fatal Errors per CASTOR FED",3,690,693); //-- FED 693 take out for the time being
98  //fedNonFatal = m_dbe->book1D("FEDNonFatal_CASTOR","Number of non-fatal errors CASTOR FED",3,690,693); //-- take it out for the time being
99 
100  //meDCCVersion = m_dbe->bookProfile("DCC Firmware Version","DCC Firmware Version", 3, 690, 693, 256, -0.5, 255.5);
101  //meDCCVersion->setAxisTitle("FED ID", 1);
102  spigotStatusMap = m_dbe->book2D("CASTOR spigot status","CASTOR spigot status",15,0,15,4,690,694); //-- get some space for the legend
103 
104  }
105 
106  else{
107  if(fVerbosity>0) std::cout << "CastorDataIntegrityMonitor::setup - NO DQMStore service" << std::endl;
108  }
109 
110 
111  if(fVerbosity>0) std::cout << "CastorDataIntegrityMonitor::beginRun (end)" << std::endl;
112 
113 
114  return;
115 }
116 
117 
118 
119 //=================================================================//
120 //========================== processEvent =========================//
121 //=================================================================//
122 
124  {
125  if(fVerbosity>0) std::cout << "CastorDataIntegrityMonitor::processEvent (begin)" << std::endl;
126 
127  meEVT_->Fill(ievt_);
128 
130  ievt_++;
131 
133  for (std::vector<int>::const_iterator i=fedUnpackList_.begin();i!=fedUnpackList_.end(); i++) {
134  const FEDRawData& fed = RawData.FEDData(*i);
135  if (fed.size()<12) continue;
136  unpack(fed,emap);
137  }
138 
140  for (int spigot=0; spigot<15; spigot++){
141  for (int dcc=0; dcc<3; dcc++){
142 
143  if( problemsSpigot[spigot][dcc] == 0) statusSpigotDCC=1.0;
144  else if( double(problemsSpigot[spigot][dcc])/double(ievt_) < 0.05) statusSpigotDCC=0.;
145  else statusSpigotDCC=-1.0;
147  spigotStatusMap->getTH2F()->SetBinContent(spigot+1,dcc+1,statusSpigotDCC);
148  if(fVerbosity>1)
149  std::cout<< "==> SpigotNr:"<< spigot+1 <<" DCC_ID:"<< dcc+690 << " # problems=" << problemsSpigot[spigot][dcc]
150  << "==> ievt_:"<< ievt_ << " ratio=" << double(problemsSpigot[spigot][dcc])/double(ievt_) << " STATUS=" << statusSpigotDCC << std::endl;
151  }
152  }
153 
154  if(fVerbosity>0) std::cout << "CastorDataIntegrityMonitor::processEvent (end)" << std::endl;
155 
156  return;
157 }
158 
159 
160 //=======================================================//
161 //=============== unpack CASTOR FED =====================//
162 //=======================================================//
163 
165 
166 
168  const HcalDCCHeader* dccHeader=(const HcalDCCHeader*)(raw.data());
169  if(!dccHeader) return;
170 
172  unsigned char* trailer_ptr = (unsigned char*) (raw.data()+raw.size()-sizeof(uint64_t));
173  FEDTrailer trailer = FEDTrailer(trailer_ptr);
174 
175  dccid=dccHeader->getSourceId();
176 
177  HcalHTRData htr;
178 
180  CDFProbThisDCC = false;
181 
182 
183  //================ BASIC CHECKS OF DATA INTEGRITY ====================//
184 
185 
187 
188  /* 1 */ //There should always be a second CDF header word indicated.
189  if (!dccHeader->thereIsASecondCDFHeaderWord())
190  {
191  CDFProbThisDCC = true;
192  }
193 
194  /* 2 */ //Make sure a reference CDF Version value has been recorded for this dccid
196  if (CDFvers_it == CDFversionNumber_list.end())
197  {
198  CDFversionNumber_list.insert(std::pair<int,short>
199  (dccid,dccHeader->getCDFversionNumber() ) );
201  } // then check against it.
202 
203  if (dccHeader->getCDFversionNumber()!= CDFvers_it->second)
204  {
205  CDFProbThisDCC = true;
206  }
207 
208  /* 3 */ //Make sure a reference CDF EventType value has been recorded for this dccid
210  if (CDFEvT_it == CDFEventType_list.end())
211  {
212  CDFEventType_list.insert(std::pair<int,short>
213  (dccid,dccHeader->getCDFEventType() ) );
215  } // then check against it.
216 
217  if (dccHeader->getCDFEventType()!= CDFEvT_it->second)
218  {
219  // On probation until safe against Orbit Gap Calibration Triggers...
220  CDFProbThisDCC = true;
221  }
222 
223  /* 4 */ //There should always be a '5' in CDF Header word 0, bits [63:60]
224  if (dccHeader->BOEshouldBe5Always()!=5)
225  {
226  CDFProbThisDCC = true;
227  }
228 
229  /* 5 */ //There should never be a third CDF Header word indicated.
230  if (dccHeader->thereIsAThirdCDFHeaderWord())
231  {
232  CDFProbThisDCC = true;
233  }
234 
235  /* 6 */ //Make sure a reference value of Reserved Bits has been recorded for this dccid
236 
239  CDFReservedBits_list.insert(std::pair<int,short>
240  (dccid,dccHeader->getSlink64ReservedBits() ) );
242  } // then check against it.
243 
244  if ((int) dccHeader->getSlink64ReservedBits()!= CDFReservedBits_it->second)
245  {
246  // On probation until safe against Orbit Gap Calibration Triggers...
247  // CDFProbThisDCC = true;
248  }
249 
250  /* 7 */ //There should always be 0x0 in CDF Header word 1, bits [63:60]
251  if (dccHeader->BOEshouldBeZeroAlways() !=0)
252  {
253  CDFProbThisDCC = true;
254  }
255 
256  /* 8 */ //There should only be one trailer
257  if (trailer.moreTrailers())
258  {
259  CDFProbThisDCC = true;
260  }
261  // if trailer.
262 
263  /* 9 */ //CDF Trailer [55:30] should be the # 64-bit words in the EvFragment
264  if ((uint64_t) raw.size() != ( (uint64_t) trailer.lenght()*sizeof(uint64_t)) ) //The function name is a typo! Awesome.
265  {
266  CDFProbThisDCC = true;
267  }
268  /*10 */ //There is a rudimentary sanity check built into the FEDTrailer class
269  if (!trailer.check())
270  {
271  CDFProbThisDCC = true;
272  }
273 
276 
279 
280 
281 
282  //================== do similar what HCALRawDataMonitor does
284  //uint64_t* dccfw= (uint64_t*) (raw.data()+(sizeof(uint64_t)*2)); //64-bit DAQ word number 2 (from 0)
285  //int dcc_fw = ( ((*dccfw)>>(6*8))&0x00000000000000FF ); //Shift right 6 bytes, get that low byte.
286  //meDCCVersion->Fill(dccid,dcc_fw);
287  //char TTS_state = (char)trailer.ttsBits();
288 
289  //errors per-Spigot bits from the DCC Header
290  int WholeErrorList=0;
291 
293  for(int spigot=0; spigot<HcalDCCHeader::SPIGOT_COUNT; spigot++) {
294 
295  if (!( dccHeader->getSpigotEnabled((unsigned int) spigot)) ) continue; //-- skip when not enabled
296 
297  //-- set OK here
298  spigotStatus=1;
299  //-- get DCC id
300  dccid=dccHeader->getSourceId();
301 
302  if (dccid==693) continue; //-- skip this one
303 
305  WholeErrorList=dccHeader->getLRBErrorBits((unsigned int) spigot);
306  if (WholeErrorList!=0) {
307 
308  if ((WholeErrorList>>0)&0x01) {
309  if(fVerbosity>0) std::cout << "CastorDataIntegrityMonitor:: error==> " << std::endl;
310  spigotStatus=-1;
311  ++problemsSpigot[spigot][dccid-690];
312  }
313 
314  if (((WholeErrorList>>1)&0x01)!=0) {
315  if(fVerbosity>0) std::cout << "CastorDataIntegrityMonitor:: error ==> Uncorrected Error" << std::endl;
316  if(spigotStatus>0) ++problemsSpigot[spigot][dccid-690];
317  spigotStatus=-1;
318  }
319 
320  if (((WholeErrorList>>2)&0x01)!=0) {
321  if(fVerbosity>0) std::cout << "CastorDataIntegrityMonitor:: error ==> Truncated data coming into LRB" << std::endl;
322  if(spigotStatus>0) ++problemsSpigot[spigot][dccid-690];
323  spigotStatus=-1;
324  }
325 
326  if (((WholeErrorList>>3)&0x01)!=0) {
327  if(fVerbosity>0) std::cout << "CastorDataIntegrityMonitor: error ==>: FIFO Overflow" << std::endl;
328  if(spigotStatus>0) ++problemsSpigot[spigot][dccid-690];
329  spigotStatus=-1;
330  }
331 
332  if (((WholeErrorList>>4)&0x01)!=0) {
333  if(fVerbosity>0) std::cout << "CastorDataIntegrityMonitor:: error ==> (EvN Mismatch), htr payload metadeta" << std::endl;
334  if(spigotStatus>0) ++problemsSpigot[spigot][dccid-690];
335  spigotStatus=-1;
336  }
337 
338  if (((WholeErrorList>>5)&0x01)!=0) {
339  if(fVerbosity>0) std::cout << "CastorDataIntegrityMonitor:: error ==> STatus: hdr/data/trlr error" << std::endl;
340  if(spigotStatus>0) ++problemsSpigot[spigot][dccid-690];
341  spigotStatus=-1;
342  }
343 
344  if (((WholeErrorList>>6)&0x01)!=0) {
345  if(fVerbosity>0) std::cout << "CastorDataIntegrityMonitor:: error ==> ODD 16-bit word count from HT error" << std::endl;
346  if(spigotStatus>0) ++problemsSpigot[spigot][dccid-690];
347  spigotStatus=-1;
348  }
349 
350  }
351 
353 
354  if (!dccHeader->getSpigotPresent((unsigned int) spigot)){
355  if(fVerbosity>0) std::cout <<"CastorDataIntegrityMonitor:: HTR Problem: Spigot Not Present"<<std::endl;
356  if(spigotStatus>0) ++problemsSpigot[spigot][dccid-690];
357  spigotStatus=-1;
358  }
359  else {
360  if ( dccHeader->getSpigotDataTruncated((unsigned int) spigot)) {
361  if(fVerbosity>0) std::cout <<"CastorDataIntegrityMonitor:: HTR Problem: Spigot Data Truncated"<<std::endl;
362  if(spigotStatus>0) ++problemsSpigot[spigot][dccid-690];
363  spigotStatus=-1;
364  }
365  if ( dccHeader->getSpigotCRCError((unsigned int) spigot)) {
366  if(fVerbosity>0) std::cout <<"CastorDataIntegrityMonitor:: HTR Problem: Spigot CRC Error"<<std::endl;
367  if(spigotStatus>0) ++problemsSpigot[spigot][dccid-690];
368  spigotStatus=-1;
369  }
370  if (dccHeader->getSpigotDataLength(spigot) <(unsigned long)4) {
371  if(fVerbosity>0) std::cout <<"CastorDataIntegrityMonitor:: HTR Problem: Spigot Data Length too small"<<std::endl;
372  if(spigotStatus>0) ++problemsSpigot[spigot][dccid-690];
373  spigotStatus=-1;
374  }
375 
376  if (dccHeader->getSpigotData(spigot,htr,raw.size())==-1) {
377  if(fVerbosity>0) std::cout<< "CastorDataIntegrityMonitor:: Invalid HTR data (data beyond payload size) observed on spigot " << spigot
378  << " of DCC with source id " << dccHeader->getSourceId()<< std::endl;
379  if(spigotStatus>0) ++problemsSpigot[spigot][dccid-690];
380  spigotStatus=-1;
381  }
382 
383  if (!htr.check()) {
384  if(fVerbosity>0) std::cout << "CastorDataIntegrityMonitor:: Invalid HTR data observed on spigot " << spigot << " of DCC with source id " << dccHeader->getSourceId() << std::endl;
385  if(spigotStatus>0) ++problemsSpigot[spigot][dccid-690];
386  spigotStatus=-1;
387  }
388 
389  if (htr.isHistogramEvent()) {
390  if(fVerbosity>0) std::cout << "CastorDataIntegrityMonitor:: Histogram data passed to non-histogram unpacker on spigot " << spigot << " of DCC with source id "
391  << dccHeader->getSourceId() << std::endl;
392  if(spigotStatus>0) ++problemsSpigot[spigot][dccid-690];
393  spigotStatus=-1;
394  }
395 
396  }
397 
398  } //-- end of loop over spigots
399 
400  return;
401 }
int i
Definition: DBlmapReader.cc:9
std::map< int, short > CDFEventType_list
bool check()
Definition: FEDTrailer.cc:64
unsigned int getSlink64ReservedBits() const
Definition: HcalDCCHeader.h:48
void unpack(const FEDRawData &raw, const CastorElectronicsMap &emap)
virtual void setup(const edm::ParameterSet &ps, DQMStore *dbe)
unsigned int getSpigotDataLength(int nspigot) const
Definition: HcalDCCHeader.h:96
bool check() const
Check for a good event Requires a minimum length, matching wordcount and length, not an empty event...
Definition: HcalHTRData.cc:62
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:928
bool getSpigotCRCError(unsigned int nspigot) const
Read the &quot;CRC-Mismatch&quot; bit for this spigot.
bool moreTrailers()
Definition: FEDTrailer.cc:37
#define NULL
Definition: scimark2.h:8
bool thereIsAThirdCDFHeaderWord() const
Definition: HcalDCCHeader.h:44
int getSpigotData(int nspigot, HcalHTRData &decodeTool, int validSize) const
unsigned char getLRBErrorBits(unsigned int nspigot) const
Access the Link Receiver Board error bits (decoding tbd)
void beginRun(const edm::EventSetup &iSetup)
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
std::map< int, short >::iterator CDFvers_it
void Fill(long long x)
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
std::string baseFolder_
std::map< int, short > CDFReservedBits_list
bool getSpigotPresent(unsigned int nspigot) const
Read the &quot;PRESENT&quot; bit for this spigot.
unsigned short getCDFEventType() const
Definition: HcalDCCHeader.h:38
std::map< int, short >::iterator CDFReservedBits_it
bool getSpigotEnabled(unsigned int nspigot) const
Read the &quot;ENABLED&quot; bit for this spigot.
Definition: HcalDCCHeader.h:99
int getSourceId() const
Definition: HcalDCCHeader.h:32
unsigned long long uint64_t
Definition: Time.h:15
int lenght()
The length of the event fragment counted in 64-bit words including header and trailer.
Definition: FEDTrailer.cc:17
std::map< int, short > CDFversionNumber_list
void processEvent(const FEDRawDataCollection &RawData, const HcalUnpackerReport &report, const CastorElectronicsMap &emap)
short BOEshouldBeZeroAlways() const
Definition: HcalDCCHeader.h:50
void setup(const edm::ParameterSet &ps, DQMStore *dbe)
std::map< int, short >::iterator CDFEvT_it
static const int SPIGOT_COUNT
Definition: HcalDCCHeader.h:19
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
std::string rootFolder_
bool getSpigotDataTruncated(unsigned int nspigot) const
Read the &quot;TRUNCATED&quot; bit for this spigot; LRB truncated data (took too long)
tuple cout
Definition: gather_cfg.py:121
short getCDFversionNumber() const
Definition: HcalDCCHeader.h:30
TH2F * getTH2F(void) const
MonitorElement * bookInt(const char *name)
Book int.
Definition: DQMStore.cc:835
unsigned short BOEshouldBe5Always() const
Definition: HcalDCCHeader.h:40
MonitorElement * book2D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Book 2D histogram.
Definition: DQMStore.cc:1056
int col
Definition: cuy.py:1008
bool thereIsASecondCDFHeaderWord() const
Definition: HcalDCCHeader.h:28
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:639
bool isHistogramEvent() const
Is this event a histogram event? (do not call standard unpack in this case!!!!!)
Definition: HcalHTRData.cc:385