CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2_patch1/src/EventFilter/EcalTBRawToDigi/src/EcalDCCUnpackingModule.cc

Go to the documentation of this file.
00001 /* \file EcalDCCUnpackingModule.h
00002  *
00003  *  $Date: 2012/09/12 18:18:44 $
00004  *  $Revision: 1.45 $
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   fedRawDataCollectionTag_(pset.getParameter<edm::InputTag>("fedRawDataCollectionTag")) {
00046 
00047   formatter_ = new EcalTBDaqFormatter();
00048   ecalSupervisorFormatter_ = new EcalSupervisorTBDataFormatter();
00049   camacTBformatter_ = new CamacTBDataFormatter();
00050   tableFormatter_ = new TableDataFormatter();
00051   matacqFormatter_ = new MatacqTBDataFormatter();
00052 
00053   // digis
00054   produces<EBDigiCollection>("ebDigis");
00055   produces<EcalMatacqDigiCollection>();
00056   produces<EcalPnDiodeDigiCollection>();
00057   produces<EcalRawDataCollection>();
00058   produces<EcalTrigPrimDigiCollection>("EBTT");
00059 
00060   //TB specifics data
00061   produces<EcalTBHodoscopeRawInfo>();
00062   produces<EcalTBTDCRawInfo>();
00063   produces<EcalTBEventHeader>();
00064 
00065   // crystals' integrity
00066   produces<EBDetIdCollection>("EcalIntegrityDCCSizeErrors");
00067   produces<EcalElectronicsIdCollection>("EcalIntegrityTTIdErrors");
00068   produces<EcalElectronicsIdCollection>("EcalIntegrityBlockSizeErrors");
00069   produces<EBDetIdCollection>("EcalIntegrityChIdErrors");
00070   produces<EBDetIdCollection>("EcalIntegrityGainErrors");
00071   produces<EBDetIdCollection>("EcalIntegrityGainSwitchErrors");
00072 
00073   // mem channels' integrity
00074   produces<EcalElectronicsIdCollection>("EcalIntegrityMemTtIdErrors");
00075   produces<EcalElectronicsIdCollection>("EcalIntegrityMemBlockSize");
00076   produces<EcalElectronicsIdCollection>("EcalIntegrityMemChIdErrors");
00077   produces<EcalElectronicsIdCollection>("EcalIntegrityMemGainErrors");
00078 }
00079 
00080 
00081 EcalDCCTBUnpackingModule::~EcalDCCTBUnpackingModule(){
00082 
00083   delete formatter_;
00084 
00085 }
00086 
00087 void EcalDCCTBUnpackingModule::beginJob(){
00088 
00089 }
00090 
00091 void EcalDCCTBUnpackingModule::endJob(){
00092 
00093 }
00094 
00095 void EcalDCCTBUnpackingModule::produce(edm::Event & e, const edm::EventSetup& c){
00096 
00097   edm::Handle<FEDRawDataCollection> rawdata;
00098   e.getByLabel(fedRawDataCollectionTag_, rawdata);
00099   
00100 
00101   // create the collection of Ecal Digis
00102   std::auto_ptr<EBDigiCollection> productEb(new EBDigiCollection);
00103 
00104   // create the collection of Matacq Digi
00105   std::auto_ptr<EcalMatacqDigiCollection> productMatacq(new EcalMatacqDigiCollection());
00106 
00107   // create the collection of Ecal PN's
00108   std::auto_ptr<EcalPnDiodeDigiCollection> productPN(new EcalPnDiodeDigiCollection);
00109   
00110   //create the collection of Ecal DCC Header
00111   std::auto_ptr<EcalRawDataCollection> productDCCHeader(new EcalRawDataCollection);
00112 
00113   // create the collection with trigger primitives, bits and flags
00114   std::auto_ptr<EcalTrigPrimDigiCollection> productTriggerPrimitives(new EcalTrigPrimDigiCollection);
00115 
00116   // create the collection of Ecal Integrity DCC Size
00117   std::auto_ptr<EBDetIdCollection> productDCCSize(new EBDetIdCollection);
00118 
00119   // create the collection of Ecal Integrity TT Id
00120   std::auto_ptr<EcalElectronicsIdCollection> productTTId(new EcalElectronicsIdCollection);
00121 
00122   // create the collection of Ecal Integrity TT Block Size
00123   std::auto_ptr<EcalElectronicsIdCollection> productBlockSize(new EcalElectronicsIdCollection);
00124 
00125   // create the collection of Ecal Integrity Ch Id
00126   std::auto_ptr<EBDetIdCollection> productChId(new EBDetIdCollection);
00127 
00128   // create the collection of Ecal Integrity Gain
00129   std::auto_ptr<EBDetIdCollection> productGain(new EBDetIdCollection);
00130 
00131   // create the collection of Ecal Integrity Gain Switch
00132   std::auto_ptr<EBDetIdCollection> productGainSwitch(new EBDetIdCollection);
00133 
00134   // create the collection of Ecal Integrity Mem towerBlock_id errors
00135   std::auto_ptr<EcalElectronicsIdCollection> productMemTtId(new EcalElectronicsIdCollection);
00136   
00137   // create the collection of Ecal Integrity Mem gain errors
00138   std::auto_ptr< EcalElectronicsIdCollection> productMemBlockSize(new EcalElectronicsIdCollection);
00139 
00140   // create the collection of Ecal Integrity Mem gain errors
00141   std::auto_ptr< EcalElectronicsIdCollection> productMemGain(new EcalElectronicsIdCollection);
00142   
00143   // create the collection of Ecal Integrity Mem ch_id errors
00144   std::auto_ptr<EcalElectronicsIdCollection> productMemChIdErrors(new EcalElectronicsIdCollection);
00145   
00146   // create the collection of TB specifics data
00147   std::auto_ptr<EcalTBHodoscopeRawInfo> productHodo(new EcalTBHodoscopeRawInfo());         
00148   std::auto_ptr<EcalTBTDCRawInfo> productTdc(new EcalTBTDCRawInfo());                      
00149   std::auto_ptr<EcalTBEventHeader> productHeader(new EcalTBEventHeader());                      
00150 
00151 
00152   try {
00153 
00154   for (int id= 0; id<=FEDNumbering::MAXFEDID; ++id){ 
00155 
00156     //    edm::LogInfo("EcalDCCTBUnpackingModule") << "EcalDCCTBUnpackingModule::Got FED ID "<< id <<" ";
00157     const FEDRawData& data = rawdata->FEDData(id);
00158     //    edm::LogInfo("EcalDCCTBUnpackingModule") << " Fed data size " << data.size() ;
00159    
00160     //std::cout <<"1 Fed id: "<<dec<<id<< " Fed data size: " <<data.size() << std::endl;
00161 //    const unsigned char * pData = data.data();
00162 //    int length = data.size();
00163 //    if(length >0 ){
00164 //      if(length >= 40){length = 40;}
00165 //    std::cout<<"##############################################################"<<std::endl;
00166 //    for( int i=0; i<length; i++ ) {
00167 //      std::cout << std::hex << std::setw(8) << int(pData[i]) << " ";
00168 //      if( (i+1)%8 == 0 ) std::cout << std::endl;
00169 //     }
00170 //    std::cout<<"##############################################################"<<std::endl;
00171 //    } 
00172     if (data.size()>16){
00173 
00174       if ( (id >= BEG_DCC_FED_ID && id <= END_DCC_FED_ID) ||
00175            (id >= BEG_DCC_FED_ID_GLOBAL && id <= END_DCC_FED_ID_GLOBAL)
00176          )
00177         {       // do the DCC data unpacking and fill the collections
00178           
00179           (*productHeader).setSmInBeam(id);
00180           formatter_->interpretRawData(data,  *productEb, *productPN, 
00181                                        *productDCCHeader, 
00182                                        *productDCCSize, 
00183                                        *productTTId, *productBlockSize, 
00184                                        *productChId, *productGain, *productGainSwitch, 
00185                                        *productMemTtId,  *productMemBlockSize,
00186                                        *productMemGain,  *productMemChIdErrors,
00187                                        *productTriggerPrimitives);
00188           int runType = (*productDCCHeader)[0].getRunType();
00189           if ( runType == EcalDCCHeaderBlock::COSMIC || runType == EcalDCCHeaderBlock::BEAMH4 ) 
00190             (*productHeader).setTriggerMask(0x1);
00191           else if ( runType == 4 || runType == 5 || runType == 6 ) //laser runs
00192             (*productHeader).setTriggerMask(0x2000);
00193           else if ( runType == 9 || runType == 10 || runType == 11 ) //pedestal runs
00194             (*productHeader).setTriggerMask(0x800);
00195           LogDebug("EcalDCCTBUnpackingModule") << "Event type is " << (*productHeader).eventType() << " dbEventType " << (*productHeader).dbEventType();
00196         } 
00197       else if ( id == ECAL_SUPERVISOR_FED_ID )
00198         ecalSupervisorFormatter_->interpretRawData(data, *productHeader);
00199       else if ( id == TBCAMAC_FED_ID )
00200         camacTBformatter_->interpretRawData(data, *productHeader,*productHodo, *productTdc );
00201       else if ( id == TABLE_FED_ID )
00202         tableFormatter_->interpretRawData(data, *productHeader);
00203       else if ( id == MATACQ_FED_ID )     
00204         matacqFormatter_->interpretRawData(data, *productMatacq);
00205     }// endif 
00206   }//endfor
00207   
00208 
00209   // commit to the event  
00210   e.put(productPN);
00211   e.put(productEb,"ebDigis");
00212   e.put(productMatacq);
00213   e.put(productDCCHeader);
00214   e.put(productTriggerPrimitives,"EBTT");
00215 
00216   e.put(productDCCSize,"EcalIntegrityDCCSizeErrors");
00217   e.put(productTTId,"EcalIntegrityTTIdErrors");
00218   e.put(productBlockSize,"EcalIntegrityBlockSizeErrors");
00219   e.put(productChId,"EcalIntegrityChIdErrors");
00220   e.put(productGain,"EcalIntegrityGainErrors");
00221   e.put(productGainSwitch,"EcalIntegrityGainSwitchErrors");
00222 
00223   e.put(productMemTtId,"EcalIntegrityMemTtIdErrors");
00224   e.put(productMemBlockSize,"EcalIntegrityMemBlockSize");
00225   e.put(productMemChIdErrors,"EcalIntegrityMemChIdErrors");
00226   e.put(productMemGain,"EcalIntegrityMemGainErrors");
00227 
00228   e.put(productHodo);
00229   e.put(productTdc);
00230   e.put(productHeader);
00231 
00232   } catch (ECALTBParserException &e) {
00233     std::cout << "[EcalDCCTBUnpackingModule] " << e.what() << std::endl;
00234   } catch (ECALTBParserBlockException &e) {
00235     std::cout << "[EcalDCCTBUnpackingModule] " << e.what() << std::endl;
00236   } catch (cms::Exception &e) {
00237     std::cout << "[EcalDCCTBUnpackingModule] " << e.what() << std::endl;
00238   } catch (...) {
00239     std::cout << "[EcalDCCTBUnpackingModule] Unknown exception ..." << std::endl;
00240   }
00241 
00242 }