Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:14:49

0001 // -*- C++ -*-
0002 //
0003 // Package:    EcalDigiToRaw
0004 // Class:      EcalDigiToRaw
0005 //
0006 /**\class EcalDigiToRaw EcalDigiToRaw.cc EventFilter/EcalDigiToRaw/src/EcalDigiToRaw.cc
0007 
0008  Description: <one line class summary>
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Emmanuelle Perez
0015 //         Created:  Sat Nov 25 13:59:51 CET 2006
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 #include <iostream>
0022 #include <string>
0023 
0024 // user include files
0025 #include "FWCore/Framework/interface/Frameworkfwd.h"
0026 #include "FWCore/Framework/interface/global/EDProducer.h"
0027 
0028 #include "FWCore/Framework/interface/Event.h"
0029 #include "FWCore/Framework/interface/MakerMacros.h"
0030 
0031 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0032 #include "FWCore/Utilities/interface/ESGetToken.h"
0033 
0034 #include "EventFilter/EcalDigiToRaw/interface/TowerBlockFormatter.h"
0035 #include "EventFilter/EcalDigiToRaw/interface/TCCBlockFormatter.h"
0036 #include "EventFilter/EcalDigiToRaw/interface/BlockFormatter.h"
0037 #include "EventFilter/EcalDigiToRaw/interface/SRBlockFormatter.h"
0038 
0039 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
0040 #include "DataFormats/EcalDigi/interface/EcalSrFlag.h"
0041 
0042 #include "DataFormats/EcalDetId/interface/EcalDetIdCollections.h"
0043 
0044 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0045 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
0046 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0047 
0048 #include "DataFormats/Common/interface/Handle.h"
0049 #include "FWCore/Framework/interface/EventSetup.h"
0050 #include "FWCore/Framework/interface/ESHandle.h"
0051 
0052 #include "Geometry/EcalMapping/interface/EcalElectronicsMapping.h"
0053 #include "Geometry/EcalMapping/interface/EcalMappingRcd.h"
0054 
0055 class EcalDigiToRaw : public edm::global::EDProducer<> {
0056 public:
0057   EcalDigiToRaw(const edm::ParameterSet& pset);
0058 
0059   void produce(edm::StreamID, edm::Event& e, const edm::EventSetup& c) const override;
0060 
0061   typedef long long Word64;
0062   typedef unsigned int Word32;
0063 
0064   static const int BXMAX = 2808;
0065 
0066 private:
0067   // ----------member data ---------------------------
0068 
0069   edm::EDGetTokenT<EcalTrigPrimDigiCollection> labelTT_;
0070   edm::EDGetTokenT<EBSrFlagCollection> labelEBSR_;
0071   edm::EDGetTokenT<EESrFlagCollection> labelEESR_;
0072   edm::EDGetTokenT<EBDigiCollection> EBDigiToken_;
0073   edm::EDGetTokenT<EEDigiCollection> EEDigiToken_;
0074   edm::ESGetToken<EcalElectronicsMapping, EcalMappingRcd> ecalmappingToken_;
0075   edm::EDPutTokenT<FEDRawDataCollection> putToken_;
0076 
0077   const std::vector<int32_t> listDCCId_;
0078 
0079   const BlockFormatter::Config config_;
0080 };
0081 
0082 using namespace edm;
0083 using namespace std;
0084 
0085 EcalDigiToRaw::EcalDigiToRaw(const edm::ParameterSet& iConfig)
0086     : listDCCId_{iConfig.getUntrackedParameter<std::vector<int32_t> >("listDCCId")},
0087       config_{&listDCCId_,
0088               iConfig.getUntrackedParameter<bool>("debug"),
0089               iConfig.getUntrackedParameter<bool>("DoBarrel"),
0090               iConfig.getUntrackedParameter<bool>("DoEndCap"),
0091               iConfig.getUntrackedParameter<bool>("WriteTCCBlock"),
0092               iConfig.getUntrackedParameter<bool>("WriteSRFlags"),
0093               iConfig.getUntrackedParameter<bool>("WriteTowerBlock")} {
0094   auto label = iConfig.getParameter<string>("Label");
0095   auto instanceNameEB = iConfig.getParameter<string>("InstanceEB");
0096   auto instanceNameEE = iConfig.getParameter<string>("InstanceEE");
0097 
0098   edm::InputTag EBlabel = edm::InputTag(label, instanceNameEB);
0099   edm::InputTag EElabel = edm::InputTag(label, instanceNameEE);
0100 
0101   EBDigiToken_ = consumes<EBDigiCollection>(EBlabel);
0102   EEDigiToken_ = consumes<EEDigiCollection>(EElabel);
0103 
0104   labelTT_ = consumes<EcalTrigPrimDigiCollection>(iConfig.getParameter<edm::InputTag>("labelTT"));
0105 
0106   labelEBSR_ = consumes<EBSrFlagCollection>(iConfig.getParameter<edm::InputTag>("labelEBSRFlags"));
0107   labelEESR_ = consumes<EESrFlagCollection>(iConfig.getParameter<edm::InputTag>("labelEESRFlags"));
0108   ecalmappingToken_ = esConsumes<EcalElectronicsMapping, EcalMappingRcd>();
0109 
0110   putToken_ = produces<FEDRawDataCollection>();
0111 }
0112 
0113 //
0114 // member functions
0115 //
0116 
0117 // ------------ method called to for each event  ------------
0118 void EcalDigiToRaw::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
0119   if (config_.debug_)
0120     cout << "Enter in EcalDigiToRaw::produce ... " << endl;
0121 
0122   ESHandle<EcalElectronicsMapping> ecalmapping = iSetup.getHandle(ecalmappingToken_);
0123   const EcalElectronicsMapping* TheMapping = ecalmapping.product();
0124 
0125   FEDRawDataCollection productRawData;
0126 
0127   BlockFormatter::Params params;
0128   int counter = iEvent.id().event();
0129   params.counter_ = counter;
0130   params.orbit_number_ = iEvent.orbitNumber();
0131   params.bx_ = iEvent.bunchCrossing();
0132   params.lv1_ = counter % (0x1 << 24);
0133   params.runnumber_ = iEvent.id().run();
0134 
0135   BlockFormatter Headerblockformatter(config_, params);
0136   TCCBlockFormatter TCCblockformatter(config_, params);
0137   TowerBlockFormatter Towerblockformatter(config_, params);
0138   SRBlockFormatter SRblockformatter(config_, params);
0139 
0140   Headerblockformatter.DigiToRaw(&productRawData);
0141 
0142   // ---------   Now the Trigger Block part
0143 
0144   Handle<EcalTrigPrimDigiCollection> ecalTrigPrim;
0145 
0146   Handle<EBSrFlagCollection> ebSrFlags;
0147   Handle<EESrFlagCollection> eeSrFlags;
0148 
0149   if (config_.doTCC_) {
0150     if (config_.debug_)
0151       cout << "Creation of the TCC block  " << endl;
0152     // iEvent.getByType(ecalTrigPrim);
0153     iEvent.getByToken(labelTT_, ecalTrigPrim);
0154 
0155     // loop on TP's and add one by one to the block
0156     for (EcalTrigPrimDigiCollection::const_iterator it = ecalTrigPrim->begin(); it != ecalTrigPrim->end(); it++) {
0157       const EcalTriggerPrimitiveDigi& trigprim = *it;
0158       const EcalTrigTowerDetId& detid = it->id();
0159 
0160       if ((detid.subDet() == EcalBarrel) && (!config_.doBarrel_))
0161         continue;
0162       if ((detid.subDet() == EcalEndcap) && (!config_.doEndCap_))
0163         continue;
0164 
0165       int iDCC = TheMapping->DCCid(detid);
0166       int FEDid = FEDNumbering::MINECALFEDID + iDCC;
0167 
0168       FEDRawData& rawdata = productRawData.FEDData(FEDid);
0169 
0170       // adding the primitive to the block
0171       TCCblockformatter.DigiToRaw(trigprim, rawdata, TheMapping);
0172 
0173     }  // end loop on ecalTrigPrim
0174 
0175   }  // endif doTCC
0176 
0177   if (config_.doSR_) {
0178     if (config_.debug_)
0179       cout << " Process the SR flags " << endl;
0180 
0181     if (config_.doBarrel_) {
0182       // iEvent.getByType(ebSrFlags);
0183       iEvent.getByToken(labelEBSR_, ebSrFlags);
0184 
0185       for (EBSrFlagCollection::const_iterator it = ebSrFlags->begin(); it != ebSrFlags->end(); it++) {
0186         const EcalSrFlag& srflag = *it;
0187         int flag = srflag.value();
0188 
0189         EcalTrigTowerDetId id = srflag.id();
0190         int Dccid = TheMapping->DCCid(id);
0191         int DCC_Channel = TheMapping->iTT(id);
0192         int FEDid = FEDNumbering::MINECALFEDID + Dccid;
0193         // if (Dccid == 10) cout << "Dcc " << Dccid << " DCC_Channel " << DCC_Channel << " flag " << flag << endl;
0194         if (config_.debug_)
0195           cout << "will process SRblockformatter_ for FEDid " << dec << FEDid << endl;
0196         FEDRawData& rawdata = productRawData.FEDData(FEDid);
0197         if (config_.debug_)
0198           Headerblockformatter.print(rawdata);
0199         SRblockformatter.DigiToRaw(Dccid, DCC_Channel, flag, rawdata);
0200       }
0201     }  // end DoBarrel
0202 
0203     if (config_.doEndCap_) {
0204       // iEvent.getByType(eeSrFlags);
0205       iEvent.getByToken(labelEESR_, eeSrFlags);
0206 
0207       for (EESrFlagCollection::const_iterator it = eeSrFlags->begin(); it != eeSrFlags->end(); it++) {
0208         const EcalSrFlag& srflag = *it;
0209         int flag = srflag.value();
0210         EcalScDetId id = srflag.id();
0211         pair<int, int> ind = TheMapping->getDCCandSC(id);
0212         int Dccid = ind.first;
0213         int DCC_Channel = ind.second;
0214 
0215         int FEDid = FEDNumbering::MINECALFEDID + Dccid;
0216         FEDRawData& rawdata = productRawData.FEDData(FEDid);
0217         SRblockformatter.DigiToRaw(Dccid, DCC_Channel, flag, rawdata);
0218       }
0219     }  // end doEndCap
0220 
0221   }  // endif doSR
0222 
0223   // ---------  Now the Tower Block part
0224 
0225   Handle<EBDigiCollection> ebDigis;
0226   Handle<EEDigiCollection> eeDigis;
0227 
0228   if (config_.doTower_) {
0229     if (config_.doBarrel_) {
0230       if (config_.debug_)
0231         cout << "Creation of the TowerBlock ... Barrel case " << endl;
0232       iEvent.getByToken(EBDigiToken_, ebDigis);
0233       for (EBDigiCollection::const_iterator it = ebDigis->begin(); it != ebDigis->end(); it++) {
0234         const EBDataFrame& dataframe = *it;
0235         const EBDetId& ebdetid = it->id();
0236         int DCCid = TheMapping->DCCid(ebdetid);
0237         int FEDid = FEDNumbering::MINECALFEDID + DCCid;
0238         FEDRawData& rawdata = productRawData.FEDData(FEDid);
0239         Towerblockformatter.DigiToRaw(dataframe, rawdata, TheMapping);
0240       }
0241     }
0242 
0243     if (config_.doEndCap_) {
0244       if (config_.debug_)
0245         cout << "Creation of the TowerBlock ... EndCap case " << endl;
0246       iEvent.getByToken(EEDigiToken_, eeDigis);
0247       for (EEDigiCollection::const_iterator it = eeDigis->begin(); it != eeDigis->end(); it++) {
0248         const EEDataFrame& dataframe = *it;
0249         const EEDetId& eedetid = it->id();
0250         EcalElectronicsId elid = TheMapping->getElectronicsId(eedetid);
0251         int DCCid = elid.dccId();
0252         int FEDid = FEDNumbering::MINECALFEDID + DCCid;
0253         FEDRawData& rawdata = productRawData.FEDData(FEDid);
0254         Towerblockformatter.DigiToRaw(dataframe, rawdata, TheMapping);
0255       }
0256     }
0257 
0258   }  // endif config_.doTower_
0259 
0260   // -------- Clean up things ...
0261 
0262   map<int, map<int, int> >& FEDorder = Towerblockformatter.GetFEDorder();
0263 
0264   Headerblockformatter.CleanUp(&productRawData, &FEDorder);
0265 
0266   /*
0267    cout << "For FED 633 " << endl;
0268          FEDRawData& rawdata = productRawData -> FEDData(633);
0269          Headerblockformatter_ -> print(rawdata);
0270 */
0271 
0272   // Headerblockformatter_ -> PrintSizes(productRawData.get());
0273 
0274   Towerblockformatter.EndEvent(&productRawData);
0275 
0276   iEvent.emplace(putToken_, std::move(productRawData));
0277 
0278   return;
0279 }
0280 
0281 DEFINE_FWK_MODULE(EcalDigiToRaw);