CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/EventFilter/EcalTBRawToDigi/src/EcalDCC07UnpackingModule.cc

Go to the documentation of this file.
00001 /* \file EcalDCCTB07UnpackingModule.h
00002  *
00003  *  $Date: 2009/12/14 22:22:37 $
00004  *  $Revision: 1.12 $
00005  *  \author Y. Maravin
00006  *  \author G. Franzoni
00007  *  \author G. Della Ricca
00008  */
00009 
00010 #include <EventFilter/EcalTBRawToDigi/interface/EcalDCC07UnpackingModule.h>
00011 #include <EventFilter/EcalTBRawToDigi/src/EcalTB07DaqFormatter.h>
00012 #include <EventFilter/EcalTBRawToDigi/src/EcalSupervisorDataFormatter.h>
00013 #include <EventFilter/EcalTBRawToDigi/src/CamacTBDataFormatter.h>
00014 #include <EventFilter/EcalTBRawToDigi/src/TableDataFormatter.h>
00015 #include <EventFilter/EcalTBRawToDigi/src/MatacqDataFormatter.h>
00016 #include <EventFilter/EcalTBRawToDigi/src/ECALParserException.h>
00017 #include <EventFilter/EcalTBRawToDigi/src/ECALParserBlockException.h>
00018 #include <DataFormats/FEDRawData/interface/FEDRawData.h>
00019 #include <DataFormats/FEDRawData/interface/FEDNumbering.h>
00020 #include <DataFormats/FEDRawData/interface/FEDRawDataCollection.h>
00021 #include <DataFormats/EcalDigi/interface/EcalDigiCollections.h>
00022 #include <DataFormats/EcalRawData/interface/EcalRawDataCollections.h>
00023 #include <TBDataFormats/EcalTBObjects/interface/EcalTBCollections.h>
00024 #include <DataFormats/Common/interface/Handle.h>
00025 #include <FWCore/Framework/interface/Event.h>
00026 #include <FWCore/ParameterSet/interface/FileInPath.h>
00027 
00028 
00029 #include <iostream>
00030 #include <iomanip>
00031 
00032 // in full CMS this range cannot be used (allocated to pixel, see DataFormats/ FEDRawData/ src/ FEDNumbering.cc) 
00033 #define BEG_DCC_FED_ID 0
00034 #define END_DCC_FED_ID 0
00035 #define BEG_DCC_FED_ID_GLOBAL 0
00036 #define END_DCC_FED_ID_GLOBAL 0
00037 
00038 #define ECAL_SUPERVISOR_FED_ID 40 
00039 #define TBCAMAC_FED_ID 41
00040 #define TABLE_FED_ID 42
00041 #define MATACQ_FED_ID 43
00042 
00043 EcalDCCTB07UnpackingModule::EcalDCCTB07UnpackingModule(const edm::ParameterSet& pset){
00044 
00045   std::string tbName = pset.getUntrackedParameter<std::string >("tbName", std::string("h2") );
00046 
00047   ProduceEEDigis_ = pset.getUntrackedParameter<bool >("produceEEdigi", true );
00048   ProduceEBDigis_ = pset.getUntrackedParameter<bool >("produceEBdigi", false );
00049 
00050   // index of crystal <-> tower ID (DQM plots) position <-> stripIDs <-> channelIDs for the test beam (2007)
00051   std::vector<int> ics        = pset.getUntrackedParameter<std::vector<int> >("ics",          std::vector<int>());
00052   std::vector<int> towerIDs   = pset.getUntrackedParameter<std::vector<int> >("towerIDs",     std::vector<int>());
00053   std::vector<int> stripIDs   = pset.getUntrackedParameter<std::vector<int> >("stripIDs",     std::vector<int>());
00054   std::vector<int> channelIDs = pset.getUntrackedParameter<std::vector<int> >("channelIDs",   std::vector<int>());
00055 
00056   // status id <-> tower CCU ID <-> DQM plots position mapping for the test beam (2007)
00057   std::vector<int> statusIDs   = pset.getUntrackedParameter<std::vector<int> >("statusIDs",   std::vector<int>());
00058   std::vector<int> ccuIDs      = pset.getUntrackedParameter<std::vector<int> >("ccuIDs",      std::vector<int>());
00059   std::vector<int> positionIDs = pset.getUntrackedParameter<std::vector<int> >("positionIDs", std::vector<int>());
00060 
00061   // check if vectors are filled
00062   if ( ics.size() == 0 || towerIDs.size() == 0 || stripIDs.size() == 0 || channelIDs.size() == 0 ){
00063     edm::LogError("EcalDCCTB07UnpackingModule") << "Some of the mapping info is missing! Check config files! " <<
00064       " Size of IC vector is " << ics.size() <<
00065       " Size of Tower ID vector is " << towerIDs.size() <<
00066       " Size of Strip ID vector is " << stripIDs.size() <<
00067       " Size of Channel ID vector is " << channelIDs.size();
00068   }
00069   if ( statusIDs.size() == 0 || ccuIDs.size() == 0 || positionIDs.size() == 0 ) {
00070     edm::LogError("EcalDCCTB07UnpackingModule") << "Some of the mapping info is missing! Check config files! " <<
00071       " Size of status ID vector is " << statusIDs.size() <<
00072       " Size of ccu ID vector is " << ccuIDs.size() <<
00073       " positionIDs size is " << positionIDs.size();
00074   }
00075   
00076   // check if vectors have the same size
00077   if ( ics.size() != towerIDs.size() || ics.size() != stripIDs.size() || ics.size() != channelIDs.size() ||
00078        towerIDs.size() != stripIDs.size() || towerIDs.size() != channelIDs.size() ||
00079        stripIDs.size() != channelIDs.size() )
00080     edm::LogError("EcalDCCTB07UnpackingModule") << "Mapping information is corrupted. " <<
00081       "Tower/DQM position/strip/channel vectors are of different size! Check cfi files! \n" <<
00082       " Size of IC vector is " << ics.size() <<
00083       " Size of Tower ID vector is " << towerIDs.size() <<
00084       " Size of Strip ID vector is " << stripIDs.size() <<
00085       " Size of Channel ID vector is " << channelIDs.size();
00086   
00087   if ( statusIDs.size() != ccuIDs.size() || statusIDs.size() != positionIDs.size() ||
00088        ccuIDs.size() != positionIDs.size() ) 
00089     edm::LogError("EcalDCCTB07UnpackingModule") << "Mapping information is corrupted. " <<
00090       "Status/CCU ID/DQM position vectors are of different size! Check cfi files! \n" <<
00091       " Size of status ID vector is " << statusIDs.size() <<
00092       " Size of ccu ID vector is " << ccuIDs.size() <<
00093       " positionIDs size is " << positionIDs.size();
00094   
00095   int cryIcMap[68][5][5];
00096   int tbStatusToLocation[71];
00097   int tbTowerIDToLocation[201];
00098   for (unsigned it=1; it <= 68; ++it )
00099     for (unsigned is=1; is <=5; ++is )
00100       for (unsigned ic=1; ic <=5; ++ic)
00101         cryIcMap[it-1][is-1][ic-1] = 1700;
00102 
00103   for (unsigned it=1; it <=71; ++it)
00104     tbStatusToLocation[it-1] = it - 1;
00105 
00106   for (unsigned it=1; it <= 201; ++it)
00107     tbTowerIDToLocation[it-1] = it - 1;
00108 
00109   // Fill the cry IC map
00110   for(unsigned int i=0; i < ics.size(); ++i) {
00111     int tower = towerIDs[i];
00112     int strip = stripIDs[i];
00113     int channel = channelIDs[i];
00114     int ic = ics[i];
00115     cryIcMap[tower-1][strip-1][channel-1] = ic;
00116   }
00117   for(unsigned int i = 0; i < statusIDs.size(); ++i) {
00118     int is = statusIDs[i];
00119     int it = ccuIDs[i];
00120     int itEB = positionIDs[i];
00121 
00122     tbStatusToLocation[is] = itEB;
00123     tbTowerIDToLocation[it] = itEB;
00124   }
00125 
00126   formatter_ = new EcalTB07DaqFormatter(tbName, cryIcMap, tbStatusToLocation, tbTowerIDToLocation);
00127   ecalSupervisorFormatter_ = new EcalSupervisorTBDataFormatter();
00128   camacTBformatter_ = new CamacTBDataFormatter();
00129   tableFormatter_ = new TableDataFormatter();
00130   matacqFormatter_ = new MatacqTBDataFormatter();
00131 
00132 
00133   // digis
00134   produces<EBDigiCollection>("ebDigis");
00135   produces<EEDigiCollection>("eeDigis");
00136   produces<EcalMatacqDigiCollection>();
00137   produces<EcalPnDiodeDigiCollection>();
00138   produces<EcalRawDataCollection>();
00139   produces<EcalTrigPrimDigiCollection>("EBTT");
00140 
00141   //TB specifics data
00142   produces<EcalTBHodoscopeRawInfo>();
00143   produces<EcalTBTDCRawInfo>();
00144   produces<EcalTBEventHeader>();
00145 
00146   // crystals' integrity
00147   produces<EBDetIdCollection>("EcalIntegrityDCCSizeErrors");
00148   produces<EcalElectronicsIdCollection>("EcalIntegrityTTIdErrors");
00149   produces<EcalElectronicsIdCollection>("EcalIntegrityBlockSizeErrors");
00150   produces<EBDetIdCollection>("EcalIntegrityChIdErrors");
00151   produces<EBDetIdCollection>("EcalIntegrityGainErrors");
00152   produces<EBDetIdCollection>("EcalIntegrityGainSwitchErrors");
00153 
00154   // mem channels' integrity
00155   produces<EcalElectronicsIdCollection>("EcalIntegrityMemTtIdErrors");
00156   produces<EcalElectronicsIdCollection>("EcalIntegrityMemBlockSize");
00157   produces<EcalElectronicsIdCollection>("EcalIntegrityMemChIdErrors");
00158   produces<EcalElectronicsIdCollection>("EcalIntegrityMemGainErrors");
00159 }
00160 
00161 
00162 EcalDCCTB07UnpackingModule::~EcalDCCTB07UnpackingModule(){
00163 
00164   delete formatter_;
00165 
00166 }
00167 
00168 void EcalDCCTB07UnpackingModule::beginJob(){
00169 
00170 }
00171 
00172 void EcalDCCTB07UnpackingModule::endJob(){
00173 
00174 }
00175 
00176 void EcalDCCTB07UnpackingModule::produce(edm::Event & e, const edm::EventSetup& c){
00177 
00178   edm::Handle<FEDRawDataCollection> rawdata;
00179   e.getByType(rawdata);
00180   
00181 
00182   // create the collection of Ecal Digis
00183   std::auto_ptr<EBDigiCollection> productEb(new EBDigiCollection);
00184 
00185   // YM create the collection of Ecal Endcap Digis
00186   std::auto_ptr<EEDigiCollection> productEe(new EEDigiCollection);
00187 
00188   // create the collection of Matacq Digi
00189   std::auto_ptr<EcalMatacqDigiCollection> productMatacq(new EcalMatacqDigiCollection());
00190 
00191   // create the collection of Ecal PN's
00192   std::auto_ptr<EcalPnDiodeDigiCollection> productPN(new EcalPnDiodeDigiCollection);
00193   
00194   //create the collection of Ecal DCC Header
00195   std::auto_ptr<EcalRawDataCollection> productDCCHeader(new EcalRawDataCollection);
00196 
00197   // create the collection with trigger primitives, bits and flags
00198   std::auto_ptr<EcalTrigPrimDigiCollection> productTriggerPrimitives(new EcalTrigPrimDigiCollection);
00199 
00200   // create the collection of Ecal Integrity DCC Size
00201   std::auto_ptr<EBDetIdCollection> productDCCSize(new EBDetIdCollection);
00202 
00203   // create the collection of Ecal Integrity TT Id
00204   std::auto_ptr<EcalElectronicsIdCollection> productTTId(new EcalElectronicsIdCollection);
00205 
00206   // create the collection of Ecal Integrity TT Block Size
00207   std::auto_ptr<EcalElectronicsIdCollection> productBlockSize(new EcalElectronicsIdCollection);
00208 
00209   // create the collection of Ecal Integrity Ch Id
00210   std::auto_ptr<EBDetIdCollection> productChId(new EBDetIdCollection);
00211 
00212   // create the collection of Ecal Integrity Gain
00213   std::auto_ptr<EBDetIdCollection> productGain(new EBDetIdCollection);
00214 
00215   // create the collection of Ecal Integrity Gain Switch
00216   std::auto_ptr<EBDetIdCollection> productGainSwitch(new EBDetIdCollection);
00217 
00218   // create the collection of Ecal Integrity Mem towerBlock_id errors
00219   std::auto_ptr<EcalElectronicsIdCollection> productMemTtId(new EcalElectronicsIdCollection);
00220   
00221   // create the collection of Ecal Integrity Mem gain errors
00222   std::auto_ptr< EcalElectronicsIdCollection> productMemBlockSize(new EcalElectronicsIdCollection);
00223 
00224   // create the collection of Ecal Integrity Mem gain errors
00225   std::auto_ptr< EcalElectronicsIdCollection> productMemGain(new EcalElectronicsIdCollection);
00226   
00227   // create the collection of Ecal Integrity Mem ch_id errors
00228   std::auto_ptr<EcalElectronicsIdCollection> productMemChIdErrors(new EcalElectronicsIdCollection);
00229   
00230   // create the collection of TB specifics data
00231   std::auto_ptr<EcalTBHodoscopeRawInfo> productHodo(new EcalTBHodoscopeRawInfo());         
00232   std::auto_ptr<EcalTBTDCRawInfo> productTdc(new EcalTBTDCRawInfo());                      
00233   std::auto_ptr<EcalTBEventHeader> productHeader(new EcalTBEventHeader());                      
00234 
00235 
00236   try {
00237 
00238   for (int id= 0; id<=FEDNumbering::MAXFEDID; ++id){ 
00239 
00240     //    edm::LogInfo("EcalDCCTB07UnpackingModule") << "EcalDCCTB07UnpackingModule::Got FED ID "<< id <<" ";
00241     const FEDRawData& data = rawdata->FEDData(id);
00242     //    edm::LogInfo("EcalDCCTB07UnpackingModule") << " Fed data size " << data.size() ;
00243    
00244     //std::cout <<"1 Fed id: "<<dec<<id<< " Fed data size: " <<data.size() << std::endl;
00245 //    const unsigned char * pData = data.data();
00246 //    int length = data.size();
00247 //    if(length >0 ){
00248 //      if(length >= 40){length = 40;}
00249 //    std::cout<<"##############################################################"<<std::endl;
00250 //    for( int i=0; i<length; i++ ) {
00251 //      std::cout << std::hex << std::setw(8) << int(pData[i]) << " ";
00252 //      if( (i+1)%8 == 0 ) std::cout << std::endl;
00253 //     }
00254 //    std::cout<<"##############################################################"<<std::endl;
00255 //    } 
00256     if (data.size()>16){
00257 
00258       if (        (id >= BEG_DCC_FED_ID && id <= END_DCC_FED_ID) ||
00259           ( BEG_DCC_FED_ID_GLOBAL <= id &&  id <= END_DCC_FED_ID_GLOBAL )
00260           )
00261         {       // do the DCC data unpacking and fill the collections
00262           
00263           (*productHeader).setSmInBeam(id);
00264           // YM add productEe to the list of arguments of the formatter
00265           formatter_->interpretRawData(data,  *productEb, *productEe, *productPN, 
00266                                        *productDCCHeader, 
00267                                        *productDCCSize, 
00268                                        *productTTId, *productBlockSize, 
00269                                        *productChId, *productGain, *productGainSwitch, 
00270                                        *productMemTtId,  *productMemBlockSize,
00271                                        *productMemGain,  *productMemChIdErrors,
00272                                        *productTriggerPrimitives);
00273           int runType = (*productDCCHeader)[0].getRunType();
00274           if ( runType == EcalDCCHeaderBlock::COSMIC || runType == EcalDCCHeaderBlock::BEAMH4 ) 
00275             (*productHeader).setTriggerMask(0x1);
00276           else if ( runType == 4 || runType == 5 || runType == 6 ) //laser runs
00277             (*productHeader).setTriggerMask(0x2000);
00278           else if ( runType == 9 || runType == 10 || runType == 11 ) //pedestal runs
00279             (*productHeader).setTriggerMask(0x800);
00280           LogDebug("EcalDCCTB07UnpackingModule") << "Event type is " << (*productHeader).eventType() << " dbEventType " << (*productHeader).dbEventType();
00281         } 
00282       else if ( id == ECAL_SUPERVISOR_FED_ID )
00283         ecalSupervisorFormatter_->interpretRawData(data, *productHeader);
00284       else if ( id == TBCAMAC_FED_ID )
00285         camacTBformatter_->interpretRawData(data, *productHeader,*productHodo, *productTdc );
00286       else if ( id == TABLE_FED_ID )
00287         tableFormatter_->interpretRawData(data, *productHeader);
00288       else if ( id == MATACQ_FED_ID )     
00289         matacqFormatter_->interpretRawData(data, *productMatacq);
00290     }// endif 
00291   }//endfor
00292   
00293 
00294   // commit to the event  
00295   e.put(productPN);
00296   if (ProduceEBDigis_)  e.put(productEb,"ebDigis");
00297   if (ProduceEEDigis_)  e.put(productEe,"eeDigis");
00298   e.put(productMatacq);
00299   e.put(productDCCHeader);
00300   e.put(productTriggerPrimitives, "EBTT");
00301   
00302   if (ProduceEBDigis_)  e.put(productDCCSize,"EcalIntegrityDCCSizeErrors");
00303   if (ProduceEBDigis_)  e.put(productTTId,"EcalIntegrityTTIdErrors");
00304   if (ProduceEBDigis_)  e.put(productBlockSize,"EcalIntegrityBlockSizeErrors");
00305   if (ProduceEBDigis_)  e.put(productChId,"EcalIntegrityChIdErrors");
00306   if (ProduceEBDigis_)  e.put(productGain,"EcalIntegrityGainErrors");
00307   if (ProduceEBDigis_)  e.put(productGainSwitch,"EcalIntegrityGainSwitchErrors");
00308   
00309   if (ProduceEBDigis_)  e.put(productMemTtId,"EcalIntegrityMemTtIdErrors");
00310   if (ProduceEBDigis_)  e.put(productMemBlockSize,"EcalIntegrityMemBlockSize");
00311   if (ProduceEBDigis_)  e.put(productMemChIdErrors,"EcalIntegrityMemChIdErrors");
00312   if (ProduceEBDigis_)  e.put(productMemGain,"EcalIntegrityMemGainErrors");
00313 
00314   e.put(productHodo);
00315   e.put(productTdc);
00316   e.put(productHeader);
00317 
00318   } catch (ECALTBParserException &e) {
00319     std::cout << "[EcalDCCTB07UnpackingModule] " << e.what() << std::endl;
00320   } catch (ECALTBParserBlockException &e) {
00321     std::cout << "[EcalDCCTB07UnpackingModule] " << e.what() << std::endl;
00322   } catch (cms::Exception &e) {
00323     std::cout << "[EcalDCCTB07UnpackingModule] " << e.what() << std::endl;
00324   } catch (...) {
00325     std::cout << "[EcalDCCTB07UnpackingModule] Unknown exception ..." << std::endl;
00326   }
00327 
00328 }