CMS 3D CMS Logo

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