Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-07 04:36:10

0001 /* \file EcalDCCUnpackingModule.h
0002  *
0003  *  \author N. Marinelli
0004  *  \author G. Della Ricca
0005  *  \author G. Franzoni
0006  *  \author A. Ghezzi
0007  */
0008 
0009 #include <EventFilter/EcalTBRawToDigi/interface/EcalDCCUnpackingModule.h>
0010 #include <EventFilter/EcalTBRawToDigi/src/EcalTBDaqFormatter.h>
0011 #include <EventFilter/EcalTBRawToDigi/src/EcalSupervisorDataFormatter.h>
0012 #include <EventFilter/EcalTBRawToDigi/src/CamacTBDataFormatter.h>
0013 #include <EventFilter/EcalTBRawToDigi/src/TableDataFormatter.h>
0014 #include <EventFilter/EcalTBRawToDigi/src/MatacqDataFormatter.h>
0015 #include <EventFilter/EcalTBRawToDigi/src/ECALParserException.h>
0016 #include <EventFilter/EcalTBRawToDigi/src/ECALParserBlockException.h>
0017 #include <DataFormats/FEDRawData/interface/FEDRawData.h>
0018 #include <DataFormats/FEDRawData/interface/FEDNumbering.h>
0019 #include <DataFormats/FEDRawData/interface/FEDRawDataCollection.h>
0020 #include <DataFormats/EcalDigi/interface/EcalDigiCollections.h>
0021 #include <DataFormats/EcalRawData/interface/EcalRawDataCollections.h>
0022 #include <TBDataFormats/EcalTBObjects/interface/EcalTBCollections.h>
0023 #include <DataFormats/Common/interface/Handle.h>
0024 #include <FWCore/Framework/interface/Event.h>
0025 
0026 #include <iostream>
0027 #include <iomanip>
0028 
0029 // in full CMS this range cannot be used (allocated to pixel, see DataFormats/ FEDRawData/ src/ FEDNumbering.cc)
0030 #define BEG_DCC_FED_ID 0
0031 #define END_DCC_FED_ID 35
0032 #define BEG_DCC_FED_ID_GLOBAL 600
0033 #define END_DCC_FED_ID_GLOBAL 670
0034 
0035 #define ECAL_SUPERVISOR_FED_ID 40
0036 #define TBCAMAC_FED_ID 41
0037 #define TABLE_FED_ID 42
0038 #define MATACQ_FED_ID 43
0039 
0040 EcalDCCTBUnpackingModule::EcalDCCTBUnpackingModule(const edm::ParameterSet& pset)
0041     : fedRawDataCollectionTag_(pset.getParameter<edm::InputTag>("fedRawDataCollectionTag")) {
0042   formatter_ = new EcalTBDaqFormatter();
0043   ecalSupervisorFormatter_ = new EcalSupervisorTBDataFormatter();
0044   camacTBformatter_ = new CamacTBDataFormatter();
0045   tableFormatter_ = new TableDataFormatter();
0046   matacqFormatter_ = new MatacqTBDataFormatter();
0047 
0048   // digis
0049   produces<EBDigiCollection>("ebDigis");
0050   produces<EcalMatacqDigiCollection>();
0051   produces<EcalPnDiodeDigiCollection>();
0052   produces<EcalRawDataCollection>();
0053   produces<EcalTrigPrimDigiCollection>("EBTT");
0054 
0055   //TB specifics data
0056   produces<EcalTBHodoscopeRawInfo>();
0057   produces<EcalTBTDCRawInfo>();
0058   produces<EcalTBEventHeader>();
0059 
0060   // crystals' integrity
0061   produces<EBDetIdCollection>("EcalIntegrityDCCSizeErrors");
0062   produces<EcalElectronicsIdCollection>("EcalIntegrityTTIdErrors");
0063   produces<EcalElectronicsIdCollection>("EcalIntegrityBlockSizeErrors");
0064   produces<EBDetIdCollection>("EcalIntegrityChIdErrors");
0065   produces<EBDetIdCollection>("EcalIntegrityGainErrors");
0066   produces<EBDetIdCollection>("EcalIntegrityGainSwitchErrors");
0067 
0068   // mem channels' integrity
0069   produces<EcalElectronicsIdCollection>("EcalIntegrityMemTtIdErrors");
0070   produces<EcalElectronicsIdCollection>("EcalIntegrityMemBlockSize");
0071   produces<EcalElectronicsIdCollection>("EcalIntegrityMemChIdErrors");
0072   produces<EcalElectronicsIdCollection>("EcalIntegrityMemGainErrors");
0073 }
0074 
0075 EcalDCCTBUnpackingModule::~EcalDCCTBUnpackingModule() { delete formatter_; }
0076 
0077 void EcalDCCTBUnpackingModule::produce(edm::Event& e, const edm::EventSetup& c) {
0078   edm::Handle<FEDRawDataCollection> rawdata;
0079   e.getByLabel(fedRawDataCollectionTag_, rawdata);
0080 
0081   // create the collection of Ecal Digis
0082   auto productEb = std::make_unique<EBDigiCollection>();
0083 
0084   // create the collection of Matacq Digi
0085   auto productMatacq = std::make_unique<EcalMatacqDigiCollection>();
0086 
0087   // create the collection of Ecal PN's
0088   auto productPN = std::make_unique<EcalPnDiodeDigiCollection>();
0089 
0090   //create the collection of Ecal DCC Header
0091   auto productDCCHeader = std::make_unique<EcalRawDataCollection>();
0092 
0093   // create the collection with trigger primitives, bits and flags
0094   auto productTriggerPrimitives = std::make_unique<EcalTrigPrimDigiCollection>();
0095 
0096   // create the collection of Ecal Integrity DCC Size
0097   auto productDCCSize = std::make_unique<EBDetIdCollection>();
0098 
0099   // create the collection of Ecal Integrity TT Id
0100   auto productTTId = std::make_unique<EcalElectronicsIdCollection>();
0101 
0102   // create the collection of Ecal Integrity TT Block Size
0103   auto productBlockSize = std::make_unique<EcalElectronicsIdCollection>();
0104 
0105   // create the collection of Ecal Integrity Ch Id
0106   auto productChId = std::make_unique<EBDetIdCollection>();
0107 
0108   // create the collection of Ecal Integrity Gain
0109   auto productGain = std::make_unique<EBDetIdCollection>();
0110 
0111   // create the collection of Ecal Integrity Gain Switch
0112   auto productGainSwitch = std::make_unique<EBDetIdCollection>();
0113 
0114   // create the collection of Ecal Integrity Mem towerBlock_id errors
0115   auto productMemTtId = std::make_unique<EcalElectronicsIdCollection>();
0116 
0117   // create the collection of Ecal Integrity Mem gain errors
0118   auto productMemBlockSize = std::make_unique<EcalElectronicsIdCollection>();
0119 
0120   // create the collection of Ecal Integrity Mem gain errors
0121   auto productMemGain = std::make_unique<EcalElectronicsIdCollection>();
0122 
0123   // create the collection of Ecal Integrity Mem ch_id errors
0124   auto productMemChIdErrors = std::make_unique<EcalElectronicsIdCollection>();
0125 
0126   // create the collection of TB specifics data
0127   auto productHodo = std::make_unique<EcalTBHodoscopeRawInfo>();
0128   auto productTdc = std::make_unique<EcalTBTDCRawInfo>();
0129   auto productHeader = std::make_unique<EcalTBEventHeader>();
0130 
0131   try {
0132     for (int id = 0; id <= FEDNumbering::MAXFEDID; ++id) {
0133       //    edm::LogInfo("EcalDCCTBUnpackingModule") << "EcalDCCTBUnpackingModule::Got FED ID "<< id <<" ";
0134       const FEDRawData& data = rawdata->FEDData(id);
0135       //    edm::LogInfo("EcalDCCTBUnpackingModule") << " Fed data size " << data.size() ;
0136 
0137       //std::cout <<"1 Fed id: "<<dec<<id<< " Fed data size: " <<data.size() << std::endl;
0138       //    const unsigned char * pData = data.data();
0139       //    int length = data.size();
0140       //    if(length >0 ){
0141       //      if(length >= 40){length = 40;}
0142       //    std::cout<<"##############################################################"<<std::endl;
0143       //    for( int i=0; i<length; i++ ) {
0144       //      std::cout << std::hex << std::setw(8) << int(pData[i]) << " ";
0145       //      if( (i+1)%8 == 0 ) std::cout << std::endl;
0146       //     }
0147       //    std::cout<<"##############################################################"<<std::endl;
0148       //    }
0149       if (data.size() > 16) {
0150         if ((id >= BEG_DCC_FED_ID && id <= END_DCC_FED_ID) ||
0151             (id >= BEG_DCC_FED_ID_GLOBAL &&
0152              id <= END_DCC_FED_ID_GLOBAL)) {  // do the DCC data unpacking and fill the collections
0153 
0154           (*productHeader).setSmInBeam(id);
0155           formatter_->interpretRawData(data,
0156                                        *productEb,
0157                                        *productPN,
0158                                        *productDCCHeader,
0159                                        *productDCCSize,
0160                                        *productTTId,
0161                                        *productBlockSize,
0162                                        *productChId,
0163                                        *productGain,
0164                                        *productGainSwitch,
0165                                        *productMemTtId,
0166                                        *productMemBlockSize,
0167                                        *productMemGain,
0168                                        *productMemChIdErrors,
0169                                        *productTriggerPrimitives);
0170           int runType = (*productDCCHeader)[0].getRunType();
0171           if (runType == EcalDCCHeaderBlock::COSMIC || runType == EcalDCCHeaderBlock::BEAMH4)
0172             (*productHeader).setTriggerMask(0x1);
0173           else if (runType == 4 || runType == 5 || runType == 6)  //laser runs
0174             (*productHeader).setTriggerMask(0x2000);
0175           else if (runType == 9 || runType == 10 || runType == 11)  //pedestal runs
0176             (*productHeader).setTriggerMask(0x800);
0177           LogDebug("EcalDCCTBUnpackingModule")
0178               << "Event type is " << (*productHeader).eventType() << " dbEventType " << (*productHeader).dbEventType();
0179         } else if (id == ECAL_SUPERVISOR_FED_ID)
0180           ecalSupervisorFormatter_->interpretRawData(data, *productHeader);
0181         else if (id == TBCAMAC_FED_ID)
0182           camacTBformatter_->interpretRawData(data, *productHeader, *productHodo, *productTdc);
0183         else if (id == TABLE_FED_ID)
0184           tableFormatter_->interpretRawData(data, *productHeader);
0185         else if (id == MATACQ_FED_ID)
0186           matacqFormatter_->interpretRawData(data, *productMatacq);
0187       }  // endif
0188     }  //endfor
0189 
0190     // commit to the event
0191     e.put(std::move(productPN));
0192     e.put(std::move(productEb), "ebDigis");
0193     e.put(std::move(productMatacq));
0194     e.put(std::move(productDCCHeader));
0195     e.put(std::move(productTriggerPrimitives), "EBTT");
0196 
0197     e.put(std::move(productDCCSize), "EcalIntegrityDCCSizeErrors");
0198     e.put(std::move(productTTId), "EcalIntegrityTTIdErrors");
0199     e.put(std::move(productBlockSize), "EcalIntegrityBlockSizeErrors");
0200     e.put(std::move(productChId), "EcalIntegrityChIdErrors");
0201     e.put(std::move(productGain), "EcalIntegrityGainErrors");
0202     e.put(std::move(productGainSwitch), "EcalIntegrityGainSwitchErrors");
0203 
0204     e.put(std::move(productMemTtId), "EcalIntegrityMemTtIdErrors");
0205     e.put(std::move(productMemBlockSize), "EcalIntegrityMemBlockSize");
0206     e.put(std::move(productMemChIdErrors), "EcalIntegrityMemChIdErrors");
0207     e.put(std::move(productMemGain), "EcalIntegrityMemGainErrors");
0208 
0209     e.put(std::move(productHodo));
0210     e.put(std::move(productTdc));
0211     e.put(std::move(productHeader));
0212 
0213   } catch (ECALTBParserException& e) {
0214     std::cout << "[EcalDCCTBUnpackingModule] " << e.what() << std::endl;
0215   } catch (ECALTBParserBlockException& e) {
0216     std::cout << "[EcalDCCTBUnpackingModule] " << e.what() << std::endl;
0217   } catch (cms::Exception& e) {
0218     std::cout << "[EcalDCCTBUnpackingModule] " << e.what() << std::endl;
0219   } catch (...) {
0220     std::cout << "[EcalDCCTBUnpackingModule] Unknown exception ..." << std::endl;
0221   }
0222 }