CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/EventFilter/EcalTBRawToDigi/src/DCCTowerBlock.cc

Go to the documentation of this file.
00001 #include "DCCTowerBlock.h"
00002 #include "DCCEventBlock.h"
00003 #include "DCCDataParser.h"
00004 #include "DCCXtalBlock.h"
00005 #include "DCCDataMapper.h"
00006 #include "ECALParserBlockException.h"
00007 #include <stdio.h>
00008 
00009 
00010 
00011 DCCTBTowerBlock::DCCTBTowerBlock(
00012         DCCTBEventBlock * dccBlock, 
00013         DCCTBDataParser * parser, 
00014         uint32_t * buffer, 
00015         uint32_t numbBytes,
00016         uint32_t wordsToEnd,
00017         uint32_t wordEventOffset,
00018         uint32_t expectedTowerID
00019 )
00020 : DCCTBBlockPrototype(parser,"TOWERHEADER", buffer, numbBytes,wordsToEnd, wordEventOffset ) 
00021  , dccBlock_(dccBlock), expectedTowerID_(expectedTowerID)
00022 {
00023         
00024         //Reset error counters ///////////
00025         errors_["FE::HEADER"]        = 0;
00026         errors_["FE::TT/SC ID"]      = 0; 
00027         errors_["FE::BLOCK LENGTH"]  = 0;
00029 
00030         
00031         
00032         // Get data fields from the mapper and retrieve data /////////////////////////////////////
00033         mapperFields_ = parser_->mapper()->towerFields();       
00034         parseData();
00036  }
00037  
00038  
00039  void DCCTBTowerBlock::parseXtalData(){
00040         
00041         uint32_t numbBytes = blockSize_;
00042         uint32_t wordsToEnd =wordsToEndOfEvent_;
00043         
00044         // See if we can construct the correct number of XTAL Blocks////////////////////////////////////////////////////////////////////////////////
00045         uint32_t numbDWInXtalBlock = ( parser_->numbXtalSamples() )/4 + 1;
00046         uint32_t length            = getDataField("BLOCK LENGTH");
00047         uint32_t numbOfXtalBlocks  = 0 ;
00048         
00049         if( length > 0 ){ numbOfXtalBlocks = (length-1)/numbDWInXtalBlock; }
00050         uint32_t xtalBlockSize     =  numbDWInXtalBlock*8;
00051         //uint32_t pIncrease         =  numbDWInXtalBlock*2;
00052         
00053         //std::cout<<"\n DEBUG::numbDWInXtal Block "<<dec<<numbDWInXtalBlock<<std::endl;
00054         //std::cout<<"\n DEBUG::length             "<<length<<std::endl;
00055         //std::cout<<"\n DEBUG::xtalBlockSize      "<<xtalBlockSize<<std::endl;
00056         //std::cout<<"\n DEBUG::pIncreade          "<<pIncrease<<std::endl;
00057 
00058         
00059         
00060         bool zs = dccBlock_->getDataField("ZS");
00061         if( !zs && numbOfXtalBlocks != 25 ){
00062         
00063            
00064                 (errors_["FE::BLOCK LENGTH"])++;
00065                 errorString_ += "\n ======================================================================\n";          
00066                 errorString_ += std::string(" ") + name_ + std::string(" ZS is not active, error in the Tower Length !") ;
00067                 errorString_ += "\n Tower Length is : " + (parser_->getDecString(numbBytes/8))+std::string(" , while it should be : ");
00068                 std::string myString = parser_->getDecString((uint32_t)(25*numbDWInXtalBlock+1));
00069                 errorString_ += "\n It was only possible to build : " + parser_->getDecString( numbOfXtalBlocks)+ std::string(" XTAL blocks");
00070                 errorString_ += "\n ======================================================================";
00071                 blockError_ = true;
00072         };
00073         if( numbOfXtalBlocks > 25 ){
00074                 if (errors_["FE::BLOCK LENGTH"]==0)(errors_["FE::BLOCK LENGTH"])++;
00075                 errorString_ += "\n ======================================================================\n";          
00076                 errorString_ += std::string(" ") + name_ + std::string(" Tower Length is larger then expected...!") ;
00077                 errorString_ += "\n Tower Length is : " + parser_->getDecString(numbBytes/8)+std::string(" , while it should be at maximum : ");
00078                 std::string myString = parser_->getDecString((uint32_t)(25*numbDWInXtalBlock+1));
00079                 errorString_ += "\n Action -> data after the xtal 25 is ignored... "; 
00080                 errorString_ += "\n ======================================================================";
00081                 blockError_ = true;
00082                 
00083         }
00085         
00086         blockSize_     += length*8;  //??????????????????????
00087         
00088         // Get XTAL Data //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
00089         uint32_t stripID, xtalID;
00090         
00091         
00092         for(uint32_t numbXtal=1; numbXtal <= numbOfXtalBlocks && numbXtal <=25 ; numbXtal++){
00093         
00094                 increment(1);
00095                 
00096                 stripID =( numbXtal-1)/5 + 1;   
00097                 xtalID  = numbXtal - (stripID-1)*5;
00098                 
00099                 
00100                 if(!zs){        
00101                         xtalBlocks_.push_back(  new DCCTBXtalBlock( parser_, dataP_, xtalBlockSize, wordsToEnd-wordCounter_,wordCounter_+wordEventOffset_,xtalID, stripID) );
00102                 }else{
00103                         xtalBlocks_.push_back(  new DCCTBXtalBlock( parser_, dataP_, xtalBlockSize, wordsToEnd-wordCounter_,wordCounter_+wordEventOffset_,0,0));
00104                 }
00105                 
00106                 increment(xtalBlockSize/4-1);
00107         }
00109 
00110                 
00111         // Check internal data ////////////
00112         if(parser_->debug()){ dataCheck();};
00114 }
00115 
00116 
00117 
00118 DCCTBTowerBlock::~DCCTBTowerBlock(){
00119         std::vector<DCCTBXtalBlock *>::iterator it;
00120         for(it=xtalBlocks_.begin();it!=xtalBlocks_.end();it++){ delete (*it);}
00121         xtalBlocks_.clear();
00122 }
00123 
00124 
00125 
00126 void DCCTBTowerBlock::dataCheck(){
00127         std::string checkErrors("");    
00128         
00129         
00130         std::pair <bool,std::string> res;
00131         
00133         // For TB we don-t check Bx 
00134         //res = checkDataField("BX", BXMASK & (dccBlock_->getDataField("BX")));
00135         //if(!res.first){ checkErrors += res.second; (errors_["FE::HEADER"])++; }
00137         
00138         // mod to account for ECAL counters starting from 0 in the front end N. Almeida
00139         res = checkDataField("LV1", L1MASK &  (dccBlock_->getDataField("LV1")  -1)   ); 
00140         if(!res.first){ checkErrors += res.second; (errors_["FE::HEADER"])++; }
00141         
00142         
00143         if(expectedTowerID_ != 0){ 
00144                 res = checkDataField("TT/SC ID",expectedTowerID_); 
00145                 if(!res.first){ checkErrors += res.second; (errors_["FE::HEADER"])++; } 
00146         }
00147         
00148         if( checkErrors !="" ){
00149                 std::string myTowerId;
00150                 
00151                 errorString_ +="\n ======================================================================\n"; 
00152                 errorString_ += std::string(" ") + name_ + std::string("( ID = ")+parser_->getDecString((uint32_t)(expectedTowerID_))+std::string(" ) errors : ") ;
00153                 errorString_ += checkErrors ;
00154                 errorString_ += "\n ======================================================================";
00155                 blockError_ = true;     
00156         }
00157 } 
00158 
00159 
00160 std::vector< DCCTBXtalBlock * > DCCTBTowerBlock::xtalBlocksById(uint32_t stripId, uint32_t xtalId){
00161         std::vector<DCCTBXtalBlock *> myVector; 
00162         std::vector<DCCTBXtalBlock *>::iterator it;
00163         
00164         for( it = xtalBlocks_.begin(); it!= xtalBlocks_.end(); it++ ){
00165                 try{
00166                         
00167                   std::pair<bool,std::string> stripIdCheck   = (*it)->checkDataField("STRIP ID",stripId);
00168                   std::pair<bool,std::string> xtalIdCheck    = (*it)->checkDataField("XTAL ID",xtalId);
00169                         
00170                         if(xtalIdCheck.first && stripIdCheck.first ){ myVector.push_back( (*it) ); }
00171                         
00172                 }catch (ECALTBParserBlockException &e){/*ignore*/ }
00173         }
00174         
00175         return myVector;
00176 }
00177 
00178 int DCCTBTowerBlock::towerID() {
00179   int result=-1;
00180 
00181   for(std::set<DCCTBDataField *,DCCTBDataFieldComparator>::iterator it = mapperFields_->begin(); it!= mapperFields_->end(); it++){
00182     if ( (*it)->name() == "TT/SC ID" ) 
00183       result=getDataField( (*it)->name() )  ;
00184     
00185   }
00186   
00187   return result;
00188 
00189 }