CMS 3D CMS Logo

DCCEventBlock.cc

Go to the documentation of this file.
00001 #include "DCCEventBlock.h"
00002 #include "DCCBlockPrototype.h"
00003 #include "DCCDataParser.h"
00004 #include "DCCDataMapper.h"
00005 #include "DCCTowerBlock.h"
00006 #include "ECALParserException.h"
00007 #include "ECALParserBlockException.h"
00008 #include "DCCSRPBlock.h"
00009 #include "DCCTCCBlock.h"
00010 #include "DCCXtalBlock.h"
00011 #include "DCCTrailerBlock.h"
00012 
00013 #include <iomanip>
00014 #include <sstream>
00015 
00016 DCCTBEventBlock::DCCTBEventBlock(
00017         DCCTBDataParser * parser, 
00018         ulong * buffer, 
00019         ulong numbBytes, 
00020         ulong wordsToEnd, 
00021         ulong wordBufferOffset , 
00022         ulong wordEventOffset 
00023 ) : 
00024 DCCTBBlockPrototype(parser,"DCCHEADER", buffer, numbBytes,wordsToEnd)
00025 ,dccTrailerBlock_(0),srpBlock_(0),wordBufferOffset_(wordBufferOffset) {
00026         
00027         
00028         //Reset error counters ////
00029         errors_["DCC::HEADER"] = 0;
00030         errors_["DCC::EVENT LENGTH"] = 0;
00032         
00033         ulong wToEnd(0);
00034         
00035         try{ 
00036         
00037                 // Get data fields from the mapper and retrieve data ///        
00038                 if(numbBytes == DCCTBDataParser::EMPTYEVENTSIZE ){
00039                         mapperFields_ = parser_->mapper()->emptyEventFields();
00040                         emptyEvent = true;
00041                 }else{
00042                         mapperFields_ = parser_->mapper()->dccFields(); 
00043                         emptyEvent = false;
00044                 }
00045                 
00046                 try{ parseData(); }
00047                 catch (ECALTBParserBlockException &e){/*ignore*/}
00049                 
00050 
00051         
00052                 // Check internal data //////////////
00053                 if(parser_->debug()){ dataCheck(); }
00055         
00056         
00057                 // Check if empty event was produced /////////////////////////////////////////////////////////////////
00058 
00059                 if( !emptyEvent && getDataField("DCC ERRORS")!= DCCERROR_EMPTYEVENT ){
00060                                         
00061                         // Build the SRP block ////////////////////////////////////////////////////////////////////////////////////
00062                 
00063                         bool srp(false);
00064                         ulong sr_ch = getDataField("SR_CHSTATUS");
00065                         if( sr_ch!=CH_TIMEOUT  && sr_ch != CH_DISABLED ){                       
00066                                 
00067                                 //Go to the begining of the block
00068                                 increment(1," (while trying to create a SR Block !)");
00069                                 wToEnd = numbBytes/4-wordCounter_-1;    
00070                                 
00071                                 // Build SRP Block //////////////////////////////////////////////////////////////////////
00072                                 srpBlock_ = new DCCTBSRPBlock( this, parser_, dataP_, parser_->srpBlockSize(), wToEnd,wordCounter_);
00074                 
00075                                 increment((parser_->srpBlockSize())/4-1);
00076                                 if(getDataField("SR")){ srp=true; }
00077                         }       
00078                         
00080 
00081 
00082                         // Build TCC blocks ////////////////////////////////////////////////////////////////////////////////////////
00083                         for(ulong i=1; i<=4;i++){
00084                           ulong tcc_ch=0;  ulong  tccId=0;
00085                                 if( i == 1){ tccId = parser_->tcc1Id();}
00086                                 if( i == 2){ tccId = parser_->tcc2Id();}
00087                                 if( i == 3){ tccId = parser_->tcc3Id();}        
00088                                 if( i == 4){ tccId = parser_->tcc4Id();}
00089                                 
00090                                 std::string tcc = std::string("TCC_CHSTATUS#") + parser_->getDecString(i);      
00091                                 tcc_ch = getDataField(tcc);
00092                                 
00093                                 if( tcc_ch != CH_TIMEOUT && tcc_ch != CH_DISABLED){      
00094                                         
00095                                         //std::cout<<"\n debug:Building TCC Block, channel enabled without errors"<<std::endl;
00096                                         
00097                                         // Go to the begining of the block
00098                                         increment(1," (while trying to create a"+tcc+" Block !)");
00099                                         
00100                                         wToEnd = numbBytes/4-wordCounter_-1;    
00101                                         //wToEnd or wordsToEnd ????????????????????????????????????????
00102                                         
00103                                 
00104                                         
00105                                         // Build TCC Block /////////////////////////////////////////////////////////////////////////////////
00106                                         tccBlocks_.push_back(  new DCCTBTCCBlock( this, parser_, dataP_,parser_->tccBlockSize(), wToEnd,wordCounter_, tccId));
00108                                         
00109                                         increment((parser_->tccBlockSize())/4-1);
00110                                 }
00111                         }
00113                         
00114                         
00115                         
00116                         // Build channel data //////////////////////////////////////////////////////////////////////////////////////////////////////    
00117                         // See number of channels that we need according to the trigger type //
00118                         // TODO : WHEN IN LOCAL MODE WE SHOULD CHECK RUN TYPE
00119                         ulong triggerType = getDataField("TRIGGER TYPE");                       
00120                         ulong numbChannels;
00121                         if( triggerType == PHYSICTRIGGER )          { numbChannels = 68; }
00122                         else if (triggerType == CALIBRATIONTRIGGER ){ numbChannels = 70; }
00123                         // TODO :: implement other triggers
00124                         else{
00125                           std::string error = std::string("\n DCC::HEADER TRIGGER TYPE = ")+parser_->getDecString(triggerType)+std::string(" is not a valid type !");
00126                                 ECALTBParserBlockException a(error);
00127                                 throw a;
00128                         }
00130                         
00131                         
00132                         
00133 //                      ulong chStatus;
00134                         ulong srFlag;
00135                         bool suppress(false);
00136                         
00137                         for( ulong i=1; i<=numbChannels; i++){
00138                                 
00139                           std::string chStatusId = std::string("FE_CHSTATUS#") + parser_->getDecString(i);
00140                                 ulong chStatus = getDataField(chStatusId);
00141                                 
00142                                 // If srp is on, we need to check if channel was suppressed ////////////////////
00143                                 if(srp){ 
00144                                         srFlag   = srpBlock_->getDataField( std::string("SR#") + parser_->getDecString(i));
00145                                         if(srFlag == SR_NREAD){ suppress = true; }
00146                                         else{ suppress = false; }
00147                                 }
00149                                         
00150                                  
00151                                 if( chStatus != CH_TIMEOUT && chStatus != CH_DISABLED && !suppress && chStatus !=CH_SUPPRESS){
00152 
00153                                         
00154                                         //Go to the begining of the block ///////////////////////////////////////////////////////////////////////
00155                                         increment(1," (while trying to create a TOWERHEADER Block for channel "+parser_->getDecString(i)+" !)" );
00157                                         
00158                                         
00159                                         // Instantiate a new tower block//////////////////////////////////////////////////////////////////////////
00160                                         wToEnd = numbBytes/4-wordCounter_-1;
00161                                         DCCTBTowerBlock * towerBlock = new DCCTBTowerBlock(this,parser_,dataP_,TOWERHEADER_SIZE,wToEnd,wordCounter_,i); 
00162                                         towerBlocks_.push_back (towerBlock);
00163                                         towerBlock->parseXtalData();
00165                                         
00166                                         
00167                                         //go to the end of the block ///////////////////////////////
00168                                         increment((towerBlock->getDataField("BLOCK LENGTH"))*2 - 1);
00170                                                 
00171                                 }
00172                         }
00174                         
00175 
00176                         // go to the begining of the block ////////////////////////////////////////////////////////////////////                 
00177                         increment(1," (while trying to create a DCC TRAILER Block !)");
00178                         wToEnd = numbBytes/4-wordCounter_-1;
00179                         dccTrailerBlock_ = new DCCTBTrailerBlock(parser_,dataP_,TRAILER_SIZE,wToEnd,wordCounter_,blockSize_/8,0);
00181                         
00182                 }
00183         
00184         }catch( ECALTBParserException & e){}
00185         catch( ECALTBParserBlockException & e){
00186           // ulong nEv = (parser_->dccEvents()).size() +1;
00187           errorString_ += std::string(e.what());
00188           blockError_=true;
00189           //std::cout<<"cout"<<e.what();
00190         }
00191         
00192         
00193 
00194 } 
00195 
00196 
00197 
00198 DCCTBEventBlock::~DCCTBEventBlock(){
00199         
00200         std::vector<DCCTBTCCBlock *>::iterator it1;
00201         for(it1=tccBlocks_.begin();it1!=tccBlocks_.end();it1++){ delete (*it1);}
00202         tccBlocks_.clear();
00203         
00204         std::vector<DCCTBTowerBlock *>::iterator it2;
00205         for(it2=towerBlocks_.begin();it2!=towerBlocks_.end();it2++){ delete (*it2);}
00206         towerBlocks_.clear();
00207         
00208         if(srpBlock_ !=        0 ) { delete srpBlock_;       }
00209         if(dccTrailerBlock_ != 0 ) { delete dccTrailerBlock_;}
00210         
00211 }
00212 
00213 
00214 
00215 void DCCTBEventBlock::dataCheck(){
00216         
00217         
00218         std::string checkErrors("");
00219         
00220         
00221         // Check BOE field/////////////////////////////////////////////////////
00222         std::pair<bool,std::string> res =  checkDataField("BOE",BOE);
00223         if(!res.first){ checkErrors += res.second; (errors_["DCC::HEADER"])++; }
00225         
00226         
00227         // Check H Field //////////////////////////////////////////////////////
00228         std::string hField= std::string("H");
00229         res = checkDataField(hField,1);
00230         if(!res.first){ checkErrors += res.second; (errors_["DCC::HEADER"])++; }
00232         
00233         
00234         // Check Headers //////////////////////////////////////////////////////////
00235         ulong dccHeaderWords;
00236         
00237         if(emptyEvent){ dccHeaderWords = 2;}
00238         else if(!emptyEvent){ dccHeaderWords = 7;}
00239 
00240         for(ulong i = 1; i<=dccHeaderWords ; i++){
00241 
00242                 std::string header= std::string("H") + parser_->getDecString(i);
00243                 res = checkDataField(header,i);
00244                 if(!res.first){ checkErrors += res.second; (errors_["DCC::HEADER"])++; }
00245         }
00247         
00248         
00249         // Check event length ///////////////////////////////////////////////////////
00250         res = checkDataField("EVENT LENGTH",blockSize_/8);
00251         if(!res.first){ checkErrors += res.second; (errors_["DCC::EVENT LENGTH"])++; }
00253                 
00254         
00255         if(checkErrors!=""){
00256                 errorString_ +="\n ======================================================================\n";           
00257                 errorString_ += std::string(" ") + name_ + std::string(" data fields checks errors : ") ;
00258                 errorString_ += checkErrors ;
00259                 errorString_ += "\n ======================================================================";
00260                 blockError_ = true;     
00261         }
00262         
00263         
00264 }
00265 
00266 
00267 
00268 void  DCCTBEventBlock::displayEvent(std::ostream & os){
00269 
00270   os << "\n\n\n\n\n >>>>>>>>>>>>>>>>>>>> Event started at word position " << std::dec << wordBufferOffset_ <<" <<<<<<<<<<<<<<<<<<<<"<<std::endl;
00271         
00272         // Display DCC Header ///
00273         displayData(os);
00275                 
00276                 
00277         // Display SRP Block Contents //////////////
00278         if(srpBlock_){ srpBlock_->displayData(os);}
00280                 
00281                 
00282         // Display TCC Block Contents ///////////////////////////////
00283         std::vector<DCCTBTCCBlock *>::iterator it1;
00284         for( it1 = tccBlocks_.begin(); it1!= tccBlocks_.end(); it1++){
00285                 (*it1)->displayData(os);
00286         }
00287         
00288         // Display Towers Blocks /////////////////////////////////////
00289         std::vector<DCCTBTowerBlock *>::iterator it2;
00290         for(it2 = towerBlocks_.begin();it2!=towerBlocks_.end();it2++){
00291                         
00292                 (*it2)->displayData(os);
00293                         
00294                 // Display Xtal Data /////////////////////////////////////
00295                 std::vector<DCCTBXtalBlock * > &xtalBlocks = (*it2)->xtalBlocks();
00296                 std::vector<DCCTBXtalBlock * >::iterator it3;
00297                 for(it3 = xtalBlocks.begin();it3!=xtalBlocks.end();it3++){
00298                         (*it3)->displayData(os);
00299                 }       
00300         }
00301                 
00302         // Display Trailer Block Contents /////////////////////////
00303         if(dccTrailerBlock_){ dccTrailerBlock_->displayData(os);}
00304                 
00305 }
00306 
00307 
00308 std::pair<bool,std::string> DCCTBEventBlock::compare(DCCTBEventBlock * block){
00309         
00310         // DCC Header comparision /////////////////////////////// 
00311         std::pair<bool,std::string> ret(DCCTBBlockPrototype::compare(block));
00313         
00314           std::stringstream out;
00315         
00316         // Selective readout processor block comparision ////////////////////////////////////////////
00317         if( srpBlock_ && block->srpBlock() ){ 
00318                 std::pair<bool,std::string> temp( srpBlock_->compare(block->srpBlock()));
00319                 ret.first   = ret.first & temp.first;
00320                 out<<temp.second; 
00321         }else if( !srpBlock_ && block->srpBlock() ){
00322                 ret.first   = false;    
00323                 out<<"\n ====================================================================="
00324                    <<"\n ERROR SR block identified in the ORIGINAL BLOCK ... "
00325                    <<"\n ... but the block is not present in the COMPARISION BLOCK !" 
00326                    <<"\n =====================================================================";
00327         }else if( srpBlock_ && !(block->srpBlock()) ){
00328                 ret.first   = false;    
00329                 out<<"\n ====================================================================="
00330                    <<"\n ERROR SR block identified in the COMPARISION BLOCK ... "
00331                    <<"\n ... but the block is not present in the ORIGINAL BLOCK !" 
00332                    <<"\n =====================================================================";
00333         }
00335         
00336         
00337         
00338         // TCC Blocks comparision ////////////////////////////////////////////////////////
00339         // check number of TCC blocks 
00340         int numbTccBlocks_a = tccBlocks_.size();
00341         int numbTccBlocks_b = block->tccBlocks().size();
00342         
00343         if( numbTccBlocks_a != numbTccBlocks_b ){
00344                 ret.first = false;
00345                 out<<"\n ====================================================================="
00346                    <<"\n ERROR number of TCC blocks in the ORIGINAL BLOCK( ="<<numbTccBlocks_a<<" )"
00347                    <<"\n and in the COMPARISION BLOCK( = "<<numbTccBlocks_b<<" is different !"
00348                    <<"\n =====================================================================";
00349         }
00350         
00351         std::vector<DCCTBTCCBlock *>::iterator it1Tcc    = tccBlocks_.begin();
00352         std::vector<DCCTBTCCBlock *>::iterator it1TccEnd = tccBlocks_.end();
00353         std::vector<DCCTBTCCBlock *>::iterator it2Tcc    = block->tccBlocks().begin();
00354         std::vector<DCCTBTCCBlock *>::iterator it2TccEnd = block->tccBlocks().end();
00355         
00356         for( ; it1Tcc!=it1TccEnd && it2Tcc!=it2TccEnd; it1Tcc++, it2Tcc++){
00357                 std::pair<bool,std::string> temp( (*it1Tcc)->compare( *it2Tcc ) );
00358                 ret.first   = ret.first & temp.first;
00359                 out<<temp.second; 
00360         }
00362         
00363         
00364         // FE Blocks comparision ////////////////////////////////////////////////////////
00365         // check number of FE blocks 
00366         int numbTowerBlocks_a = towerBlocks_.size();
00367         int numbTowerBlocks_b = block->towerBlocks().size();
00368         
00369         if( numbTowerBlocks_a != numbTowerBlocks_b ){
00370                 ret.first = false;
00371                 out<<"\n ====================================================================="
00372                    <<"\n ERROR number of Tower blocks in the ORIGINAL BLOCK( ="<<numbTowerBlocks_a<<" )"
00373                    <<"\n and in the COMPARISION BLOCK( = "<<numbTowerBlocks_b<<" is different !"
00374                    <<"\n =====================================================================";
00375         }
00376         
00377         std::vector<DCCTBTowerBlock *>::iterator it1Tower    = towerBlocks_.begin();
00378         std::vector<DCCTBTowerBlock *>::iterator it1TowerEnd  = towerBlocks_.end();
00379         std::vector<DCCTBTowerBlock *>::iterator it2Tower    = (block->towerBlocks()).begin();
00380         std::vector<DCCTBTowerBlock *>::iterator it2TowerEnd = (block->towerBlocks()).end();
00381         
00382         for( ; it1Tower!=it1TowerEnd && it2Tower!=it2TowerEnd; it1Tower++, it2Tower++){
00383                 
00384                 std::pair<bool,std::string> temp( (*it1Tower)->compare( *it2Tower ) );
00385                 ret.first   = ret.first & temp.first;
00386                 out<<temp.second;
00387 
00388                 // Xtal Block comparision ////////////////////////////
00389                 std::vector<DCCTBXtalBlock *> xtalBlocks1( (*it1Tower)->xtalBlocks());
00390                 std::vector<DCCTBXtalBlock *> xtalBlocks2( (*it2Tower)->xtalBlocks());
00391                 // check number of xtal blocks 
00392         int numbXtalBlocks_a = xtalBlocks1.size();
00393                 int numbXtalBlocks_b = xtalBlocks2.size();
00394         
00395                 if( numbXtalBlocks_a != numbXtalBlocks_b ){
00396                         ret.first = false;
00397                         out<<"\n ====================================================================="
00398                            <<"\n ERROR number of Xtal blocks in this TOWER ORIGINAL BLOCK( ="<<numbXtalBlocks_a<<" )"
00399                            <<"\n and in the TOWER COMPARISION BLOCK( = "<<numbXtalBlocks_b<<" is different !"
00400                            <<"\n =====================================================================";
00401                 }
00402                 
00403                 std::vector<DCCTBXtalBlock *>::iterator it1Xtal    = xtalBlocks1.begin();
00404                 std::vector<DCCTBXtalBlock *>::iterator it1XtalEnd = xtalBlocks1.end();
00405                 std::vector<DCCTBXtalBlock *>::iterator it2Xtal    = xtalBlocks1.begin();
00406                 std::vector<DCCTBXtalBlock *>::iterator it2XtalEnd = xtalBlocks2.end();
00407                 
00408                 for( ; it1Xtal!=it1XtalEnd && it2Xtal!=it2XtalEnd; it1Xtal++, it2Xtal++){
00409                         std::pair<bool,std::string> temp( (*it1Xtal)->compare( *it2Xtal ) );
00410                         ret.first   = ret.first & temp.first;
00411                         out<<temp.second; 
00412                 }
00413                 
00414         }
00415         
00416         
00417         // Trailer block comparision ////////////////////////////////////////////
00418         if(  block->trailerBlock() && trailerBlock() ){ 
00419                 std::pair<bool,std::string> temp( trailerBlock()->compare(block->trailerBlock()));
00420                 ret.first   = ret.first & temp.first;
00421                 out<<temp.second; 
00422         }
00423         
00424         ret.second += out.str(); 
00425 
00426         return ret;
00427 }
00428                         
00429                 
00430                 
00431                 
00432                 
00433                 
00434                 
00435                 
00436 
00437 bool DCCTBEventBlock::eventHasErrors(){
00438         
00439         bool ret(false);
00440         ret = blockError() ;
00441         
00442 
00443         // See if we have errors in the  TCC Block Contents ///////////////////////////////
00444         std::vector<DCCTBTCCBlock *>::iterator it1;
00445         for( it1 = tccBlocks_.begin(); it1!= tccBlocks_.end(); it1++){
00446                 ret |= (*it1)->blockError();
00447         }
00449 
00450         // See if we have errors in the SRP Block /////////
00451         if(srpBlock_){  ret |= srpBlock_->blockError(); }
00453 
00454         
00455         // See if we have errors in the Trigger Blocks ///////////////
00456         std::vector<DCCTBTowerBlock *>::iterator it2;
00457         for(it2 = towerBlocks_.begin();it2!=towerBlocks_.end();it2++){
00458                         
00459                 ret |= (*it2)->blockError();
00460                         
00461                 // See if we have errors in the Xtal Data /////////////////
00462                 std::vector<DCCTBXtalBlock * > & xtalBlocks = (*it2)->xtalBlocks();
00463                 std::vector<DCCTBXtalBlock * >::iterator it3;
00464                 for(it3 = xtalBlocks.begin();it3!=xtalBlocks.end();it3++){
00465                         ret |= (*it3)->blockError();
00466                 }
00468         }
00470         
00471                 
00472         // See if we have errors in the  trailler ///////////////////
00473         if(dccTrailerBlock_){ ret |= dccTrailerBlock_->blockError();}
00475         
00476         
00477         return ret;
00478         
00479 }
00480 
00481 
00482 std::string DCCTBEventBlock::eventErrorString(){
00483         
00484         std::string ret("");
00485         
00486         if( eventHasErrors() ){
00487                 
00488                 
00489                 ret +="\n ======================================================================\n";            
00490                 ret += std::string(" Event Erros occurred for L1A ( decoded value ) = ") ; 
00491                 ret += parser_->getDecString(getDataField("LV1"));
00492                 ret += "\n ======================================================================";
00493                 
00494         
00495                 ret += errorString();
00496         
00497                 // TODO ::
00498                 // See if we have errors in the  TCC Block Contents /////////////
00499                 std::vector<DCCTBTCCBlock *>::iterator it1;
00500                 for( it1 = tccBlocks_.begin(); it1!= tccBlocks_.end(); it1++){
00501                         ret += (*it1)->errorString();
00502                 }
00504                 // See if we have errors in the SRP Block ////
00505                  if(srpBlock_){  ret += srpBlock_->errorString(); }
00507         
00508         
00509                 // See if we have errors in the Tower Blocks ///////////////////////////////////////////////////
00510                 std::vector<DCCTBTowerBlock *>::iterator it2;
00511                 
00512                 for(it2 = towerBlocks_.begin();it2!=towerBlocks_.end();it2++){
00513                         
00514                         ret += (*it2)->errorString();
00515                         
00516                         // See if we have errors in the Xtal Data /////////////////
00517                         std::vector<DCCTBXtalBlock * > & xtalBlocks = (*it2)->xtalBlocks();
00518                         std::vector<DCCTBXtalBlock * >::iterator it3;
00519                 
00520                 
00521                         std::string temp;
00522                         for(it3 = xtalBlocks.begin();it3!=xtalBlocks.end();it3++){ temp += (*it3)->errorString();}
00523                 
00524                         if(temp!=""){
00525                                 ret += "\n Fine grain data Errors found ...";
00526                                 ret += "\n(  Tower ID = " + parser_->getDecString( (*it2)->getDataField("TT/SC ID"));
00527                                 ret += ", LV1 = " + parser_->getDecString( (*it2)->getDataField("LV1"));
00528                                 ret += ", BX = " + parser_->getDecString( (*it2)->getDataField("BX")) + " )";
00529                                 ret += temp;
00530                         }
00532                         
00533                 }
00534         
00535                 
00536                 // See if we have errors in the  trailler ////////////////////
00537                 if(dccTrailerBlock_){ ret += dccTrailerBlock_->errorString();}
00539         
00540         }
00541         
00542         return ret;
00543         
00544 }
00545 
00546 
00547 
00548 
00549 std::vector< DCCTBTowerBlock * > DCCTBEventBlock::towerBlocksById(ulong towerId){
00550         std::vector<DCCTBTowerBlock *> myVector;        
00551         std::vector<DCCTBTowerBlock *>::iterator it;
00552         
00553         for( it = towerBlocks_.begin(); it!= towerBlocks_.end(); it++ ){
00554                 try{
00555                         
00556                         std::pair<bool,std::string> idCheck   = (*it)->checkDataField("TT/SC ID",towerId);
00557                         
00558                         if(idCheck.first ){ myVector.push_back( (*it) ); }
00559                 }catch (ECALTBParserBlockException &e){/*ignore*/}
00560         }
00561         
00562         return myVector;
00563 }

Generated on Tue Jun 9 17:34:37 2009 for CMSSW by  doxygen 1.5.4