CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
29 public:
30  explicit L1uGTTreeProducer(edm::ParameterSet const &);
31  ~L1uGTTreeProducer() override;
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
50 
51  // L1 uGT menu
52  unsigned long long cache_id_;
53 };
54 
56  : results_(nullptr),
57  tree_(nullptr),
58  ugt_token_(consumes<GlobalAlgBlkBxCollection>(config.getParameter<edm::InputTag>("ugtToken"))),
59  cache_id_(0) {
60  // set up the TTree and its branches
61  tree_ = fs_->make<TTree>("L1uGTTree", "L1uGTTree");
62  tree_->Branch("L1uGT", "GlobalAlgBlk", &results_, 32000, 3);
63 }
64 
66  //if (tree_) { delete tree_; tree_ = NULL; }
67  //if (results_) { delete results_; results_ = NULL; } // It seems TTree owns this pointer...
68 }
69 
70 //
71 // member functions
72 //
73 
74 // ------------ method called to for each event ------------
76  unsigned long long id = setup.get<L1TUtmTriggerMenuRcd>().cacheIdentifier();
77  if (id != cache_id_) {
78  cache_id_ = id;
80  setup.get<L1TUtmTriggerMenuRcd>().get(menu);
81 
82  for (auto const &keyval : menu->getAlgorithmMap()) {
83  std::string const &name = keyval.second.getName();
84  unsigned int index = keyval.second.getIndex();
85  //std::cerr << fmt::sprintf("bit %4d: %s", index, name) << std::endl;
86  tree_->SetAlias(name.c_str(), fmt::sprintf("L1uGT.m_algoDecisionInitial[%d]", index).c_str());
87  }
88  }
89 
91 
92  event.getByToken(ugt_token_, ugt);
93 
94  if (ugt.isValid()) {
95  results_ = &ugt->at(0, 0);
96  }
97 
98  tree_->Fill();
99 }
100 
101 // ------------ method called once each job just before starting event loop ------------
103 
104 // ------------ method called once each job just after ending the event loop ------------
106 
107 //define this as a plug-in
uint16_t *__restrict__ id
void analyze(edm::Event const &, edm::EventSetup const &) override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
GlobalAlgBlk const * results_
L1uGTTreeProducer(edm::ParameterSet const &)
~L1uGTTreeProducer() override
bool isValid() const
Definition: HandleBase.h:70
void beginJob() override
const edm::EDGetTokenT< GlobalAlgBlkBxCollection > ugt_token_
unsigned long long cache_id_
tuple config
parse the configuration file
edm::Service< TFileService > fs_
T get() const
Definition: EventSetup.h:88
void endJob() override