Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-02-28 01:32:08

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