CMS 3D CMS Logo

L1uGTTreeProducer.cc
Go to the documentation of this file.
1 // system include files
2 #include <memory>
3 
4 // {fmt} headers
5 #include <fmt/printf.h>
6 
7 // ROOT
8 #include <TTree.h>
9 
10 // framework and data formats
23 
24 //
25 // class declaration
26 //
27 
28 class L1uGTTreeProducer : public edm::one::EDAnalyzer<edm::one::SharedResources> {
29 public:
30  explicit L1uGTTreeProducer(edm::ParameterSet const &);
31  ~L1uGTTreeProducer() override = default;
32 
33 private:
34  void beginJob() override;
35  void analyze(edm::Event const &, edm::EventSetup const &) override;
36  void endJob() override;
37 
38 private:
39  // output file
41 
42  // pointers to the objects that will be stored as branches within the tree
44 
45  // tree
46  TTree *tree_;
47 
48  // EDM input tokens
51 
52  // L1 uGT menu
53  unsigned long long cache_id_;
54 };
55 
57  : results_(nullptr),
58  tree_(nullptr),
59  ugtToken_(consumes<GlobalAlgBlkBxCollection>(config.getParameter<edm::InputTag>("ugtToken"))),
61  cache_id_(0) {
62  usesResource(TFileService::kSharedResource);
63  // set up the TTree and its branches
64  tree_ = fs_->make<TTree>("L1uGTTree", "L1uGTTree");
65  tree_->Branch("L1uGT", "GlobalAlgBlk", &results_, 32000, 3);
66 }
67 
68 //
69 // member functions
70 //
71 
72 // ------------ method called to for each event ------------
74  unsigned long long id = setup.get<L1TUtmTriggerMenuRcd>().cacheIdentifier();
75  if (id != cache_id_) {
76  cache_id_ = id;
78  menu = setup.getHandle(l1GtMenuToken_);
79 
80  for (auto const &keyval : menu->getAlgorithmMap()) {
81  std::string const &name = keyval.second.getName();
82  unsigned int index = keyval.second.getIndex();
83  //std::cerr << fmt::sprintf("bit %4d: %s", index, name) << std::endl;
84  tree_->SetAlias(name.c_str(), fmt::sprintf("L1uGT.m_algoDecisionInitial[%d]", index).c_str());
85  }
86  }
87 
89  event.getByToken(ugtToken_, ugt);
90  if (ugt.isValid() && ugt.product()->size() != 0) {
91  results_ = &ugt->at(0, 0);
92  } else {
93  edm::LogWarning("MissingProduct")
94  << "L1uGTTree or L1uGTTestcrateTree GlobalAlgBlkBxCollection not found. Branch will not be filled.\n"
95  << "Please note that the L1uGTTestcrateTree is not expected to exist in MC, so this warning can be ignored!"
96  << std::endl;
97  }
98 
99  tree_->Fill();
100 }
101 
102 // ------------ method called once each job just before starting event loop ------------
104 
105 // ------------ method called once each job just after ending the event loop ------------
107 
108 //define this as a plug-in
static const std::string kSharedResource
Definition: TFileService.h:76
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
void analyze(edm::Event const &, edm::EventSetup const &) override
const edm::ESGetToken< L1TUtmTriggerMenu, L1TUtmTriggerMenuRcd > l1GtMenuToken_
T const * product() const
Definition: Handle.h:70
Definition: config.py:1
GlobalAlgBlk const * results_
unsigned size(int bx) const
L1uGTTreeProducer(edm::ParameterSet const &)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const T & at(int bx, unsigned i) const
void beginJob() override
~L1uGTTreeProducer() override=default
unsigned long long cache_id_
bool isValid() const
Definition: HandleBase.h:70
HLT enums.
edm::Service< TFileService > fs_
const edm::EDGetTokenT< GlobalAlgBlkBxCollection > ugtToken_
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
void endJob() override
Log< level::Warning, false > LogWarning
Definition: event.py:1