Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-01-24 01:14:46

0001 // system include files
0002 #include <memory>
0003 
0004 // {fmt} headers
0005 #include <fmt/printf.h>
0006 
0007 // ROOT
0008 #include <TTree.h>
0009 
0010 // framework and data formats
0011 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0012 #include "CondFormats/DataRecord/interface/L1TUtmTriggerMenuRcd.h"
0013 #include "CondFormats/L1TObjects/interface/L1TUtmTriggerMenu.h"
0014 #include "DataFormats/L1TGlobal/interface/GlobalAlgBlk.h"
0015 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0016 #include "FWCore/Framework/interface/ESHandle.h"
0017 #include "FWCore/Framework/interface/Event.h"
0018 #include "FWCore/Framework/interface/EventSetup.h"
0019 #include "FWCore/Framework/interface/Frameworkfwd.h"
0020 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0021 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0022 #include "FWCore/ServiceRegistry/interface/Service.h"
0023 
0024 //
0025 // class declaration
0026 //
0027 
0028 class L1uGTTreeProducer : public edm::one::EDAnalyzer<edm::one::SharedResources> {
0029 public:
0030   explicit L1uGTTreeProducer(edm::ParameterSet const &);
0031   ~L1uGTTreeProducer() override = default;
0032 
0033 private:
0034   void beginJob() override;
0035   void analyze(edm::Event const &, edm::EventSetup const &) override;
0036   void endJob() override;
0037 
0038 private:
0039   // output file
0040   edm::Service<TFileService> fs_;
0041 
0042   // pointers to the objects that will be stored as branches within the tree
0043   GlobalAlgBlk const *results_;
0044 
0045   // tree
0046   TTree *tree_;
0047 
0048   // EDM input tokens
0049   const edm::EDGetTokenT<GlobalAlgBlkBxCollection> ugtToken_;
0050   const edm::ESGetToken<L1TUtmTriggerMenu, L1TUtmTriggerMenuRcd> l1GtMenuToken_;
0051 
0052   // L1 uGT menu
0053   unsigned long long cache_id_;
0054 };
0055 
0056 L1uGTTreeProducer::L1uGTTreeProducer(edm::ParameterSet const &config)
0057     : results_(nullptr),
0058       tree_(nullptr),
0059       ugtToken_(consumes<GlobalAlgBlkBxCollection>(config.getParameter<edm::InputTag>("ugtToken"))),
0060       l1GtMenuToken_(esConsumes<L1TUtmTriggerMenu, L1TUtmTriggerMenuRcd>()),
0061       cache_id_(0) {
0062   usesResource(TFileService::kSharedResource);
0063   // set up the TTree and its branches
0064   tree_ = fs_->make<TTree>("L1uGTTree", "L1uGTTree");
0065   tree_->Branch("L1uGT", "GlobalAlgBlk", &results_, 32000, 3);
0066 }
0067 
0068 //
0069 // member functions
0070 //
0071 
0072 // ------------ method called to for each event  ------------
0073 void L1uGTTreeProducer::analyze(edm::Event const &event, edm::EventSetup const &setup) {
0074   unsigned long long id = setup.get<L1TUtmTriggerMenuRcd>().cacheIdentifier();
0075   if (id != cache_id_) {
0076     cache_id_ = id;
0077     edm::ESHandle<L1TUtmTriggerMenu> menu;
0078     menu = setup.getHandle(l1GtMenuToken_);
0079 
0080     for (auto const &keyval : menu->getAlgorithmMap()) {
0081       std::string const &name = keyval.second.getName();
0082       unsigned int index = keyval.second.getIndex();
0083       //std::cerr << fmt::sprintf("bit %4d: %s", index, name) << std::endl;
0084       tree_->SetAlias(name.c_str(), fmt::sprintf("L1uGT.m_algoDecisionInitial[%d]", index).c_str());
0085     }
0086   }
0087 
0088   edm::Handle<GlobalAlgBlkBxCollection> ugt;
0089   event.getByToken(ugtToken_, ugt);
0090   if (ugt.isValid()) {
0091     results_ = &ugt->at(0, 0);
0092   }
0093 
0094   tree_->Fill();
0095 }
0096 
0097 // ------------ method called once each job just before starting event loop  ------------
0098 void L1uGTTreeProducer::beginJob(void) {}
0099 
0100 // ------------ method called once each job just after ending the event loop  ------------
0101 void L1uGTTreeProducer::endJob() {}
0102 
0103 //define this as a plug-in
0104 #include "FWCore/Framework/interface/MakerMacros.h"
0105 DEFINE_FWK_MODULE(L1uGTTreeProducer);