Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-06-11 03:13:06

0001 /* \file EcalDCCTB07UnpackingModule.h
0002  *
0003  *  \author Y. Maravin
0004  *  \author G. Franzoni
0005  *  \author G. Della Ricca
0006  */
0007 
0008 #include <EventFilter/EcalTBRawToDigi/interface/EcalDCC07UnpackingModule.h>
0009 #include <EventFilter/EcalTBRawToDigi/src/EcalTB07DaqFormatter.h>
0010 #include <EventFilter/EcalTBRawToDigi/src/EcalSupervisorDataFormatter.h>
0011 #include <EventFilter/EcalTBRawToDigi/src/CamacTBDataFormatter.h>
0012 #include <EventFilter/EcalTBRawToDigi/src/TableDataFormatter.h>
0013 #include <EventFilter/EcalTBRawToDigi/src/MatacqDataFormatter.h>
0014 #include <EventFilter/EcalTBRawToDigi/src/ECALParserException.h>
0015 #include <EventFilter/EcalTBRawToDigi/src/ECALParserBlockException.h>
0016 #include <DataFormats/FEDRawData/interface/FEDRawData.h>
0017 #include <DataFormats/FEDRawData/interface/FEDNumbering.h>
0018 #include <DataFormats/FEDRawData/interface/FEDRawDataCollection.h>
0019 #include <DataFormats/EcalDigi/interface/EcalDigiCollections.h>
0020 #include <DataFormats/EcalRawData/interface/EcalRawDataCollections.h>
0021 #include <TBDataFormats/EcalTBObjects/interface/EcalTBCollections.h>
0022 #include <DataFormats/Common/interface/Handle.h>
0023 #include <FWCore/Framework/interface/Event.h>
0024 #include <FWCore/ParameterSet/interface/FileInPath.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 0
0032 #define BEG_DCC_FED_ID_GLOBAL 0
0033 #define END_DCC_FED_ID_GLOBAL 0
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 EcalDCCTB07UnpackingModule::EcalDCCTB07UnpackingModule(const edm::ParameterSet& pset)
0041     : fedRawDataCollectionTag_(pset.getParameter<edm::InputTag>("fedRawDataCollectionTag")) {
0042   std::string tbName = pset.getUntrackedParameter<std::string>("tbName", std::string("h2"));
0043 
0044   ProduceEEDigis_ = pset.getUntrackedParameter<bool>("produceEEdigi", true);
0045   ProduceEBDigis_ = pset.getUntrackedParameter<bool>("produceEBdigi", false);
0046 
0047   // index of crystal <-> tower ID (DQM plots) position <-> stripIDs <-> channelIDs for the test beam (2007)
0048   std::vector<int> ics = pset.getUntrackedParameter<std::vector<int> >("ics", std::vector<int>());
0049   std::vector<int> towerIDs = pset.getUntrackedParameter<std::vector<int> >("towerIDs", std::vector<int>());
0050   std::vector<int> stripIDs = pset.getUntrackedParameter<std::vector<int> >("stripIDs", std::vector<int>());
0051   std::vector<int> channelIDs = pset.getUntrackedParameter<std::vector<int> >("channelIDs", std::vector<int>());
0052 
0053   // status id <-> tower CCU ID <-> DQM plots position mapping for the test beam (2007)
0054   std::vector<int> statusIDs = pset.getUntrackedParameter<std::vector<int> >("statusIDs", std::vector<int>());
0055   std::vector<int> ccuIDs = pset.getUntrackedParameter<std::vector<int> >("ccuIDs", std::vector<int>());
0056   std::vector<int> positionIDs = pset.getUntrackedParameter<std::vector<int> >("positionIDs", std::vector<int>());
0057 
0058   // check if vectors are filled
0059   if (ics.empty() || towerIDs.empty() || stripIDs.empty() || channelIDs.empty()) {
0060     edm::LogError("EcalDCCTB07UnpackingModule")
0061         << "Some of the mapping info is missing! Check config files! "
0062         << " Size of IC vector is " << ics.size() << " Size of Tower ID vector is " << towerIDs.size()
0063         << " Size of Strip ID vector is " << stripIDs.size() << " Size of Channel ID vector is " << channelIDs.size();
0064   }
0065   if (statusIDs.empty() || ccuIDs.empty() || positionIDs.empty()) {
0066     edm::LogError("EcalDCCTB07UnpackingModule")
0067         << "Some of the mapping info is missing! Check config files! "
0068         << " Size of status ID vector is " << statusIDs.size() << " Size of ccu ID vector is " << ccuIDs.size()
0069         << " positionIDs size is " << positionIDs.size();
0070   }
0071 
0072   // check if vectors have the same size
0073   if (ics.size() != towerIDs.size() || ics.size() != stripIDs.size() || ics.size() != channelIDs.size() ||
0074       towerIDs.size() != stripIDs.size() || towerIDs.size() != channelIDs.size() ||
0075       stripIDs.size() != channelIDs.size())
0076     edm::LogError("EcalDCCTB07UnpackingModule")
0077         << "Mapping information is corrupted. "
0078         << "Tower/DQM position/strip/channel vectors are of different size! Check cfi files! \n"
0079         << " Size of IC vector is " << ics.size() << " Size of Tower ID vector is " << towerIDs.size()
0080         << " Size of Strip ID vector is " << stripIDs.size() << " Size of Channel ID vector is " << channelIDs.size();
0081 
0082   if (statusIDs.size() != ccuIDs.size() || statusIDs.size() != positionIDs.size() ||
0083       ccuIDs.size() != positionIDs.size())
0084     edm::LogError("EcalDCCTB07UnpackingModule")
0085         << "Mapping information is corrupted. "
0086         << "Status/CCU ID/DQM position vectors are of different size! Check cfi files! \n"
0087         << " Size of status ID vector is " << statusIDs.size() << " Size of ccu ID vector is " << ccuIDs.size()
0088         << " positionIDs size is " << positionIDs.size();
0089 
0090   int cryIcMap[68][5][5];
0091   int tbStatusToLocation[71];
0092   int tbTowerIDToLocation[201];
0093   for (unsigned it = 1; it <= 68; ++it)
0094     for (unsigned is = 1; is <= 5; ++is)
0095       for (unsigned ic = 1; ic <= 5; ++ic)
0096         cryIcMap[it - 1][is - 1][ic - 1] = 1700;
0097 
0098   for (unsigned it = 1; it <= 71; ++it)
0099     tbStatusToLocation[it - 1] = it - 1;
0100 
0101   for (unsigned it = 1; it <= 201; ++it)
0102     tbTowerIDToLocation[it - 1] = it - 1;
0103 
0104   // Fill the cry IC map
0105   for (unsigned int i = 0; i < ics.size(); ++i) {
0106     int tower = towerIDs[i];
0107     int strip = stripIDs[i];
0108     int channel = channelIDs[i];
0109     int ic = ics[i];
0110     cryIcMap[tower - 1][strip - 1][channel - 1] = ic;
0111   }
0112   for (unsigned int i = 0; i < statusIDs.size(); ++i) {
0113     int is = statusIDs[i];
0114     int it = ccuIDs[i];
0115     int itEB = positionIDs[i];
0116 
0117     tbStatusToLocation[is] = itEB;
0118     tbTowerIDToLocation[it] = itEB;
0119   }
0120 
0121   formatter_ = new EcalTB07DaqFormatter(tbName, cryIcMap, tbStatusToLocation, tbTowerIDToLocation);
0122   ecalSupervisorFormatter_ = new EcalSupervisorTBDataFormatter();
0123   camacTBformatter_ = new CamacTBDataFormatter();
0124   tableFormatter_ = new TableDataFormatter();
0125   matacqFormatter_ = new MatacqTBDataFormatter();
0126 
0127   // digis
0128   produces<EBDigiCollection>("ebDigis");
0129   produces<EEDigiCollection>("eeDigis");
0130   produces<EcalMatacqDigiCollection>();
0131   produces<EcalPnDiodeDigiCollection>();
0132   produces<EcalRawDataCollection>();
0133   produces<EcalTrigPrimDigiCollection>("EBTT");
0134 
0135   //TB specifics data
0136   produces<EcalTBHodoscopeRawInfo>();
0137   produces<EcalTBTDCRawInfo>();
0138   produces<EcalTBEventHeader>();
0139 
0140   // crystals' integrity
0141   produces<EBDetIdCollection>("EcalIntegrityDCCSizeErrors");
0142   produces<EcalElectronicsIdCollection>("EcalIntegrityTTIdErrors");
0143   produces<EcalElectronicsIdCollection>("EcalIntegrityBlockSizeErrors");
0144   produces<EBDetIdCollection>("EcalIntegrityChIdErrors");
0145   produces<EBDetIdCollection>("EcalIntegrityGainErrors");
0146   produces<EBDetIdCollection>("EcalIntegrityGainSwitchErrors");
0147 
0148   // mem channels' integrity
0149   produces<EcalElectronicsIdCollection>("EcalIntegrityMemTtIdErrors");
0150   produces<EcalElectronicsIdCollection>("EcalIntegrityMemBlockSize");
0151   produces<EcalElectronicsIdCollection>("EcalIntegrityMemChIdErrors");
0152   produces<EcalElectronicsIdCollection>("EcalIntegrityMemGainErrors");
0153 }
0154 
0155 EcalDCCTB07UnpackingModule::~EcalDCCTB07UnpackingModule() { delete formatter_; }
0156 
0157 void EcalDCCTB07UnpackingModule::produce(edm::Event& e, const edm::EventSetup& c) {
0158   edm::Handle<FEDRawDataCollection> rawdata;
0159   e.getByLabel(fedRawDataCollectionTag_, rawdata);
0160 
0161   // create the collection of Ecal Digis
0162   auto productEb = std::make_unique<EBDigiCollection>();
0163 
0164   // YM create the collection of Ecal Endcap Digis
0165   auto productEe = std::make_unique<EEDigiCollection>();
0166 
0167   // create the collection of Matacq Digi
0168   auto productMatacq = std::make_unique<EcalMatacqDigiCollection>();
0169 
0170   // create the collection of Ecal PN's
0171   auto productPN = std::make_unique<EcalPnDiodeDigiCollection>();
0172 
0173   //create the collection of Ecal DCC Header
0174   auto productDCCHeader = std::make_unique<EcalRawDataCollection>();
0175 
0176   // create the collection with trigger primitives, bits and flags
0177   auto productTriggerPrimitives = std::make_unique<EcalTrigPrimDigiCollection>();
0178 
0179   // create the collection of Ecal Integrity DCC Size
0180   auto productDCCSize = std::make_unique<EBDetIdCollection>();
0181 
0182   // create the collection of Ecal Integrity TT Id
0183   auto productTTId = std::make_unique<EcalElectronicsIdCollection>();
0184 
0185   // create the collection of Ecal Integrity TT Block Size
0186   auto productBlockSize = std::make_unique<EcalElectronicsIdCollection>();
0187 
0188   // create the collection of Ecal Integrity Ch Id
0189   auto productChId = std::make_unique<EBDetIdCollection>();
0190 
0191   // create the collection of Ecal Integrity Gain
0192   auto productGain = std::make_unique<EBDetIdCollection>();
0193 
0194   // create the collection of Ecal Integrity Gain Switch
0195   auto productGainSwitch = std::make_unique<EBDetIdCollection>();
0196 
0197   // create the collection of Ecal Integrity Mem towerBlock_id errors
0198   auto productMemTtId = std::make_unique<EcalElectronicsIdCollection>();
0199 
0200   // create the collection of Ecal Integrity Mem gain errors
0201   auto productMemBlockSize = std::make_unique<EcalElectronicsIdCollection>();
0202 
0203   // create the collection of Ecal Integrity Mem gain errors
0204   auto productMemGain = std::make_unique<EcalElectronicsIdCollection>();
0205 
0206   // create the collection of Ecal Integrity Mem ch_id errors
0207   auto productMemChIdErrors = std::make_unique<EcalElectronicsIdCollection>();
0208 
0209   // create the collection of TB specifics data
0210   auto productHodo = std::make_unique<EcalTBHodoscopeRawInfo>();
0211   auto productTdc = std::make_unique<EcalTBTDCRawInfo>();
0212   auto productHeader = std::make_unique<EcalTBEventHeader>();
0213 
0214   try {
0215     for (int id = 0; id <= FEDNumbering::MAXFEDID; ++id) {
0216       //    edm::LogInfo("EcalDCCTB07UnpackingModule") << "EcalDCCTB07UnpackingModule::Got FED ID "<< id <<" ";
0217       const FEDRawData& data = rawdata->FEDData(id);
0218       //    edm::LogInfo("EcalDCCTB07UnpackingModule") << " Fed data size " << data.size() ;
0219 
0220       //std::cout <<"1 Fed id: "<<dec<<id<< " Fed data size: " <<data.size() << std::endl;
0221       //    const unsigned char * pData = data.data();
0222       //    int length = data.size();
0223       //    if(length >0 ){
0224       //      if(length >= 40){length = 40;}
0225       //    std::cout<<"##############################################################"<<std::endl;
0226       //    for( int i=0; i<length; i++ ) {
0227       //      std::cout << std::hex << std::setw(8) << int(pData[i]) << " ";
0228       //      if( (i+1)%8 == 0 ) std::cout << std::endl;
0229       //     }
0230       //    std::cout<<"##############################################################"<<std::endl;
0231       //    }
0232       if (data.size() > 16) {
0233         if ((id >= BEG_DCC_FED_ID && id <= END_DCC_FED_ID) ||
0234             (BEG_DCC_FED_ID_GLOBAL <= id &&
0235              id <= END_DCC_FED_ID_GLOBAL)) {  // do the DCC data unpacking and fill the collections
0236 
0237           (*productHeader).setSmInBeam(id);
0238           // YM add productEe to the list of arguments of the formatter
0239           formatter_->interpretRawData(data,
0240                                        *productEb,
0241                                        *productEe,
0242                                        *productPN,
0243                                        *productDCCHeader,
0244                                        *productDCCSize,
0245                                        *productTTId,
0246                                        *productBlockSize,
0247                                        *productChId,
0248                                        *productGain,
0249                                        *productGainSwitch,
0250                                        *productMemTtId,
0251                                        *productMemBlockSize,
0252                                        *productMemGain,
0253                                        *productMemChIdErrors,
0254                                        *productTriggerPrimitives);
0255           int runType = (*productDCCHeader)[0].getRunType();
0256           if (runType == EcalDCCHeaderBlock::COSMIC || runType == EcalDCCHeaderBlock::BEAMH4)
0257             (*productHeader).setTriggerMask(0x1);
0258           else if (runType == 4 || runType == 5 || runType == 6)  //laser runs
0259             (*productHeader).setTriggerMask(0x2000);
0260           else if (runType == 9 || runType == 10 || runType == 11)  //pedestal runs
0261             (*productHeader).setTriggerMask(0x800);
0262           LogDebug("EcalDCCTB07UnpackingModule")
0263               << "Event type is " << (*productHeader).eventType() << " dbEventType " << (*productHeader).dbEventType();
0264         } else if (id == ECAL_SUPERVISOR_FED_ID)
0265           ecalSupervisorFormatter_->interpretRawData(data, *productHeader);
0266         else if (id == TBCAMAC_FED_ID)
0267           camacTBformatter_->interpretRawData(data, *productHeader, *productHodo, *productTdc);
0268         else if (id == TABLE_FED_ID)
0269           tableFormatter_->interpretRawData(data, *productHeader);
0270         else if (id == MATACQ_FED_ID)
0271           matacqFormatter_->interpretRawData(data, *productMatacq);
0272       }  // endif
0273     }    //endfor
0274 
0275     // commit to the event
0276     e.put(std::move(productPN));
0277     if (ProduceEBDigis_)
0278       e.put(std::move(productEb), "ebDigis");
0279     if (ProduceEEDigis_)
0280       e.put(std::move(productEe), "eeDigis");
0281     e.put(std::move(productMatacq));
0282     e.put(std::move(productDCCHeader));
0283     e.put(std::move(productTriggerPrimitives), "EBTT");
0284 
0285     if (ProduceEBDigis_)
0286       e.put(std::move(productDCCSize), "EcalIntegrityDCCSizeErrors");
0287     if (ProduceEBDigis_)
0288       e.put(std::move(productTTId), "EcalIntegrityTTIdErrors");
0289     if (ProduceEBDigis_)
0290       e.put(std::move(productBlockSize), "EcalIntegrityBlockSizeErrors");
0291     if (ProduceEBDigis_)
0292       e.put(std::move(productChId), "EcalIntegrityChIdErrors");
0293     if (ProduceEBDigis_)
0294       e.put(std::move(productGain), "EcalIntegrityGainErrors");
0295     if (ProduceEBDigis_)
0296       e.put(std::move(productGainSwitch), "EcalIntegrityGainSwitchErrors");
0297 
0298     if (ProduceEBDigis_)
0299       e.put(std::move(productMemTtId), "EcalIntegrityMemTtIdErrors");
0300     if (ProduceEBDigis_)
0301       e.put(std::move(productMemBlockSize), "EcalIntegrityMemBlockSize");
0302     if (ProduceEBDigis_)
0303       e.put(std::move(productMemChIdErrors), "EcalIntegrityMemChIdErrors");
0304     if (ProduceEBDigis_)
0305       e.put(std::move(productMemGain), "EcalIntegrityMemGainErrors");
0306 
0307     e.put(std::move(productHodo));
0308     e.put(std::move(productTdc));
0309     e.put(std::move(productHeader));
0310 
0311   } catch (ECALTBParserException& e) {
0312     std::cout << "[EcalDCCTB07UnpackingModule] " << e.what() << std::endl;
0313   } catch (ECALTBParserBlockException& e) {
0314     std::cout << "[EcalDCCTB07UnpackingModule] " << e.what() << std::endl;
0315   } catch (cms::Exception& e) {
0316     std::cout << "[EcalDCCTB07UnpackingModule] " << e.what() << std::endl;
0317   } catch (...) {
0318     std::cout << "[EcalDCCTB07UnpackingModule] Unknown exception ..." << std::endl;
0319   }
0320 }