CMS 3D CMS Logo

DCCEventBlock.cc
Go to the documentation of this file.
1 #include "DCCEventBlock.h"
2 #include "DCCDataParser.h"
3 #include "DCCDataMapper.h"
4 #include "DCCTowerBlock.h"
5 #include "ECALParserException.h"
7 #include "DCCSRPBlock.h"
8 #include "DCCTCCBlock.h"
9 #include "DCCXtalBlock.h"
10 #include "DCCTrailerBlock.h"
11 
12 #include <iomanip>
13 #include <sstream>
14 
17  const uint32_t * buffer,
18  uint32_t numbBytes,
19  uint32_t wordsToEnd,
20  uint32_t wordBufferOffset ,
21  uint32_t wordEventOffset
22 ) :
23 DCCTBBlockPrototype(parser,"DCCHEADER", buffer, numbBytes,wordsToEnd)
24 ,dccTrailerBlock_(nullptr),srpBlock_(nullptr),wordBufferOffset_(wordBufferOffset) {
25 
26 
27  //Reset error counters ////
28  errors_["DCC::HEADER"] = 0;
29  errors_["DCC::EVENT LENGTH"] = 0;
31 
32  uint32_t wToEnd(0);
33 
34  try{
35 
36  // Get data fields from the mapper and retrieve data ///
37  if(numbBytes == DCCTBDataParser::EMPTYEVENTSIZE ){
39  emptyEvent = true;
40  }else{
42  emptyEvent = false;
43  }
44 
45  try{ parseData(); }
46  catch (ECALTBParserBlockException &e){/*ignore*/}
48 
49 
50 
51  // Check internal data //////////////
52  if(parser_->debug()){ dataCheck(); }
54 
55 
56  // Check if empty event was produced /////////////////////////////////////////////////////////////////
57 
58  if( !emptyEvent && getDataField("DCC ERRORS")!= DCCERROR_EMPTYEVENT ){
59 
60  // Build the SRP block ////////////////////////////////////////////////////////////////////////////////////
61 
62  bool srp(false);
63  uint32_t sr_ch = getDataField("SR_CHSTATUS");
64  if( sr_ch!=CH_TIMEOUT && sr_ch != CH_DISABLED ){
65 
66  //Go to the begining of the block
67  increment(1," (while trying to create a SR Block !)");
68  wToEnd = numbBytes/4-wordCounter_-1;
69 
70  // Build SRP Block //////////////////////////////////////////////////////////////////////
73 
74  increment((parser_->srpBlockSize())/4-1);
75  if(getDataField("SR")){ srp=true; }
76  }
77 
79 
80 
81  // Build TCC blocks ////////////////////////////////////////////////////////////////////////////////////////
82  for(uint32_t i=1; i<=4;i++){
83  uint32_t tcc_ch=0; uint32_t tccId=0;
84  if( i == 1){ tccId = parser_->tcc1Id();}
85  if( i == 2){ tccId = parser_->tcc2Id();}
86  if( i == 3){ tccId = parser_->tcc3Id();}
87  if( i == 4){ tccId = parser_->tcc4Id();}
88 
89  std::string tcc = std::string("TCC_CHSTATUS#") + parser_->getDecString(i);
90  tcc_ch = getDataField(tcc);
91 
92  if( tcc_ch != CH_TIMEOUT && tcc_ch != CH_DISABLED){
93 
94  //std::cout<<"\n debug:Building TCC Block, channel enabled without errors"<<std::endl;
95 
96  // Go to the begining of the block
97  increment(1," (while trying to create a"+tcc+" Block !)");
98 
99  wToEnd = numbBytes/4-wordCounter_-1;
100  //wToEnd or wordsToEnd ????????????????????????????????????????
101 
102 
103 
104  // Build TCC Block /////////////////////////////////////////////////////////////////////////////////
105  tccBlocks_.push_back( new DCCTBTCCBlock( this, parser_, dataP_,parser_->tccBlockSize(), wToEnd,wordCounter_, tccId));
107 
108  increment((parser_->tccBlockSize())/4-1);
109  }
110  }
112 
113 
114 
115  // Build channel data //////////////////////////////////////////////////////////////////////////////////////////////////////
116  // See number of channels that we need according to the trigger type //
117  // TODO : WHEN IN LOCAL MODE WE SHOULD CHECK RUN TYPE
118  uint32_t triggerType = getDataField("TRIGGER TYPE");
119  uint32_t numbChannels;
120  if( triggerType == PHYSICTRIGGER ) { numbChannels = 68; }
121  else if (triggerType == CALIBRATIONTRIGGER ){ numbChannels = 70; }
122  // TODO :: implement other triggers
123  else{
124  std::string error = std::string("\n DCC::HEADER TRIGGER TYPE = ")+parser_->getDecString(triggerType)+std::string(" is not a valid type !");
126  throw a;
127  }
129 
130 
131 
132 // uint32_t chStatus;
133  uint32_t srFlag;
134  bool suppress(false);
135 
136  for( uint32_t i=1; i<=numbChannels; i++){
137 
138  std::string chStatusId = std::string("FE_CHSTATUS#") + parser_->getDecString(i);
139  uint32_t chStatus = getDataField(chStatusId);
140 
141  // If srp is on, we need to check if channel was suppressed ////////////////////
142  if(srp){
143  srFlag = srpBlock_->getDataField( std::string("SR#") + parser_->getDecString(i));
144  if(srFlag == SR_NREAD){ suppress = true; }
145  else{ suppress = false; }
146  }
148 
149 
150  if( chStatus != CH_TIMEOUT && chStatus != CH_DISABLED && !suppress && chStatus !=CH_SUPPRESS){
151 
152 
153  //Go to the begining of the block ///////////////////////////////////////////////////////////////////////
154  increment(1," (while trying to create a TOWERHEADER Block for channel "+parser_->getDecString(i)+" !)" );
156 
157 
158  // Instantiate a new tower block//////////////////////////////////////////////////////////////////////////
159  wToEnd = numbBytes/4-wordCounter_-1;
161  towerBlocks_.push_back (towerBlock);
162  towerBlock->parseXtalData();
164 
165 
166  //go to the end of the block ///////////////////////////////
167  increment((towerBlock->getDataField("BLOCK LENGTH"))*2 - 1);
169 
170  }
171  }
173 
174 
175  // go to the begining of the block ////////////////////////////////////////////////////////////////////
176  increment(1," (while trying to create a DCC TRAILER Block !)");
177  wToEnd = numbBytes/4-wordCounter_-1;
180 
181  }
182 
183  }catch( ECALTBParserException & e){}
184  catch( ECALTBParserBlockException & e){
185  // uint32_t nEv = (parser_->dccEvents()).size() +1;
186  errorString_ += std::string(e.what());
187  blockError_=true;
188  //std::cout<<"cout"<<e.what();
189  }
190 
191 
192 
193 }
194 
195 
196 
198 
199  std::vector<DCCTBTCCBlock *>::iterator it1;
200  for(it1=tccBlocks_.begin();it1!=tccBlocks_.end();it1++){ delete (*it1);}
201  tccBlocks_.clear();
202 
203  std::vector<DCCTBTowerBlock *>::iterator it2;
204  for(it2=towerBlocks_.begin();it2!=towerBlocks_.end();it2++){ delete (*it2);}
205  towerBlocks_.clear();
206 
207  if(srpBlock_ != nullptr ) { delete srpBlock_; }
208  if(dccTrailerBlock_ != nullptr ) { delete dccTrailerBlock_;}
209 
210 }
211 
212 
213 
215 
216 
217  std::string checkErrors("");
218 
219 
220  // Check BOE field/////////////////////////////////////////////////////
221  std::pair<bool,std::string> res = checkDataField("BOE",BOE);
222  if(!res.first){ checkErrors += res.second; (errors_["DCC::HEADER"])++; }
224 
225 
226  // Check H Field //////////////////////////////////////////////////////
227  std::string hField= std::string("H");
228  res = checkDataField(hField,1);
229  if(!res.first){ checkErrors += res.second; (errors_["DCC::HEADER"])++; }
231 
232 
233  // Check Headers //////////////////////////////////////////////////////////
234  uint32_t dccHeaderWords = 0;
235 
236  if(emptyEvent){ dccHeaderWords = 2;}
237  else if(!emptyEvent){ dccHeaderWords = 7;}
238 
239  for(uint32_t i = 1; i<=dccHeaderWords ; i++){
240 
242  res = checkDataField(header,i);
243  if(!res.first){ checkErrors += res.second; (errors_["DCC::HEADER"])++; }
244  }
246 
247 
248  // Check event length ///////////////////////////////////////////////////////
249  res = checkDataField("EVENT LENGTH",blockSize_/8);
250  if(!res.first){ checkErrors += res.second; (errors_["DCC::EVENT LENGTH"])++; }
252 
253 
254  if(checkErrors!=""){
255  errorString_ +="\n ======================================================================\n";
256  errorString_ += std::string(" ") + name_ + std::string(" data fields checks errors : ") ;
257  errorString_ += checkErrors ;
258  errorString_ += "\n ======================================================================";
259  blockError_ = true;
260  }
261 
262 
263 }
264 
265 
266 
267 void DCCTBEventBlock::displayEvent(std::ostream & os){
268 
269  os << "\n\n\n\n\n >>>>>>>>>>>>>>>>>>>> Event started at word position " << std::dec << wordBufferOffset_ <<" <<<<<<<<<<<<<<<<<<<<"<<std::endl;
270 
271  // Display DCC Header ///
272  displayData(os);
274 
275 
276  // Display SRP Block Contents //////////////
277  if(srpBlock_){ srpBlock_->displayData(os);}
279 
280 
281  // Display TCC Block Contents ///////////////////////////////
282  std::vector<DCCTBTCCBlock *>::iterator it1;
283  for( it1 = tccBlocks_.begin(); it1!= tccBlocks_.end(); it1++){
284  (*it1)->displayData(os);
285  }
286 
287  // Display Towers Blocks /////////////////////////////////////
288  std::vector<DCCTBTowerBlock *>::iterator it2;
289  for(it2 = towerBlocks_.begin();it2!=towerBlocks_.end();it2++){
290 
291  (*it2)->displayData(os);
292 
293  // Display Xtal Data /////////////////////////////////////
294  std::vector<DCCTBXtalBlock * > &xtalBlocks = (*it2)->xtalBlocks();
295  std::vector<DCCTBXtalBlock * >::iterator it3;
296  for(it3 = xtalBlocks.begin();it3!=xtalBlocks.end();it3++){
297  (*it3)->displayData(os);
298  }
299  }
300 
301  // Display Trailer Block Contents /////////////////////////
303 
304 }
305 
306 
307 std::pair<bool,std::string> DCCTBEventBlock::compare(DCCTBEventBlock * block){
308 
309  // DCC Header comparision ///////////////////////////////
310  std::pair<bool,std::string> ret(DCCTBBlockPrototype::compare(block));
312 
313  std::stringstream out;
314 
315  // Selective readout processor block comparision ////////////////////////////////////////////
316  if( srpBlock_ && block->srpBlock() ){
317  std::pair<bool,std::string> temp( srpBlock_->compare(block->srpBlock()));
318  ret.first = ret.first & temp.first;
319  out<<temp.second;
320  }else if( !srpBlock_ && block->srpBlock() ){
321  ret.first = false;
322  out<<"\n ====================================================================="
323  <<"\n ERROR SR block identified in the ORIGINAL BLOCK ... "
324  <<"\n ... but the block is not present in the COMPARISION BLOCK !"
325  <<"\n =====================================================================";
326  }else if( srpBlock_ && !(block->srpBlock()) ){
327  ret.first = false;
328  out<<"\n ====================================================================="
329  <<"\n ERROR SR block identified in the COMPARISION BLOCK ... "
330  <<"\n ... but the block is not present in the ORIGINAL BLOCK !"
331  <<"\n =====================================================================";
332  }
334 
335 
336 
337  // TCC Blocks comparision ////////////////////////////////////////////////////////
338  // check number of TCC blocks
339  int numbTccBlocks_a = tccBlocks_.size();
340  int numbTccBlocks_b = block->tccBlocks().size();
341 
342  if( numbTccBlocks_a != numbTccBlocks_b ){
343  ret.first = false;
344  out<<"\n ====================================================================="
345  <<"\n ERROR number of TCC blocks in the ORIGINAL BLOCK( ="<<numbTccBlocks_a<<" )"
346  <<"\n and in the COMPARISION BLOCK( = "<<numbTccBlocks_b<<" is different !"
347  <<"\n =====================================================================";
348  }
349 
350  std::vector<DCCTBTCCBlock *>::iterator it1Tcc = tccBlocks_.begin();
351  std::vector<DCCTBTCCBlock *>::iterator it1TccEnd = tccBlocks_.end();
352  std::vector<DCCTBTCCBlock *>::iterator it2Tcc = block->tccBlocks().begin();
353  std::vector<DCCTBTCCBlock *>::iterator it2TccEnd = block->tccBlocks().end();
354 
355  for( ; it1Tcc!=it1TccEnd && it2Tcc!=it2TccEnd; it1Tcc++, it2Tcc++){
356  std::pair<bool,std::string> temp( (*it1Tcc)->compare( *it2Tcc ) );
357  ret.first = ret.first & temp.first;
358  out<<temp.second;
359  }
361 
362 
363  // FE Blocks comparision ////////////////////////////////////////////////////////
364  // check number of FE blocks
365  int numbTowerBlocks_a = towerBlocks_.size();
366  int numbTowerBlocks_b = block->towerBlocks().size();
367 
368  if( numbTowerBlocks_a != numbTowerBlocks_b ){
369  ret.first = false;
370  out<<"\n ====================================================================="
371  <<"\n ERROR number of Tower blocks in the ORIGINAL BLOCK( ="<<numbTowerBlocks_a<<" )"
372  <<"\n and in the COMPARISION BLOCK( = "<<numbTowerBlocks_b<<" is different !"
373  <<"\n =====================================================================";
374  }
375 
376  std::vector<DCCTBTowerBlock *>::iterator it1Tower = towerBlocks_.begin();
377  std::vector<DCCTBTowerBlock *>::iterator it1TowerEnd = towerBlocks_.end();
378  std::vector<DCCTBTowerBlock *>::iterator it2Tower = (block->towerBlocks()).begin();
379  std::vector<DCCTBTowerBlock *>::iterator it2TowerEnd = (block->towerBlocks()).end();
380 
381  for( ; it1Tower!=it1TowerEnd && it2Tower!=it2TowerEnd; it1Tower++, it2Tower++){
382 
383  std::pair<bool,std::string> temp( (*it1Tower)->compare( *it2Tower ) );
384  ret.first = ret.first & temp.first;
385  out<<temp.second;
386 
387  // Xtal Block comparision ////////////////////////////
388  std::vector<DCCTBXtalBlock *> xtalBlocks1( (*it1Tower)->xtalBlocks());
389  std::vector<DCCTBXtalBlock *> xtalBlocks2( (*it2Tower)->xtalBlocks());
390  // check number of xtal blocks
391  int numbXtalBlocks_a = xtalBlocks1.size();
392  int numbXtalBlocks_b = xtalBlocks2.size();
393 
394  if( numbXtalBlocks_a != numbXtalBlocks_b ){
395  ret.first = false;
396  out<<"\n ====================================================================="
397  <<"\n ERROR number of Xtal blocks in this TOWER ORIGINAL BLOCK( ="<<numbXtalBlocks_a<<" )"
398  <<"\n and in the TOWER COMPARISION BLOCK( = "<<numbXtalBlocks_b<<" is different !"
399  <<"\n =====================================================================";
400  }
401 
402  std::vector<DCCTBXtalBlock *>::iterator it1Xtal = xtalBlocks1.begin();
403  std::vector<DCCTBXtalBlock *>::iterator it1XtalEnd = xtalBlocks1.end();
404  std::vector<DCCTBXtalBlock *>::iterator it2Xtal = xtalBlocks1.begin();
405  std::vector<DCCTBXtalBlock *>::iterator it2XtalEnd = xtalBlocks2.end();
406 
407  for( ; it1Xtal!=it1XtalEnd && it2Xtal!=it2XtalEnd; it1Xtal++, it2Xtal++){
408  std::pair<bool,std::string> temp( (*it1Xtal)->compare( *it2Xtal ) );
409  ret.first = ret.first & temp.first;
410  out<<temp.second;
411  }
412 
413  }
414 
415 
416  // Trailer block comparision ////////////////////////////////////////////
417  if( block->trailerBlock() && trailerBlock() ){
418  std::pair<bool,std::string> temp( trailerBlock()->compare(block->trailerBlock()));
419  ret.first = ret.first & temp.first;
420  out<<temp.second;
421  }
422 
423  ret.second += out.str();
424 
425  return ret;
426 }
427 
428 
429 
430 
431 
432 
433 
434 
435 
437 
438  bool ret(false);
439  ret = blockError() ;
440 
441 
442  // See if we have errors in the TCC Block Contents ///////////////////////////////
443  std::vector<DCCTBTCCBlock *>::iterator it1;
444  for( it1 = tccBlocks_.begin(); it1!= tccBlocks_.end(); it1++){
445  ret |= (*it1)->blockError();
446  }
448 
449  // See if we have errors in the SRP Block /////////
450  if(srpBlock_){ ret |= srpBlock_->blockError(); }
452 
453 
454  // See if we have errors in the Trigger Blocks ///////////////
455  std::vector<DCCTBTowerBlock *>::iterator it2;
456  for(it2 = towerBlocks_.begin();it2!=towerBlocks_.end();it2++){
457 
458  ret |= (*it2)->blockError();
459 
460  // See if we have errors in the Xtal Data /////////////////
461  std::vector<DCCTBXtalBlock * > & xtalBlocks = (*it2)->xtalBlocks();
462  std::vector<DCCTBXtalBlock * >::iterator it3;
463  for(it3 = xtalBlocks.begin();it3!=xtalBlocks.end();it3++){
464  ret |= (*it3)->blockError();
465  }
467  }
469 
470 
471  // See if we have errors in the trailler ///////////////////
474 
475 
476  return ret;
477 
478 }
479 
480 
482 
483  std::string ret("");
484 
485  if( eventHasErrors() ){
486 
487 
488  ret +="\n ======================================================================\n";
489  ret += std::string(" Event Erros occurred for L1A ( decoded value ) = ") ;
490  ret += parser_->getDecString(getDataField("LV1"));
491  ret += "\n ======================================================================";
492 
493 
494  ret += errorString();
495 
496  // TODO ::
497  // See if we have errors in the TCC Block Contents /////////////
498  std::vector<DCCTBTCCBlock *>::iterator it1;
499  for( it1 = tccBlocks_.begin(); it1!= tccBlocks_.end(); it1++){
500  ret += (*it1)->errorString();
501  }
503  // See if we have errors in the SRP Block ////
504  if(srpBlock_){ ret += srpBlock_->errorString(); }
506 
507 
508  // See if we have errors in the Tower Blocks ///////////////////////////////////////////////////
509  std::vector<DCCTBTowerBlock *>::iterator it2;
510 
511  for(it2 = towerBlocks_.begin();it2!=towerBlocks_.end();it2++){
512 
513  ret += (*it2)->errorString();
514 
515  // See if we have errors in the Xtal Data /////////////////
516  std::vector<DCCTBXtalBlock * > & xtalBlocks = (*it2)->xtalBlocks();
517  std::vector<DCCTBXtalBlock * >::iterator it3;
518 
519 
521  for(it3 = xtalBlocks.begin();it3!=xtalBlocks.end();it3++){ temp += (*it3)->errorString();}
522 
523  if(temp!=""){
524  ret += "\n Fine grain data Errors found ...";
525  ret += "\n( Tower ID = " + parser_->getDecString( (*it2)->getDataField("TT/SC ID"));
526  ret += ", LV1 = " + parser_->getDecString( (*it2)->getDataField("LV1"));
527  ret += ", BX = " + parser_->getDecString( (*it2)->getDataField("BX")) + " )";
528  ret += temp;
529  }
531 
532  }
533 
534 
535  // See if we have errors in the trailler ////////////////////
538 
539  }
540 
541  return ret;
542 
543 }
544 
545 
546 
547 
548 std::vector< DCCTBTowerBlock * > DCCTBEventBlock::towerBlocksById(uint32_t towerId){
549  std::vector<DCCTBTowerBlock *> myVector;
550  std::vector<DCCTBTowerBlock *>::iterator it;
551 
552  for( it = towerBlocks_.begin(); it!= towerBlocks_.end(); it++ ){
553  try{
554 
555  std::pair<bool,std::string> idCheck = (*it)->checkDataField("TT/SC ID",towerId);
556 
557  if(idCheck.first ){ myVector.push_back( (*it) ); }
558  }catch (ECALTBParserBlockException &e){/*ignore*/}
559  }
560 
561  return myVector;
562 }
uint32_t tcc3Id()
virtual std::pair< bool, std::string > checkDataField(std::string name, uint32_t data)
virtual uint32_t getDataField(std::string name)
uint32_t tccBlockSize()
std::set< DCCTBDataField *, DCCTBDataFieldComparator > * mapperFields_
virtual void increment(uint32_t numb, std::string msg="")
const uint32_t * dataP_
virtual void parseData()
std::vector< DCCTBTCCBlock * > tccBlocks_
Definition: DCCEventBlock.h:74
DCCTBDataParser * parser_
unsigned tccId(DetId const &)
std::string getDecString(uint32_t data)
DCCTBSRPBlock * srpBlock()
Definition: DCCEventBlock.h:84
#define nullptr
DCCTBEventBlock(DCCTBDataParser *parser, const uint32_t *buffer, uint32_t numbBytes, uint32_t wordsToEnd, uint32_t wordBufferOffset=0, uint32_t wordEventOffset=0)
Definition: Electron.h:6
void displayEvent(std::ostream &os=std::cout)
~DCCTBEventBlock() override
uint32_t srpBlockSize()
virtual void displayData(std::ostream &os=std::cout)
DCCTBTrailerBlock * trailerBlock()
Definition: DCCEventBlock.h:85
std::vector< DCCTBTCCBlock * > & tccBlocks()
Definition: DCCEventBlock.h:83
#define end
Definition: vmac.h:39
uint32_t tcc2Id()
DCCTBDataMapper * mapper()
std::map< std::string, uint32_t > errors_
unsigned towerId(DetId const &)
std::vector< DCCTBTowerBlock * > & towerBlocks()
Definition: DCCEventBlock.h:82
std::pair< bool, std::string > compare(DCCTBEventBlock *)
std::vector< DCCTBTowerBlock * > towerBlocksById(uint32_t towerId)
uint32_t tcc1Id()
std::vector< DCCTBTowerBlock * > towerBlocks_
Definition: DCCEventBlock.h:73
#define begin
Definition: vmac.h:32
std::string eventErrorString()
double a
Definition: hdecay.h:121
DCCTBTrailerBlock * dccTrailerBlock_
Definition: DCCEventBlock.h:75
DCCTBSRPBlock * srpBlock_
Definition: DCCEventBlock.h:76
virtual std::pair< bool, std::string > compare(DCCTBBlockPrototype *block)
uint32_t tcc4Id()
uint32_t wordBufferOffset_
Definition: DCCEventBlock.h:77
std::set< DCCTBDataField *, DCCTBDataFieldComparator > * emptyEventFields()
std::set< DCCTBDataField *, DCCTBDataFieldComparator > * dccFields()
std::string & errorString()