CMS 3D CMS Logo

DCCEventBlock.cc

Go to the documentation of this file.
00001 #include "EventFilter/EcalRawToDigiDev/interface/DCCEventBlock.h"
00002 #include "EventFilter/EcalRawToDigiDev/interface/DCCDataUnpacker.h"
00003 #include "EventFilter/EcalRawToDigiDev/interface/EcalDCCHeaderRuntypeDecoder.h"
00004 #include "EventFilter/EcalRawToDigiDev/interface/EcalElectronicsMapper.h"
00005 #include "EventFilter/EcalRawToDigiDev/interface/DCCFEBlock.h"
00006 #include "EventFilter/EcalRawToDigiDev/interface/DCCMemBlock.h"
00007 #include "EventFilter/EcalRawToDigiDev/interface/DCCTCCBlock.h"
00008 #include "EventFilter/EcalRawToDigiDev/interface/DCCSRPBlock.h"
00009 #include <sys/time.h>
00010 
00011 #include <iomanip>
00012 #include <sstream>
00013 
00014 DCCEventBlock::DCCEventBlock( DCCDataUnpacker * u , EcalElectronicsMapper * m ,  bool hU, bool srpU, bool tccU, bool feU, bool memU) : 
00015   unpacker_(u), mapper_(m), headerUnpacking_(hU), srpUnpacking_(srpU), tccUnpacking_(tccU), feUnpacking_(feU),memUnpacking_(memU)
00016 {
00017   
00018   // Build a Mem Unpacker Block
00019   memBlock_   = new DCCMemBlock(u,m,this);
00020  
00021   // setup and initialize ch status vectors
00022   for( int feChannel=1;  feChannel <= 70;  feChannel++) { feChStatus_.push_back(0);}
00023   for( int tccChannel=1; tccChannel <= 4 ; tccChannel++){ tccChStatus_.push_back(0);}
00024   
00025 }
00026 
00027 
00028 
00029 void DCCEventBlock::enableSyncChecks(){
00030    towerBlock_   ->enableSyncChecks();
00031    tccBlock_     ->enableSyncChecks();
00032    memBlock_     ->enableSyncChecks();
00033    srpBlock_     ->enableSyncChecks();
00034 }
00035 
00036 
00037 
00038 void DCCEventBlock::enableFeIdChecks(){
00039    towerBlock_   ->enableFeIdChecks();
00040 }
00041 
00042 
00043 
00044 void DCCEventBlock::updateCollectors(){
00045 
00046   dccHeaders_  = unpacker_->dccHeadersCollection();
00047 
00048   memBlock_    ->updateCollectors(); 
00049   tccBlock_    ->updateCollectors();
00050   srpBlock_    ->updateCollectors();
00051   towerBlock_  ->updateCollectors();
00052   
00053 }
00054 
00055 
00056 void DCCEventBlock::unpack( uint64_t * buffer, uint numbBytes, uint expFedId){
00057   
00058   eventSize_ = numbBytes;       
00059   data_      = buffer;
00060   
00061   // First Header Word of fed block
00062   fedId_             = ((*data_)>>H_FEDID_B)   & H_FEDID_MASK;
00063   bx_                = ((*data_)>>H_BX_B   )   & H_BX_MASK;
00064   l1_                = ((*data_)>>H_L1_B   )   & H_L1_MASK;
00065   triggerType_       = ((*data_)>>H_TTYPE_B)   & H_TTYPE_MASK;
00066   
00067   // Check if fed id is the same as expected...
00068   if( fedId_ != expFedId  ){ 
00069 
00070   if( ! DCCDataUnpacker::silentMode_ ){  
00071     edm::LogWarning("EcalRawToDigiDev")
00072       <<"\n For event L1A: "<<l1_
00073       <<"\n Expected FED id is: "<<expFedId<<" while current FED id is: "<<fedId_
00074       <<"\n => Skipping to next fed block...";
00075     }
00076   
00077   //TODO : add this to an error event collection
00078   
00079   return;
00080   } 
00081   
00082   // Check if this event is an empty event 
00083   if( eventSize_ == EMPTYEVENTSIZE ){ 
00084     if( ! DCCDataUnpacker::silentMode_ ){
00085       edm::LogWarning("EcalRawToDigiDev")
00086         <<"\n Event L1A: "<<l1_<<" is empty for fed: "<<fedId_
00087         <<"\n => Skipping to next fed block...";
00088     }
00089     return;
00090     
00091   } 
00092   
00093   //Check if event size allows at least building the header
00094   else if( eventSize_ < HEADERSIZE ){    
00095     if( ! DCCDataUnpacker::silentMode_ ){
00096       edm::LogError("EcalRawToDigiDev")
00097         <<"\n Event L1A: "<<l1_<<" in fed: "<< fedId_
00098         <<"\n Event size is "<<eventSize_<<" bytes while the minimum is "<<HEADERSIZE<<" bytes"
00099         <<"\n => Skipping to next fed block..."; 
00100      }
00101     
00102     //TODO : add this to a dcc size error collection  
00103     
00104     return;
00105     
00106   }
00107   
00108   //Second Header Word of fed block
00109   data_++;
00110   
00111   blockLength_   =   (*data_ )                 & H_EVLENGTH_MASK;
00112   dccErrors_     =   ((*data_)>>H_ERRORS_B)    & H_ERRORS_MASK;
00113   runNumber_     =   ((*data_)>>H_RNUMB_B )    & H_RNUMB_MASK;
00114   
00115   
00116   if( eventSize_ != blockLength_*8 ){
00117     if( ! DCCDataUnpacker::silentMode_ ){
00118       edm::LogError("EcalRawToDigiDev")
00119         <<"\n Event L1A: "<<l1_<<" in fed: "<< fedId_
00120         <<"\n size is "<<eventSize_<<" bytes while "<<(blockLength_*8)<<" are set in the event header "
00121         <<"\n => Skipping to next fed block..."; 
00122       //TODO : add this to a dcc size error collection 
00123      }
00124     return;
00125     
00126   }  
00127   
00128   //Third Header Word  of fed block
00129   data_++;
00130 
00131   // bits 0.. 31 of the 3rd DCC header word
00132   runType_              = (*data_) & H_RTYPE_MASK;
00133 
00134   // bits 32.. 47 of the 3rd DCC header word
00135   detailedTriggerType_ = ((*data_) >> H_DET_TTYPE_B) & H_DET_TTYPE_MASK;
00136 
00137   //Forth Header Word
00138   data_++;
00139   orbitCounter_        = ((*data_)>>H_ORBITCOUNTER_B)  & H_ORBITCOUNTER_MASK;
00140   sr_                  = ((*data_)>>H_SR_B)            & B_MASK;
00141   zs_                  = ((*data_)>>H_ZS_B)            & B_MASK;
00142   tzs_                 = ((*data_)>>H_TZS_B)           & B_MASK;
00143   srChStatus_          = ((*data_)>>H_SRCHSTATUS_B)    & H_CHSTATUS_MASK;
00144   
00145   // getting TCC channel status bits
00146   tccChStatus_[0] = ((*data_)>>H_TCC1CHSTATUS_B)   & H_CHSTATUS_MASK; 
00147   tccChStatus_[1] = ((*data_)>>H_TCC2CHSTATUS_B)   & H_CHSTATUS_MASK;
00148   tccChStatus_[2] = ((*data_)>>H_TCC3CHSTATUS_B)   & H_CHSTATUS_MASK;
00149   tccChStatus_[3] = ((*data_)>>H_TCC4CHSTATUS_B)   & H_CHSTATUS_MASK;
00150     
00151   // FE  channel Status data
00152   int channel(0);
00153   for( int dw = 0; dw<5; dw++ ){
00154     data_++;
00155     for( int i = 0; i<14; i++, channel++){
00156       uint shift = i*4; //each channel has 4 bits
00157       feChStatus_[channel] = ( (*data_)>>shift ) &  H_CHSTATUS_MASK ;
00158     }
00159   }
00160    
00161   // debugging
00162   //display(cout);
00163   
00164   if(headerUnpacking_) addHeaderToCollection();
00165   
00166   // pointer for the 
00167   std::vector<short>::iterator it;
00168   
00169   // Update number of available dwords
00170   dwToEnd_ = blockLength_ - HEADERLENGTH ;
00171    
00172   int STATUS = unpackTCCBlocks();
00173 
00174   if(  STATUS != STOP_EVENT_UNPACKING && feUnpacking_ || srpUnpacking_ ){
00175     
00176     //NMGA note : SR comes before TCC blocks 
00177     // Emmanuelle please change this in the digi to raw
00178   
00179     // Unpack SRP block
00180     if(srChStatus_ != CH_TIMEOUT &&  srChStatus_ != CH_DISABLED){
00181       STATUS = srpBlock_->unpack(&data_,&dwToEnd_);
00182     }
00183   }
00184 
00185   // See number of FE channels that we need according to the trigger type //
00186   // TODO : WHEN IN LOCAL MODE WE SHOULD CHECK RUN TYPE                 
00187   uint numbChannels(0);
00188   
00189   if(       triggerType_ == PHYSICTRIGGER      ){ numbChannels = 68; }
00190   else if ( triggerType_ == CALIBRATIONTRIGGER ){ numbChannels = 70; }
00191   else {
00192     if( ! DCCDataUnpacker::silentMode_ ){
00193       edm::LogError("EcalRawToDigiDev")
00194         <<"\n Event L1A: "<<l1_<<" in fed: "<< fedId_
00195         <<"\n Event has an unsupported trigger type "<<triggerType_
00196         <<"\n => Skipping to next fed block..."; 
00197       //TODO : add this to a dcc trigger type error collection 
00198     }
00199     return;
00200   }
00201   
00202   // note: there is no a-priori check that number_active_channels_from_header
00203   //          equals number_channels_found_in_data.
00204   //          The checks are doing f.e. by f.e. only.
00205   
00206   if( feUnpacking_ || memUnpacking_ ){                                          
00207     it = feChStatus_.begin();
00208     
00209     // looping over FE channels, i.e. tower blocks
00210     for( uint chNumber=1; chNumber<= numbChannels && STATUS!=STOP_EVENT_UNPACKING; chNumber++, it++ ){                  
00211       //for( uint i=1; chNumber<= numbChannels; chNumber++, it++ ){                     
00212 
00213       short  chStatus(*it);
00214       
00215       // not issuiung messages for regular cases
00216       if(chStatus == CH_DISABLED ||
00217          chStatus == CH_SUPPRESS) 
00218         {continue;}
00219       
00220       // issuiung messages for problematic cases, even though handled by the DCC
00221       else if( chStatus == CH_TIMEOUT || chStatus == CH_HEADERERR || chStatus == CH_LINKERR || chStatus == CH_LENGTHERR)
00222         {
00223           if( ! DCCDataUnpacker::silentMode_ ){ 
00224             edm::LogWarning("EcalRawToDigiDev") << "In fed: " << fedId_ << " at LV1: " << l1_
00225                                                 << " the DCC channel: " << chNumber 
00226                                                 << " has channel status: " << chStatus 
00227                                                 << " and is not being unpacked";
00228           }
00229           continue;
00230         }
00231       
00232       
00233       // Unpack Tower (Xtal Block) in case of SR (data are 0 suppressed)
00234       if(feUnpacking_ && sr_ && chNumber<=68)
00235         {
00236           if ( ( srpBlock_->srFlag(chNumber) & SRP_SRVAL_MASK) != SRP_NREAD ){
00237             STATUS = towerBlock_->unpack(&data_,&dwToEnd_,true,chNumber);
00238           }
00239         }
00240       
00241       
00242       // Unpack Tower (Xtal Block) for no SR (possibly 0 suppression flags)
00243       else if (feUnpacking_ && chNumber<=68)
00244         {
00245           // if tzs_ data are not really suppressed, even though zs flags are calculated
00246           if(tzs_){ zs_ = false;}
00247           STATUS = towerBlock_->unpack(&data_,&dwToEnd_,zs_,chNumber);
00248         }
00249       
00250       
00251       // Unpack Mem blocks
00252       if(memUnpacking_  && chNumber>68 )
00253         {
00254           STATUS = memBlock_->unpack(&data_,&dwToEnd_,chNumber);
00255         }
00256       
00257     }
00258     // closing loop over FE/TTblock channels
00259     
00260   }// check if we need to perform unpacking of FE or mem data
00261   
00262 }
00263 
00264 
00265 
00266 
00267 void DCCEventBlock::addHeaderToCollection(){
00268   
00269   
00270   EcalDCCHeaderBlock theDCCheader;
00271 
00272   // container for fed_id (601-654 for ECAL) 
00273   theDCCheader.setFedId(fedId_);
00274   
00275   
00276   // this needs to be migrated to the ECAL mapping package
00277 
00278   // dccId is number internal to ECAL running 1.. 54.
00279   // convention is that dccId = (fed_id - 600)
00280   int dccId = mapper_->getActiveSM();
00281   // DCCHeaders follow  the same convenction
00282   theDCCheader.setId(dccId);
00283   
00284 
00285   theDCCheader.setRunNumber(runNumber_);  
00286   theDCCheader.setBasicTriggerType(triggerType_);
00287   theDCCheader.setLV1(l1_);
00288   theDCCheader.setBX(bx_);
00289   theDCCheader.setOrbit(orbitCounter_);
00290   theDCCheader.setErrors(dccErrors_);
00291   theDCCheader.setSelectiveReadout(sr_);
00292   theDCCheader.setZeroSuppression(zs_);
00293   theDCCheader.setTestZeroSuppression(tzs_);
00294   theDCCheader.setSrpStatus(srChStatus_);
00295   theDCCheader.setTccStatus(tccChStatus_);
00296   theDCCheader.setFEStatus(feChStatus_);
00297 
00298   EcalDCCHeaderRuntypeDecoder theRuntypeDecoder;
00299   uint DCCruntype              = runType_;
00300   uint DCCdetTriggerType = detailedTriggerType_;
00301   theRuntypeDecoder.Decode(triggerType_, DCCdetTriggerType , DCCruntype, &theDCCheader);
00302 
00303   // Add Header to collection 
00304   (*dccHeaders_)->push_back(theDCCheader);
00305    
00306 }
00307 
00308 void DCCEventBlock::display(std::ostream& o){
00309   o<<"\n Unpacked Info for DCC Event Class"
00310    <<"\n DW1 ============================="
00311    <<"\n Fed Id "<<fedId_
00312    <<"\n Bx "<<bx_
00313    <<"\n L1 "<<l1_
00314    <<"\n Trigger Type "<<triggerType_
00315    <<"\n DW2 ============================="     
00316    <<"\n Length "<<blockLength_
00317    <<"\n Dcc errors "<<dccErrors_
00318    <<"\n Run number "<<runNumber_
00319    <<"\n DW3 ============================="
00320    <<"\n SR "<<sr_
00321    <<"\n ZS "<<zs_
00322    <<"\n TZS "<<tzs_
00323    <<"\n SRStatus "<<srChStatus_;
00324         
00325   std::vector<short>::iterator it;
00326   int i(0),k(0);
00327   for(it = tccChStatus_.begin(); it!=tccChStatus_.end();it++,i++){
00328     o<<"\n TCCStatus#"<<i<<" "<<(*it);
00329   } 
00330   
00331   i=0;
00332   for(it = feChStatus_.begin();it!=feChStatus_.end();it++ ,i++){
00333     if(!(i%14)){ o<<"\n DW"<<(k+3)<<" ============================="; k++; }
00334     o<<"\n FEStatus#"<<i<<" "<<(*it);           
00335   }
00336 
00337   o<<"\n";  
00338 } 
00339     
00340 
00341 DCCEventBlock::~DCCEventBlock(){
00342   if(towerBlock_){ delete towerBlock_; } 
00343   if(tccBlock_)  { delete tccBlock_;   }
00344   if(memBlock_)  { delete memBlock_;   }
00345   if(srpBlock_)  { delete srpBlock_;   }
00346 }
00347 

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