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 ( m_dbe !=NULL ) {
81  meEVT_ = m_dbe->bookInt("Digi Task Event Number");
82  fedEntries = m_dbe->book1D("FEDEntries_CASTOR" ,"Number of Entries per CASTOR FED",3,690,693); //-- FED 693 take out for the time being
83  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
84  //fedNonFatal = m_dbe->book1D("FEDNonFatal_CASTOR","Number of non-fatal errors CASTOR FED",3,690,693); //-- take it out for the time being
85 
86  //meDCCVersion = m_dbe->bookProfile("DCC Firmware Version","DCC Firmware Version", 3, 690, 693, 256, -0.5, 255.5);
87  //meDCCVersion->setAxisTitle("FED ID", 1);
88  spigotStatusMap = m_dbe->book2D("CASTOR spigot status","CASTOR spigot status",15,0,15,4,690,694); //-- get some space for the legend
89 
90  }
91 
92  else{
93  if(fVerbosity>0) std::cout << "CastorDigiMonitor::setup - NO DQMStore service" << std::endl;
94  }
95 
96  if(fVerbosity>0) std::cout << "CastorDigiMonitor::setup (end)" << std::endl;
97 
98  return;
99 
100 }
101 
102 
104 
105  if(fVerbosity>0) std::cout << "CastorDataIntegrityMonitor::processEvent" << std::endl;
106 
107  meEVT_->Fill(ievt_);
108 
110  ievt_++;
111 
113  for (std::vector<int>::const_iterator i=fedUnpackList_.begin();i!=fedUnpackList_.end(); i++) {
114  const FEDRawData& fed = RawData.FEDData(*i);
115  if (fed.size()<12) continue;
116  unpack(fed,emap);
117  }
118 
120  for (int spigot=0; spigot<15; spigot++){
121  for (int dcc=0; dcc<3; dcc++){
122 
123  if( problemsSpigot[spigot][dcc] == 0) statusSpigotDCC=1.0;
124  else if( double(problemsSpigot[spigot][dcc])/double(ievt_) < 0.05) statusSpigotDCC=0.;
125  else statusSpigotDCC=-1.0;
127  spigotStatusMap->getTH2F()->SetBinContent(spigot+1,dcc+1,statusSpigotDCC);
128  if(fVerbosity>0)
129  std::cout<< "==> SpigotNr:"<< spigot+1 <<" DCC_ID:"<< dcc+690 << " # problems=" << problemsSpigot[spigot][dcc]
130  << "==> ievt_:"<< ievt_ << " ratio=" << double(problemsSpigot[spigot][dcc])/double(ievt_) << " STATUS=" << statusSpigotDCC << std::endl;
131  }
132  }
133 
134 
135 
136 
137 
138 
139  return;
140 }
141 
142 
143 //=======================================================//
144 //=============== unpack CASTOR FED =====================//
145 //=======================================================//
146 
148 
149 
151  const HcalDCCHeader* dccHeader=(const HcalDCCHeader*)(raw.data());
152  if(!dccHeader) return;
153 
155  unsigned char* trailer_ptr = (unsigned char*) (raw.data()+raw.size()-sizeof(uint64_t));
156  FEDTrailer trailer = FEDTrailer(trailer_ptr);
157 
158  dccid=dccHeader->getSourceId();
159 
160  HcalHTRData htr;
161 
163  CDFProbThisDCC = false;
164 
165 
166  //================ BASIC CHECKS OF DATA INTEGRITY ====================//
167 
168 
170 
171  /* 1 */ //There should always be a second CDF header word indicated.
172  if (!dccHeader->thereIsASecondCDFHeaderWord())
173  {
174  CDFProbThisDCC = true;
175  }
176 
177  /* 2 */ //Make sure a reference CDF Version value has been recorded for this dccid
179  if (CDFvers_it == CDFversionNumber_list.end())
180  {
181  CDFversionNumber_list.insert(std::pair<int,short>
182  (dccid,dccHeader->getCDFversionNumber() ) );
184  } // then check against it.
185 
186  if (dccHeader->getCDFversionNumber()!= CDFvers_it->second)
187  {
188  CDFProbThisDCC = true;
189  }
190 
191  /* 3 */ //Make sure a reference CDF EventType value has been recorded for this dccid
193  if (CDFEvT_it == CDFEventType_list.end())
194  {
195  CDFEventType_list.insert(std::pair<int,short>
196  (dccid,dccHeader->getCDFEventType() ) );
198  } // then check against it.
199 
200  if (dccHeader->getCDFEventType()!= CDFEvT_it->second)
201  {
202  // On probation until safe against Orbit Gap Calibration Triggers...
203  CDFProbThisDCC = true;
204  }
205 
206  /* 4 */ //There should always be a '5' in CDF Header word 0, bits [63:60]
207  if (dccHeader->BOEshouldBe5Always()!=5)
208  {
209  CDFProbThisDCC = true;
210  }
211 
212  /* 5 */ //There should never be a third CDF Header word indicated.
213  if (dccHeader->thereIsAThirdCDFHeaderWord())
214  {
215  CDFProbThisDCC = true;
216  }
217 
218  /* 6 */ //Make sure a reference value of Reserved Bits has been recorded for this dccid
219 
222  CDFReservedBits_list.insert(std::pair<int,short>
223  (dccid,dccHeader->getSlink64ReservedBits() ) );
225  } // then check against it.
226 
227  if ((int) dccHeader->getSlink64ReservedBits()!= CDFReservedBits_it->second)
228  {
229  // On probation until safe against Orbit Gap Calibration Triggers...
230  // CDFProbThisDCC = true;
231  }
232 
233  /* 7 */ //There should always be 0x0 in CDF Header word 1, bits [63:60]
234  if (dccHeader->BOEshouldBeZeroAlways() !=0)
235  {
236  CDFProbThisDCC = true;
237  }
238 
239  /* 8 */ //There should only be one trailer
240  if (trailer.moreTrailers())
241  {
242  CDFProbThisDCC = true;
243  }
244  // if trailer.
245 
246  /* 9 */ //CDF Trailer [55:30] should be the # 64-bit words in the EvFragment
247  if ((uint64_t) raw.size() != ( (uint64_t) trailer.lenght()*sizeof(uint64_t)) ) //The function name is a typo! Awesome.
248  {
249  CDFProbThisDCC = true;
250  }
251  /*10 */ //There is a rudimentary sanity check built into the FEDTrailer class
252  if (!trailer.check())
253  {
254  CDFProbThisDCC = true;
255  }
256 
259 
262 
263 
264 
265  //================== do similar what HCALRawDataMonitor does
267  //uint64_t* dccfw= (uint64_t*) (raw.data()+(sizeof(uint64_t)*2)); //64-bit DAQ word number 2 (from 0)
268  //int dcc_fw = ( ((*dccfw)>>(6*8))&0x00000000000000FF ); //Shift right 6 bytes, get that low byte.
269  //meDCCVersion->Fill(dccid,dcc_fw);
270  //char TTS_state = (char)trailer.ttsBits();
271 
272  //errors per-Spigot bits from the DCC Header
273  int WholeErrorList=0;
274 
276  for(int spigot=0; spigot<HcalDCCHeader::SPIGOT_COUNT; spigot++) {
277 
278  if (!( dccHeader->getSpigotEnabled((unsigned int) spigot)) ) continue; //-- skip when not enabled
279 
280  //-- set OK here
281  spigotStatus=1;
282  //-- get DCC id
283  dccid=dccHeader->getSourceId();
284 
285  if (dccid==693) continue; //-- skip this one
286 
288  WholeErrorList=dccHeader->getLRBErrorBits((unsigned int) spigot);
289  if (WholeErrorList!=0) {
290 
291  if ((WholeErrorList>>0)&0x01) {
292  if(fVerbosity>0) std::cout << "CastorDataIntegrityMonitor:: error==> " << std::endl;
293  spigotStatus=-1;
294  ++problemsSpigot[spigot][dccid-690];
295  }
296 
297  if (((WholeErrorList>>1)&0x01)!=0) {
298  if(fVerbosity>0) std::cout << "CastorDataIntegrityMonitor:: error ==> Uncorrected Error" << std::endl;
299  if(spigotStatus>0) ++problemsSpigot[spigot][dccid-690];
300  spigotStatus=-1;
301  }
302 
303  if (((WholeErrorList>>2)&0x01)!=0) {
304  if(fVerbosity>0) std::cout << "CastorDataIntegrityMonitor:: error ==> Truncated data coming into LRB" << std::endl;
305  if(spigotStatus>0) ++problemsSpigot[spigot][dccid-690];
306  spigotStatus=-1;
307  }
308 
309  if (((WholeErrorList>>3)&0x01)!=0) {
310  if(fVerbosity>0) std::cout << "CastorDataIntegrityMonitor: error ==>: FIFO Overflow" << std::endl;
311  if(spigotStatus>0) ++problemsSpigot[spigot][dccid-690];
312  spigotStatus=-1;
313  }
314 
315  if (((WholeErrorList>>4)&0x01)!=0) {
316  if(fVerbosity>0) std::cout << "CastorDataIntegrityMonitor:: error ==> (EvN Mismatch), htr payload metadeta" << std::endl;
317  if(spigotStatus>0) ++problemsSpigot[spigot][dccid-690];
318  spigotStatus=-1;
319  }
320 
321  if (((WholeErrorList>>5)&0x01)!=0) {
322  if(fVerbosity>0) std::cout << "CastorDataIntegrityMonitor:: error ==> STatus: hdr/data/trlr error" << std::endl;
323  if(spigotStatus>0) ++problemsSpigot[spigot][dccid-690];
324  spigotStatus=-1;
325  }
326 
327  if (((WholeErrorList>>6)&0x01)!=0) {
328  if(fVerbosity>0) std::cout << "CastorDataIntegrityMonitor:: error ==> ODD 16-bit word count from HT error" << std::endl;
329  if(spigotStatus>0) ++problemsSpigot[spigot][dccid-690];
330  spigotStatus=-1;
331  }
332 
333  }
334 
336 
337  if (!dccHeader->getSpigotPresent((unsigned int) spigot)){
338  if(fVerbosity>0) std::cout <<"CastorDataIntegrityMonitor:: HTR Problem: Spigot Not Present"<<std::endl;
339  if(spigotStatus>0) ++problemsSpigot[spigot][dccid-690];
340  spigotStatus=-1;
341  }
342  else {
343  if ( dccHeader->getSpigotDataTruncated((unsigned int) spigot)) {
344  if(fVerbosity>0) std::cout <<"CastorDataIntegrityMonitor:: HTR Problem: Spigot Data Truncated"<<std::endl;
345  if(spigotStatus>0) ++problemsSpigot[spigot][dccid-690];
346  spigotStatus=-1;
347  }
348  if ( dccHeader->getSpigotCRCError((unsigned int) spigot)) {
349  if(fVerbosity>0) std::cout <<"CastorDataIntegrityMonitor:: HTR Problem: Spigot CRC Error"<<std::endl;
350  if(spigotStatus>0) ++problemsSpigot[spigot][dccid-690];
351  spigotStatus=-1;
352  }
353  if (dccHeader->getSpigotDataLength(spigot) <(unsigned long)4) {
354  if(fVerbosity>0) std::cout <<"CastorDataIntegrityMonitor:: HTR Problem: Spigot Data Length too small"<<std::endl;
355  if(spigotStatus>0) ++problemsSpigot[spigot][dccid-690];
356  spigotStatus=-1;
357  }
358 
359  if (dccHeader->getSpigotData(spigot,htr,raw.size())==-1) {
360  if(fVerbosity>0) std::cout<< "CastorDataIntegrityMonitor:: Invalid HTR data (data beyond payload size) observed on spigot " << spigot
361  << " of DCC with source id " << dccHeader->getSourceId()<< std::endl;
362  if(spigotStatus>0) ++problemsSpigot[spigot][dccid-690];
363  spigotStatus=-1;
364  }
365 
366  if (!htr.check()) {
367  if(fVerbosity>0) std::cout << "CastorDataIntegrityMonitor:: Invalid HTR data observed on spigot " << spigot << " of DCC with source id " << dccHeader->getSourceId() << std::endl;
368  if(spigotStatus>0) ++problemsSpigot[spigot][dccid-690];
369  spigotStatus=-1;
370  }
371 
372  if (htr.isHistogramEvent()) {
373  if(fVerbosity>0) std::cout << "CastorDataIntegrityMonitor:: Histogram data passed to non-histogram unpacker on spigot " << spigot << " of DCC with source id "
374  << dccHeader->getSourceId() << std::endl;
375  if(spigotStatus>0) ++problemsSpigot[spigot][dccid-690];
376  spigotStatus=-1;
377  }
378 
379  }
380 
381  } //-- end of loop over spigots
382 
383  return;
384 }
int i
Definition: DBlmapReader.cc:9
std::map< int, short > CDFEventType_list
bool check()
Definition: FEDTrailer.cc:66
unsigned int getSlink64ReservedBits() const
Definition: HcalDCCHeader.h:50
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:98
bool check() const
Check for a good event Requires a minimum length, matching wordcount and length, not an empty event...
Definition: HcalHTRData.cc:64
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:717
bool getSpigotCRCError(unsigned int nspigot) const
Read the &quot;CRC-Mismatch&quot; bit for this spigot.
bool moreTrailers()
Definition: FEDTrailer.cc:39
#define NULL
Definition: scimark2.h:8
bool thereIsAThirdCDFHeaderWord() const
Definition: HcalDCCHeader.h:46
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)
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:49
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:40
std::map< int, short >::iterator CDFReservedBits_it
bool getSpigotEnabled(unsigned int nspigot) const
Read the &quot;ENABLED&quot; bit for this spigot.
int getSourceId() const
Definition: HcalDCCHeader.h:34
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:19
std::map< int, short > CDFversionNumber_list
void processEvent(const FEDRawDataCollection &RawData, const HcalUnpackerReport &report, const CastorElectronicsMap &emap)
short BOEshouldBeZeroAlways() const
Definition: HcalDCCHeader.h:52
void setup(const edm::ParameterSet &ps, DQMStore *dbe)
std::map< int, short >::iterator CDFEvT_it
static const int SPIGOT_COUNT
Definition: HcalDCCHeader.h:21
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:29
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:32
TH2F * getTH2F(void) const
MonitorElement * bookInt(const char *name)
Book int.
Definition: DQMStore.cc:624
unsigned short BOEshouldBe5Always() const
Definition: HcalDCCHeader.h:42
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:845
bool thereIsASecondCDFHeaderWord() const
Definition: HcalDCCHeader.h:30
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:429
bool isHistogramEvent() const
Is this event a histogram event? (do not call standard unpack in this case!!!!!)
Definition: HcalHTRData.cc:387