Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-01-06 23:43:32

0001 // user include files
0002 #include "FWCore/Framework/interface/Frameworkfwd.h"
0003 #include "FWCore/Framework/interface/global/EDProducer.h"
0004 #include "FWCore/Framework/interface/Event.h"
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0007 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0008 
0009 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0010 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
0011 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0012 
0013 #include "EventFilter/RawDataCollector/interface/RawDataFEDSelector.h"
0014 
0015 class SubdetFEDSelector : public edm::global::EDProducer<> {
0016 public:
0017   SubdetFEDSelector(const edm::ParameterSet&);
0018   ~SubdetFEDSelector() override;
0019   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0020 
0021 private:
0022   void beginJob() override {}
0023   void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0024   void endJob() override {}
0025 
0026   // ----------member data ---------------------------
0027   const bool getEcal_;
0028   const bool getHcal_;
0029   const bool getStrip_;
0030   const bool getPixel_;
0031   const bool getMuon_;
0032   const bool getTrigger_;
0033 
0034   const edm::EDGetTokenT<FEDRawDataCollection> tok_raw_;
0035 };
0036 
0037 SubdetFEDSelector::SubdetFEDSelector(const edm::ParameterSet& iConfig)
0038     : getEcal_(iConfig.getParameter<bool>("getECAL")),
0039       getHcal_(iConfig.getParameter<bool>("getHCAL")),
0040       getStrip_(iConfig.getParameter<bool>("getSiStrip")),
0041       getPixel_(iConfig.getParameter<bool>("getSiPixel")),
0042       getMuon_(iConfig.getParameter<bool>("getMuon")),
0043       getTrigger_(iConfig.getParameter<bool>("getTrigger")),
0044       tok_raw_(consumes<FEDRawDataCollection>(iConfig.getParameter<edm::InputTag>("rawInputLabel"))) {
0045   produces<FEDRawDataCollection>();
0046 }
0047 
0048 SubdetFEDSelector::~SubdetFEDSelector() {}
0049 
0050 void SubdetFEDSelector::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
0051   auto producedData = std::make_unique<FEDRawDataCollection>();
0052 
0053   const edm::Handle<FEDRawDataCollection>& rawIn = iEvent.getHandle(tok_raw_);
0054 
0055   std::vector<int> selFEDs;
0056 
0057   if (getEcal_) {
0058     for (int i = FEDNumbering::MINECALFEDID; i <= FEDNumbering::MAXECALFEDID; i++) {
0059       selFEDs.push_back(i);
0060     }
0061     for (int i = FEDNumbering::MINPreShowerFEDID; i <= FEDNumbering::MAXPreShowerFEDID; i++) {
0062       selFEDs.push_back(i);
0063     }
0064   }
0065 
0066   if (getMuon_) {
0067     for (int i = FEDNumbering::MINCSCFEDID; i <= FEDNumbering::MAXCSCFEDID; i++) {
0068       selFEDs.push_back(i);
0069     }
0070     for (int i = FEDNumbering::MINCSCTFFEDID; i <= FEDNumbering::MAXCSCTFFEDID; i++) {
0071       selFEDs.push_back(i);
0072     }
0073     for (int i = FEDNumbering::MINDTFEDID; i <= FEDNumbering::MAXDTFEDID; i++) {
0074       selFEDs.push_back(i);
0075     }
0076     for (int i = FEDNumbering::MINDTTFFEDID; i <= FEDNumbering::MAXDTTFFEDID; i++) {
0077       selFEDs.push_back(i);
0078     }
0079     for (int i = FEDNumbering::MINRPCFEDID; i <= FEDNumbering::MAXRPCFEDID; i++) {
0080       selFEDs.push_back(i);
0081     }
0082     for (int i = FEDNumbering::MINCSCDDUFEDID; i <= FEDNumbering::MAXCSCDDUFEDID; i++) {
0083       selFEDs.push_back(i);
0084     }
0085     for (int i = FEDNumbering::MINCSCContingencyFEDID; i <= FEDNumbering::MAXCSCContingencyFEDID; i++) {
0086       selFEDs.push_back(i);
0087     }
0088     for (int i = FEDNumbering::MINCSCTFSPFEDID; i <= FEDNumbering::MAXCSCTFSPFEDID; i++) {
0089       selFEDs.push_back(i);
0090     }
0091   }
0092 
0093   if (getHcal_) {
0094     for (int i = FEDNumbering::MINHCALFEDID; i <= FEDNumbering::MAXHCALFEDID; i++) {
0095       selFEDs.push_back(i);
0096     }
0097   }
0098 
0099   if (getStrip_) {
0100     for (int i = FEDNumbering::MINSiStripFEDID; i <= FEDNumbering::MAXSiStripFEDID; i++) {
0101       selFEDs.push_back(i);
0102     }
0103   }
0104 
0105   if (getPixel_) {
0106     for (int i = FEDNumbering::MINSiPixelFEDID; i <= FEDNumbering::MAXSiPixelFEDID; i++) {
0107       selFEDs.push_back(i);
0108     }
0109   }
0110 
0111   if (getTrigger_) {
0112     for (int i = FEDNumbering::MINTriggerEGTPFEDID; i <= FEDNumbering::MAXTriggerEGTPFEDID; i++) {
0113       selFEDs.push_back(i);
0114     }
0115     for (int i = FEDNumbering::MINTriggerGTPFEDID; i <= FEDNumbering::MAXTriggerGTPFEDID; i++) {
0116       selFEDs.push_back(i);
0117     }
0118     for (int i = FEDNumbering::MINTriggerLTCFEDID; i <= FEDNumbering::MAXTriggerLTCFEDID; i++) {
0119       selFEDs.push_back(i);
0120     }
0121     for (int i = FEDNumbering::MINTriggerLTCmtccFEDID; i <= FEDNumbering::MAXTriggerLTCmtccFEDID; i++) {
0122       selFEDs.push_back(i);
0123     }
0124     for (int i = FEDNumbering::MINTriggerGCTFEDID; i <= FEDNumbering::MAXTriggerGCTFEDID; i++) {
0125       selFEDs.push_back(i);
0126     }
0127 
0128     for (int i = FEDNumbering::MINTriggerLTCTriggerFEDID; i <= FEDNumbering::MAXTriggerLTCTriggerFEDID; i++) {
0129       selFEDs.push_back(i);
0130     }
0131 
0132     for (int i = FEDNumbering::MINTriggerLTCHCALFEDID; i <= FEDNumbering::MAXTriggerLTCHCALFEDID; i++) {
0133       selFEDs.push_back(i);
0134     }
0135 
0136     for (int i = FEDNumbering::MINTriggerLTCSiStripFEDID; i <= FEDNumbering::MAXTriggerLTCSiStripFEDID; i++) {
0137       selFEDs.push_back(i);
0138     }
0139 
0140     for (int i = FEDNumbering::MINTriggerLTCECALFEDID; i <= FEDNumbering::MAXTriggerLTCECALFEDID; i++) {
0141       selFEDs.push_back(i);
0142     }
0143 
0144     for (int i = FEDNumbering::MINTriggerLTCTotemCastorFEDID; i <= FEDNumbering::MAXTriggerLTCTotemCastorFEDID; i++) {
0145       selFEDs.push_back(i);
0146     }
0147     for (int i = FEDNumbering::MINTriggerLTCRPCFEDID; i <= FEDNumbering::MAXTriggerLTCRPCFEDID; i++) {
0148       selFEDs.push_back(i);
0149     }
0150 
0151     for (int i = FEDNumbering::MINTriggerLTCCSCFEDID; i <= FEDNumbering::MAXTriggerLTCCSCFEDID; i++) {
0152       selFEDs.push_back(i);
0153     }
0154     for (int i = FEDNumbering::MINTriggerLTCDTFEDID; i <= FEDNumbering::MAXTriggerLTCDTFEDID; i++) {
0155       selFEDs.push_back(i);
0156     }
0157     for (int i = FEDNumbering::MINTriggerLTCSiPixelFEDID; i <= FEDNumbering::MAXTriggerLTCSiPixelFEDID; i++) {
0158       selFEDs.push_back(i);
0159     }
0160   }
0161 
0162   for (int i = FEDNumbering::MINDAQeFEDFEDID; i <= FEDNumbering::MAXDAQeFEDFEDID; i++) {
0163     selFEDs.push_back(i);
0164   }
0165 
0166   // Copying:
0167   const FEDRawDataCollection* rdc = rawIn.product();
0168 
0169   //   if ( ( rawData[i].provenance()->processName() != e.processHistory().rbegin()->processName() ) )
0170   //       continue ; // skip all raw collections not produced by the current process
0171 
0172   for (int j = 0; j <= FEDNumbering::MAXFEDID; ++j) {
0173     bool rightFED = false;
0174     for (uint32_t k = 0; k < selFEDs.size(); k++) {
0175       if (j == selFEDs[k]) {
0176         rightFED = true;
0177       }
0178     }
0179     if (!rightFED)
0180       continue;
0181     const FEDRawData& fedData = rdc->FEDData(j);
0182     size_t size = fedData.size();
0183 
0184     if (size > 0) {
0185       // this fed has data -- lets copy it
0186       FEDRawData& fedDataProd = producedData->FEDData(j);
0187       if (fedDataProd.size() != 0) {
0188         edm::LogVerbatim("HcalCalib") << " More than one FEDRawDataCollection with data in FED " << j
0189                                       << " Skipping the 2nd";
0190         continue;
0191       }
0192       fedDataProd.resize(size);
0193       unsigned char* dataProd = fedDataProd.data();
0194       const unsigned char* data = fedData.data();
0195       for (unsigned int k = 0; k < size; ++k) {
0196         dataProd[k] = data[k];
0197       }
0198     }
0199   }
0200 
0201   iEvent.put(std::move(producedData));
0202 }
0203 
0204 void SubdetFEDSelector::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0205   edm::ParameterSetDescription desc;
0206   desc.add<edm::InputTag>("rawInputLabel", edm::InputTag("rawDataCollector"));
0207   desc.add<bool>("getSiPixel", true);
0208   desc.add<bool>("getHCAL", true);
0209   desc.add<bool>("getECAL", false);
0210   desc.add<bool>("getMuon", false);
0211   desc.add<bool>("getTrigger", true);
0212   desc.add<bool>("getSiStrip", false);
0213   descriptions.add("subdetFED", desc);
0214 }
0215 
0216 #include "FWCore/PluginManager/interface/ModuleDef.h"
0217 #include "FWCore/Framework/interface/MakerMacros.h"
0218 
0219 DEFINE_FWK_MODULE(SubdetFEDSelector);