CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/EventFilter/EcalTBRawToDigi/src/EcalDCC07UnpackingModule.cc

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