CMS 3D CMS Logo

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

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