Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-24 04:40:28

0001 #include <utility>
0002 
0003 #include "DataFormats/EcalDetId/interface/EcalDetIdCollections.h"
0004 #include "DataFormats/EcalDigi/interface/EcalConstants.h"
0005 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
0006 #include "DataFormats/EcalDigi/interface/EcalDigiHostCollection.h"
0007 #include "DataFormats/EcalRawData/interface/EcalRawDataCollections.h"
0008 #include "FWCore/Framework/interface/Event.h"
0009 #include "FWCore/Framework/interface/EventSetup.h"
0010 #include "FWCore/Framework/interface/MakerMacros.h"
0011 #include "FWCore/Framework/interface/stream/EDProducer.h"
0012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0013 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0014 
0015 class EcalDigisFromPortableProducer : public edm::stream::EDProducer<> {
0016 public:
0017   explicit EcalDigisFromPortableProducer(edm::ParameterSet const& ps);
0018   ~EcalDigisFromPortableProducer() override = default;
0019   static void fillDescriptions(edm::ConfigurationDescriptions&);
0020 
0021 private:
0022   void produce(edm::Event&, edm::EventSetup const&) override;
0023 
0024   template <typename ProductType, typename... ARGS>
0025   edm::EDPutTokenT<ProductType> dummyProduces(ARGS&&... args) {
0026     return (produceDummyIntegrityCollections_) ? produces<ProductType>(std::forward<ARGS>(args)...)
0027                                                : edm::EDPutTokenT<ProductType>{};
0028   }
0029 
0030 private:
0031   // input digi collections on host in SoA format
0032   using InputProduct = EcalDigiHostCollection;
0033   edm::EDGetTokenT<InputProduct> digisInEBToken_;
0034   edm::EDGetTokenT<InputProduct> digisInEEToken_;
0035 
0036   // output digi collections in legacy format
0037   edm::EDPutTokenT<EBDigiCollection> digisOutEBToken_;
0038   edm::EDPutTokenT<EEDigiCollection> digisOutEEToken_;
0039 
0040   // whether to produce dummy integrity collections
0041   bool produceDummyIntegrityCollections_;
0042 
0043   // dummy producer collections
0044   edm::EDPutTokenT<EBSrFlagCollection> ebSrFlagToken_;
0045   edm::EDPutTokenT<EESrFlagCollection> eeSrFlagToken_;
0046 
0047   // dummy ECAL raw data collection
0048   edm::EDPutTokenT<EcalRawDataCollection> ecalRawDataToken_;
0049 
0050   // dummy integrity for xtal data
0051   edm::EDPutTokenT<EBDetIdCollection> ebIntegrityGainErrorsToken_;
0052   edm::EDPutTokenT<EBDetIdCollection> ebIntegrityGainSwitchErrorsToken_;
0053   edm::EDPutTokenT<EBDetIdCollection> ebIntegrityChIdErrorsToken_;
0054 
0055   // dummy integrity for xtal data - EE specific (to be rivisited towards EB+EE common collection)
0056   edm::EDPutTokenT<EEDetIdCollection> eeIntegrityGainErrorsToken_;
0057   edm::EDPutTokenT<EEDetIdCollection> eeIntegrityGainSwitchErrorsToken_;
0058   edm::EDPutTokenT<EEDetIdCollection> eeIntegrityChIdErrorsToken_;
0059 
0060   // dummy integrity errors
0061   edm::EDPutTokenT<EcalElectronicsIdCollection> integrityTTIdErrorsToken_;
0062   edm::EDPutTokenT<EcalElectronicsIdCollection> integrityZSXtalIdErrorsToken_;
0063   edm::EDPutTokenT<EcalElectronicsIdCollection> integrityBlockSizeErrorsToken_;
0064 
0065   edm::EDPutTokenT<EcalPnDiodeDigiCollection> pnDiodeDigisToken_;
0066 
0067   // dummy TCC collections
0068   edm::EDPutTokenT<EcalTrigPrimDigiCollection> ecalTriggerPrimitivesToken_;
0069   edm::EDPutTokenT<EcalPSInputDigiCollection> ecalPseudoStripInputsToken_;
0070 
0071   // dummy mem integrity collections
0072   edm::EDPutTokenT<EcalElectronicsIdCollection> ecalIntegrityMemTtIdErrorsToken_;
0073   edm::EDPutTokenT<EcalElectronicsIdCollection> ecalIntegrityMemBlockSizeErrorsToken_;
0074   edm::EDPutTokenT<EcalElectronicsIdCollection> ecalIntegrityMemChIdErrorsToken_;
0075   edm::EDPutTokenT<EcalElectronicsIdCollection> ecalIntegrityMemGainErrorsToken_;
0076 };
0077 
0078 void EcalDigisFromPortableProducer::fillDescriptions(edm::ConfigurationDescriptions& confDesc) {
0079   edm::ParameterSetDescription desc;
0080 
0081   desc.add<edm::InputTag>("digisInLabelEB", edm::InputTag{"ecalRawToDigiPortable", "ebDigis"});
0082   desc.add<edm::InputTag>("digisInLabelEE", edm::InputTag{"ecalRawToDigiPortable", "eeDigis"});
0083   desc.add<std::string>("digisOutLabelEB", "ebDigis");
0084   desc.add<std::string>("digisOutLabelEE", "eeDigis");
0085   desc.add<bool>("produceDummyIntegrityCollections", false);
0086 
0087   confDesc.add("ecalDigisFromPortableProducer", desc);
0088 }
0089 
0090 EcalDigisFromPortableProducer::EcalDigisFromPortableProducer(const edm::ParameterSet& ps)
0091     :  // input digi collections on host in SoA format
0092       digisInEBToken_{consumes(ps.getParameter<edm::InputTag>("digisInLabelEB"))},
0093       digisInEEToken_{consumes(ps.getParameter<edm::InputTag>("digisInLabelEE"))},
0094 
0095       // output digi collections in legacy format
0096       digisOutEBToken_{produces<EBDigiCollection>(ps.getParameter<std::string>("digisOutLabelEB"))},
0097       digisOutEEToken_{produces<EEDigiCollection>(ps.getParameter<std::string>("digisOutLabelEE"))},
0098 
0099       // whether to produce dummy integrity collections
0100       produceDummyIntegrityCollections_{ps.getParameter<bool>("produceDummyIntegrityCollections")},
0101 
0102       // dummy collections
0103       ebSrFlagToken_{dummyProduces<EBSrFlagCollection>()},
0104       eeSrFlagToken_{dummyProduces<EESrFlagCollection>()},
0105 
0106       // dummy ECAL raw data collection
0107       ecalRawDataToken_{dummyProduces<EcalRawDataCollection>()},
0108 
0109       // dummy integrity for xtal data
0110       ebIntegrityGainErrorsToken_{dummyProduces<EBDetIdCollection>("EcalIntegrityGainErrors")},
0111       ebIntegrityGainSwitchErrorsToken_{dummyProduces<EBDetIdCollection>("EcalIntegrityGainSwitchErrors")},
0112       ebIntegrityChIdErrorsToken_{dummyProduces<EBDetIdCollection>("EcalIntegrityChIdErrors")},
0113 
0114       // dummy integrity for xtal data - EE specific (to be rivisited towards EB+EE common collection)
0115       eeIntegrityGainErrorsToken_{dummyProduces<EEDetIdCollection>("EcalIntegrityGainErrors")},
0116       eeIntegrityGainSwitchErrorsToken_{dummyProduces<EEDetIdCollection>("EcalIntegrityGainSwitchErrors")},
0117       eeIntegrityChIdErrorsToken_{dummyProduces<EEDetIdCollection>("EcalIntegrityChIdErrors")},
0118 
0119       // dummy integrity errors
0120       integrityTTIdErrorsToken_{dummyProduces<EcalElectronicsIdCollection>("EcalIntegrityTTIdErrors")},
0121       integrityZSXtalIdErrorsToken_{dummyProduces<EcalElectronicsIdCollection>("EcalIntegrityZSXtalIdErrors")},
0122       integrityBlockSizeErrorsToken_{dummyProduces<EcalElectronicsIdCollection>("EcalIntegrityBlockSizeErrors")},
0123 
0124       //
0125       pnDiodeDigisToken_{dummyProduces<EcalPnDiodeDigiCollection>()},
0126 
0127       // dummy TCC collections
0128       ecalTriggerPrimitivesToken_{dummyProduces<EcalTrigPrimDigiCollection>("EcalTriggerPrimitives")},
0129       ecalPseudoStripInputsToken_{dummyProduces<EcalPSInputDigiCollection>("EcalPseudoStripInputs")},
0130 
0131       // dummy mem integrity collections
0132       ecalIntegrityMemTtIdErrorsToken_{dummyProduces<EcalElectronicsIdCollection>("EcalIntegrityMemTtIdErrors")},
0133       ecalIntegrityMemBlockSizeErrorsToken_{
0134           dummyProduces<EcalElectronicsIdCollection>("EcalIntegrityMemBlockSizeErrors")},
0135       ecalIntegrityMemChIdErrorsToken_{dummyProduces<EcalElectronicsIdCollection>("EcalIntegrityMemChIdErrors")},
0136       ecalIntegrityMemGainErrorsToken_{dummyProduces<EcalElectronicsIdCollection>("EcalIntegrityMemGainErrors")} {}
0137 
0138 void EcalDigisFromPortableProducer::produce(edm::Event& event, edm::EventSetup const& setup) {
0139   // output collections
0140   auto digisEB = std::make_unique<EBDigiCollection>();
0141   auto digisEE = std::make_unique<EEDigiCollection>();
0142 
0143   auto const& digisEBSoAHostColl = event.get(digisInEBToken_);
0144   auto const& digisEESoAHostColl = event.get(digisInEEToken_);
0145   auto& digisEBSoAView = digisEBSoAHostColl.view();
0146   auto& digisEESoAView = digisEESoAHostColl.view();
0147 
0148   auto const digisEBSize = digisEBSoAView.size();
0149   auto const digisEESize = digisEESoAView.size();
0150   auto const digisEBDataSize = digisEBSize * ecalPh1::sampleSize;
0151   auto const digisEEDataSize = digisEESize * ecalPh1::sampleSize;
0152 
0153   // Intermediate containers because the DigiCollection containers are accessible only as const
0154   EBDigiCollection::IdContainer digisIdsEB(digisEBSoAView.id(), digisEBSoAView.id() + digisEBSize);
0155   EEDigiCollection::IdContainer digisIdsEE(digisEESoAView.id(), digisEESoAView.id() + digisEESize);
0156   EBDigiCollection::DataContainer digisDataEB(digisEBSoAView.data()->data(),
0157                                               digisEBSoAView.data()->data() + digisEBDataSize);
0158   EEDigiCollection::DataContainer digisDataEE(digisEESoAView.data()->data(),
0159                                               digisEESoAView.data()->data() + digisEEDataSize);
0160 
0161   digisEB->swap(digisIdsEB, digisDataEB);
0162   digisEE->swap(digisIdsEE, digisDataEE);
0163 
0164   digisEB->sort();
0165   digisEE->sort();
0166 
0167   event.put(digisOutEBToken_, std::move(digisEB));
0168   event.put(digisOutEEToken_, std::move(digisEE));
0169 
0170   if (produceDummyIntegrityCollections_) {
0171     // dummy collections
0172     event.emplace(ebSrFlagToken_);
0173     event.emplace(eeSrFlagToken_);
0174     // dummy ECAL raw data collection
0175     event.emplace(ecalRawDataToken_);
0176     // dummy integrity for xtal data
0177     event.emplace(ebIntegrityGainErrorsToken_);
0178     event.emplace(ebIntegrityGainSwitchErrorsToken_);
0179     event.emplace(ebIntegrityChIdErrorsToken_);
0180     // dummy integrity for xtal data - EE specific (to be rivisited towards EB+EE common collection)
0181     event.emplace(eeIntegrityGainErrorsToken_);
0182     event.emplace(eeIntegrityGainSwitchErrorsToken_);
0183     event.emplace(eeIntegrityChIdErrorsToken_);
0184     // dummy integrity errors
0185     event.emplace(integrityTTIdErrorsToken_);
0186     event.emplace(integrityZSXtalIdErrorsToken_);
0187     event.emplace(integrityBlockSizeErrorsToken_);
0188     //
0189     event.emplace(pnDiodeDigisToken_);
0190     // dummy TCC collections
0191     event.emplace(ecalTriggerPrimitivesToken_);
0192     event.emplace(ecalPseudoStripInputsToken_);
0193     // dummy mem integrity collections
0194     event.emplace(ecalIntegrityMemTtIdErrorsToken_);
0195     event.emplace(ecalIntegrityMemBlockSizeErrorsToken_);
0196     event.emplace(ecalIntegrityMemChIdErrorsToken_);
0197     event.emplace(ecalIntegrityMemGainErrorsToken_);
0198   }
0199 }
0200 
0201 DEFINE_FWK_MODULE(EcalDigisFromPortableProducer);