CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/EventFilter/EcalTBRawToDigi/src/EcalDCCUnpackingModule.cc

Go to the documentation of this file.
00001 /* \file EcalDCCUnpackingModule.h
00002  *
00003  *  $Date: 2009/12/14 22:22:37 $
00004  *  $Revision: 1.44 $
00005  *  \author N. Marinelli
00006  *  \author G. Della Ricca
00007  *  \author G. Franzoni
00008  *  \author A. Ghezzi
00009  */
00010 
00011 #include <EventFilter/EcalTBRawToDigi/interface/EcalDCCUnpackingModule.h>
00012 #include <EventFilter/EcalTBRawToDigi/src/EcalTBDaqFormatter.h>
00013 #include <EventFilter/EcalTBRawToDigi/src/EcalSupervisorDataFormatter.h>
00014 #include <EventFilter/EcalTBRawToDigi/src/CamacTBDataFormatter.h>
00015 #include <EventFilter/EcalTBRawToDigi/src/TableDataFormatter.h>
00016 #include <EventFilter/EcalTBRawToDigi/src/MatacqDataFormatter.h>
00017 #include <EventFilter/EcalTBRawToDigi/src/ECALParserException.h>
00018 #include <EventFilter/EcalTBRawToDigi/src/ECALParserBlockException.h>
00019 #include <DataFormats/FEDRawData/interface/FEDRawData.h>
00020 #include <DataFormats/FEDRawData/interface/FEDNumbering.h>
00021 #include <DataFormats/FEDRawData/interface/FEDRawDataCollection.h>
00022 #include <DataFormats/EcalDigi/interface/EcalDigiCollections.h>
00023 #include <DataFormats/EcalRawData/interface/EcalRawDataCollections.h>
00024 #include <TBDataFormats/EcalTBObjects/interface/EcalTBCollections.h>
00025 #include <DataFormats/Common/interface/Handle.h>
00026 #include <FWCore/Framework/interface/Event.h>
00027 
00028 
00029 
00030 #include <iostream>
00031 #include <iomanip>
00032 
00033 // in full CMS this range cannot be used (allocated to pixel, see DataFormats/ FEDRawData/ src/ FEDNumbering.cc) 
00034 #define BEG_DCC_FED_ID 0
00035 #define END_DCC_FED_ID 35
00036 #define BEG_DCC_FED_ID_GLOBAL 600
00037 #define END_DCC_FED_ID_GLOBAL 670
00038 
00039 #define ECAL_SUPERVISOR_FED_ID 40 
00040 #define TBCAMAC_FED_ID 41
00041 #define TABLE_FED_ID 42
00042 #define MATACQ_FED_ID 43
00043 
00044 EcalDCCTBUnpackingModule::EcalDCCTBUnpackingModule(const edm::ParameterSet& pset){
00045 
00046   formatter_ = new EcalTBDaqFormatter();
00047   ecalSupervisorFormatter_ = new EcalSupervisorTBDataFormatter();
00048   camacTBformatter_ = new CamacTBDataFormatter();
00049   tableFormatter_ = new TableDataFormatter();
00050   matacqFormatter_ = new MatacqTBDataFormatter();
00051 
00052   // digis
00053   produces<EBDigiCollection>("ebDigis");
00054   produces<EcalMatacqDigiCollection>();
00055   produces<EcalPnDiodeDigiCollection>();
00056   produces<EcalRawDataCollection>();
00057   produces<EcalTrigPrimDigiCollection>("EBTT");
00058 
00059   //TB specifics data
00060   produces<EcalTBHodoscopeRawInfo>();
00061   produces<EcalTBTDCRawInfo>();
00062   produces<EcalTBEventHeader>();
00063 
00064   // crystals' integrity
00065   produces<EBDetIdCollection>("EcalIntegrityDCCSizeErrors");
00066   produces<EcalElectronicsIdCollection>("EcalIntegrityTTIdErrors");
00067   produces<EcalElectronicsIdCollection>("EcalIntegrityBlockSizeErrors");
00068   produces<EBDetIdCollection>("EcalIntegrityChIdErrors");
00069   produces<EBDetIdCollection>("EcalIntegrityGainErrors");
00070   produces<EBDetIdCollection>("EcalIntegrityGainSwitchErrors");
00071 
00072   // mem channels' integrity
00073   produces<EcalElectronicsIdCollection>("EcalIntegrityMemTtIdErrors");
00074   produces<EcalElectronicsIdCollection>("EcalIntegrityMemBlockSize");
00075   produces<EcalElectronicsIdCollection>("EcalIntegrityMemChIdErrors");
00076   produces<EcalElectronicsIdCollection>("EcalIntegrityMemGainErrors");
00077 }
00078 
00079 
00080 EcalDCCTBUnpackingModule::~EcalDCCTBUnpackingModule(){
00081 
00082   delete formatter_;
00083 
00084 }
00085 
00086 void EcalDCCTBUnpackingModule::beginJob(){
00087 
00088 }
00089 
00090 void EcalDCCTBUnpackingModule::endJob(){
00091 
00092 }
00093 
00094 void EcalDCCTBUnpackingModule::produce(edm::Event & e, const edm::EventSetup& c){
00095 
00096   edm::Handle<FEDRawDataCollection> rawdata;
00097   e.getByType(rawdata);
00098   
00099 
00100   // create the collection of Ecal Digis
00101   std::auto_ptr<EBDigiCollection> productEb(new EBDigiCollection);
00102 
00103   // create the collection of Matacq Digi
00104   std::auto_ptr<EcalMatacqDigiCollection> productMatacq(new EcalMatacqDigiCollection());
00105 
00106   // create the collection of Ecal PN's
00107   std::auto_ptr<EcalPnDiodeDigiCollection> productPN(new EcalPnDiodeDigiCollection);
00108   
00109   //create the collection of Ecal DCC Header
00110   std::auto_ptr<EcalRawDataCollection> productDCCHeader(new EcalRawDataCollection);
00111 
00112   // create the collection with trigger primitives, bits and flags
00113   std::auto_ptr<EcalTrigPrimDigiCollection> productTriggerPrimitives(new EcalTrigPrimDigiCollection);
00114 
00115   // create the collection of Ecal Integrity DCC Size
00116   std::auto_ptr<EBDetIdCollection> productDCCSize(new EBDetIdCollection);
00117 
00118   // create the collection of Ecal Integrity TT Id
00119   std::auto_ptr<EcalElectronicsIdCollection> productTTId(new EcalElectronicsIdCollection);
00120 
00121   // create the collection of Ecal Integrity TT Block Size
00122   std::auto_ptr<EcalElectronicsIdCollection> productBlockSize(new EcalElectronicsIdCollection);
00123 
00124   // create the collection of Ecal Integrity Ch Id
00125   std::auto_ptr<EBDetIdCollection> productChId(new EBDetIdCollection);
00126 
00127   // create the collection of Ecal Integrity Gain
00128   std::auto_ptr<EBDetIdCollection> productGain(new EBDetIdCollection);
00129 
00130   // create the collection of Ecal Integrity Gain Switch
00131   std::auto_ptr<EBDetIdCollection> productGainSwitch(new EBDetIdCollection);
00132 
00133   // create the collection of Ecal Integrity Mem towerBlock_id errors
00134   std::auto_ptr<EcalElectronicsIdCollection> productMemTtId(new EcalElectronicsIdCollection);
00135   
00136   // create the collection of Ecal Integrity Mem gain errors
00137   std::auto_ptr< EcalElectronicsIdCollection> productMemBlockSize(new EcalElectronicsIdCollection);
00138 
00139   // create the collection of Ecal Integrity Mem gain errors
00140   std::auto_ptr< EcalElectronicsIdCollection> productMemGain(new EcalElectronicsIdCollection);
00141   
00142   // create the collection of Ecal Integrity Mem ch_id errors
00143   std::auto_ptr<EcalElectronicsIdCollection> productMemChIdErrors(new EcalElectronicsIdCollection);
00144   
00145   // create the collection of TB specifics data
00146   std::auto_ptr<EcalTBHodoscopeRawInfo> productHodo(new EcalTBHodoscopeRawInfo());         
00147   std::auto_ptr<EcalTBTDCRawInfo> productTdc(new EcalTBTDCRawInfo());                      
00148   std::auto_ptr<EcalTBEventHeader> productHeader(new EcalTBEventHeader());                      
00149 
00150 
00151   try {
00152 
00153   for (int id= 0; id<=FEDNumbering::MAXFEDID; ++id){ 
00154 
00155     //    edm::LogInfo("EcalDCCTBUnpackingModule") << "EcalDCCTBUnpackingModule::Got FED ID "<< id <<" ";
00156     const FEDRawData& data = rawdata->FEDData(id);
00157     //    edm::LogInfo("EcalDCCTBUnpackingModule") << " Fed data size " << data.size() ;
00158    
00159     //std::cout <<"1 Fed id: "<<dec<<id<< " Fed data size: " <<data.size() << std::endl;
00160 //    const unsigned char * pData = data.data();
00161 //    int length = data.size();
00162 //    if(length >0 ){
00163 //      if(length >= 40){length = 40;}
00164 //    std::cout<<"##############################################################"<<std::endl;
00165 //    for( int i=0; i<length; i++ ) {
00166 //      std::cout << std::hex << std::setw(8) << int(pData[i]) << " ";
00167 //      if( (i+1)%8 == 0 ) std::cout << std::endl;
00168 //     }
00169 //    std::cout<<"##############################################################"<<std::endl;
00170 //    } 
00171     if (data.size()>16){
00172 
00173       if ( (id >= BEG_DCC_FED_ID && id <= END_DCC_FED_ID) ||
00174            (id >= BEG_DCC_FED_ID_GLOBAL && id <= END_DCC_FED_ID_GLOBAL)
00175          )
00176         {       // do the DCC data unpacking and fill the collections
00177           
00178           (*productHeader).setSmInBeam(id);
00179           formatter_->interpretRawData(data,  *productEb, *productPN, 
00180                                        *productDCCHeader, 
00181                                        *productDCCSize, 
00182                                        *productTTId, *productBlockSize, 
00183                                        *productChId, *productGain, *productGainSwitch, 
00184                                        *productMemTtId,  *productMemBlockSize,
00185                                        *productMemGain,  *productMemChIdErrors,
00186                                        *productTriggerPrimitives);
00187           int runType = (*productDCCHeader)[0].getRunType();
00188           if ( runType == EcalDCCHeaderBlock::COSMIC || runType == EcalDCCHeaderBlock::BEAMH4 ) 
00189             (*productHeader).setTriggerMask(0x1);
00190           else if ( runType == 4 || runType == 5 || runType == 6 ) //laser runs
00191             (*productHeader).setTriggerMask(0x2000);
00192           else if ( runType == 9 || runType == 10 || runType == 11 ) //pedestal runs
00193             (*productHeader).setTriggerMask(0x800);
00194           LogDebug("EcalDCCTBUnpackingModule") << "Event type is " << (*productHeader).eventType() << " dbEventType " << (*productHeader).dbEventType();
00195         } 
00196       else if ( id == ECAL_SUPERVISOR_FED_ID )
00197         ecalSupervisorFormatter_->interpretRawData(data, *productHeader);
00198       else if ( id == TBCAMAC_FED_ID )
00199         camacTBformatter_->interpretRawData(data, *productHeader,*productHodo, *productTdc );
00200       else if ( id == TABLE_FED_ID )
00201         tableFormatter_->interpretRawData(data, *productHeader);
00202       else if ( id == MATACQ_FED_ID )     
00203         matacqFormatter_->interpretRawData(data, *productMatacq);
00204     }// endif 
00205   }//endfor
00206   
00207 
00208   // commit to the event  
00209   e.put(productPN);
00210   e.put(productEb,"ebDigis");
00211   e.put(productMatacq);
00212   e.put(productDCCHeader);
00213   e.put(productTriggerPrimitives,"EBTT");
00214 
00215   e.put(productDCCSize,"EcalIntegrityDCCSizeErrors");
00216   e.put(productTTId,"EcalIntegrityTTIdErrors");
00217   e.put(productBlockSize,"EcalIntegrityBlockSizeErrors");
00218   e.put(productChId,"EcalIntegrityChIdErrors");
00219   e.put(productGain,"EcalIntegrityGainErrors");
00220   e.put(productGainSwitch,"EcalIntegrityGainSwitchErrors");
00221 
00222   e.put(productMemTtId,"EcalIntegrityMemTtIdErrors");
00223   e.put(productMemBlockSize,"EcalIntegrityMemBlockSize");
00224   e.put(productMemChIdErrors,"EcalIntegrityMemChIdErrors");
00225   e.put(productMemGain,"EcalIntegrityMemGainErrors");
00226 
00227   e.put(productHodo);
00228   e.put(productTdc);
00229   e.put(productHeader);
00230 
00231   } catch (ECALTBParserException &e) {
00232     std::cout << "[EcalDCCTBUnpackingModule] " << e.what() << std::endl;
00233   } catch (ECALTBParserBlockException &e) {
00234     std::cout << "[EcalDCCTBUnpackingModule] " << e.what() << std::endl;
00235   } catch (cms::Exception &e) {
00236     std::cout << "[EcalDCCTBUnpackingModule] " << e.what() << std::endl;
00237   } catch (...) {
00238     std::cout << "[EcalDCCTBUnpackingModule] Unknown exception ..." << std::endl;
00239   }
00240 
00241 }