Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-01-13 02:34:55

0001 // system include files
0002 #include <memory>
0003 
0004 // user include files
0005 #include "FWCore/Framework/interface/Frameworkfwd.h"
0006 #include "FWCore/Framework/interface/stream/EDProducer.h"
0007 #include "FWCore/Framework/interface/Event.h"
0008 
0009 #include "FWCore/Utilities/interface/ESInputTag.h"
0010 #include "FWCore/Utilities/interface/Transition.h"
0011 
0012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0013 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0014 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0015 
0016 #include "DataFormats/NanoAOD/interface/FlatTable.h"
0017 
0018 #include "EventFilter/HcalRawToDigi/interface/HcalUHTRData.h"
0019 #include "EventFilter/HcalRawToDigi/interface/AMC13Header.h"
0020 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0021 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0022 #include <iostream>
0023 
0024 class HcalUHTRTableProducer : public edm::stream::EDProducer<> {
0025 private:
0026   edm::EDGetTokenT<FEDRawDataCollection> tokenRaw_;
0027   edm::InputTag tagRaw_;
0028   std::vector<int> fedUnpackList_;
0029 
0030 public:
0031   explicit HcalUHTRTableProducer(const edm::ParameterSet& iConfig)
0032       : tagRaw_(iConfig.getParameter<edm::InputTag>("InputLabel")),
0033         fedUnpackList_(iConfig.getUntrackedParameter<std::vector<int>>("FEDs", std::vector<int>())) {
0034     tokenRaw_ = consumes<FEDRawDataCollection>(tagRaw_);
0035     produces<nanoaod::FlatTable>("uHTRTable");
0036 
0037     if (fedUnpackList_.empty()) {
0038       // VME range for back-compatibility
0039       for (int i = FEDNumbering::MINHCALFEDID; i <= FEDNumbering::MAXHCALFEDID; i++)
0040         fedUnpackList_.push_back(i);
0041 
0042       // uTCA range
0043       for (int i = FEDNumbering::MINHCALuTCAFEDID; i <= FEDNumbering::MAXHCALuTCAFEDID; i++)
0044         fedUnpackList_.push_back(i);
0045     }
0046   }
0047 
0048   ~HcalUHTRTableProducer() override{};
0049 
0050   /*
0051     static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0052         edm::ParameterSetDescription desc;
0053         desc.add<edm::InputTag>("tagUHTR")->setComment("Input uMNio digi collection");
0054         descriptions.add("HcalUHTRTable", desc);
0055     }
0056     */
0057 
0058 private:
0059   void produce(edm::Event&, edm::EventSetup const&) override;
0060 };
0061 
0062 void HcalUHTRTableProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0063   std::vector<int> crate;
0064   std::vector<int> slot;
0065   std::vector<uint32_t> evn;
0066   std::vector<uint32_t> bcn;
0067   std::vector<uint32_t> orn;
0068   std::vector<int> eventType;
0069 
0070   edm::Handle<FEDRawDataCollection> raw;
0071   iEvent.getByToken(tokenRaw_, raw);
0072   for (std::vector<int>::const_iterator i = fedUnpackList_.begin(); i != fedUnpackList_.end(); i++) {
0073     const FEDRawData& fed = raw->FEDData(*i);
0074     hcal::AMC13Header const* hamc13 = (hcal::AMC13Header const*)fed.data();
0075     if (!hamc13) {
0076       continue;
0077     }
0078     int namc = hamc13->NAMC();
0079     for (int iamc = 0; iamc < namc; iamc++) {
0080       HcalUHTRData uhtr(hamc13->AMCPayload(iamc), hamc13->AMCSize(iamc));
0081       crate.push_back(uhtr.crateId());
0082       slot.push_back(uhtr.slot());
0083       evn.push_back(uhtr.l1ANumber());
0084       bcn.push_back(uhtr.bunchNumber());
0085       orn.push_back(uhtr.orbitNumber());
0086       eventType.push_back(uhtr.getEventType());
0087     }
0088   }
0089 
0090   auto uHTRNanoTable = std::make_unique<nanoaod::FlatTable>(crate.size(), "uHTR", false, false);
0091   uHTRNanoTable->addColumn<int>("crate", crate, "crate");
0092   uHTRNanoTable->addColumn<int>("slot", slot, "slot");
0093   uHTRNanoTable->addColumn<uint32_t>("evn", evn, "evn");
0094   uHTRNanoTable->addColumn<uint32_t>("bcn", bcn, "bcn");
0095   uHTRNanoTable->addColumn<uint32_t>("orn", orn, "orn");
0096   uHTRNanoTable->addColumn<int>("eventType", eventType, "eventType");
0097 
0098   iEvent.put(std::move(uHTRNanoTable), "uHTRTable");
0099 }
0100 
0101 #include "FWCore/Framework/interface/MakerMacros.h"
0102 //define this as a plug-in
0103 DEFINE_FWK_MODULE(HcalUHTRTableProducer);