CMS 3D CMS Logo

L1uGTTreeProducer.cc
Go to the documentation of this file.
1 // system include files
2 #include <memory>
3 #include <boost/format.hpp>
4 
5 // framework
13 
14 // data formats
18 
19 // ROOT output stuff
22 #include "TTree.h"
23 
24 //
25 // class declaration
26 //
27 
29 public:
30  explicit L1uGTTreeProducer(edm::ParameterSet const &);
31  ~L1uGTTreeProducer() override;
32 
33 
34 private:
35  void beginJob() override;
36  void analyze(edm::Event const &, edm::EventSetup const &) override;
37  void endJob() override;
38 
39 private:
40  // output file
42 
43  // pointers to the objects that will be stored as branches within the tree
45 
46  // tree
47  TTree * tree_;
48 
49  // EDM input tokens
51 
52  // L1 uGT menu
53  unsigned long long cache_id_;
54 };
55 
56 
57 
60  ugt_token_( consumes<GlobalAlgBlkBxCollection>(config.getParameter<edm::InputTag>("ugtToken"))),
61  cache_id_( 0 )
62 {
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 
70 {
71  //if (tree_) { delete tree_; tree_ = NULL; }
72  //if (results_) { delete results_; results_ = NULL; } // It seems TTree owns this pointer...
73 }
74 
75 
76 //
77 // member functions
78 //
79 
80 // ------------ method called to for each event ------------
81 void
83 {
84  unsigned long long id = setup.get<L1TUtmTriggerMenuRcd>().cacheIdentifier();
85  if (id != cache_id_) {
86  cache_id_ = id;
88  setup.get<L1TUtmTriggerMenuRcd>().get(menu);
89 
90  for (auto const & keyval: menu->getAlgorithmMap()) {
91  std::string const & name = keyval.second.getName();
92  unsigned int index = keyval.second.getIndex();
93  //std::cerr << (boost::format("bit %4d: %s") % index % name).str() << std::endl;
94  tree_->SetAlias(name.c_str(), (boost::format("L1uGT.m_algoDecisionInitial[%d]") % index).str().c_str());
95  }
96  }
97 
99 
100  event.getByToken(ugt_token_, ugt);
101 
102  if (ugt.isValid()) {
103  results_ = & ugt->at(0, 0);
104  }
105 
106  tree_->Fill();
107 }
108 
109 // ------------ method called once each job just before starting event loop ------------
110 void
112 {
113 }
114 
115 // ------------ method called once each job just after ending the event loop ------------
116 void
118 }
119 
120 //define this as a plug-in
void analyze(edm::Event const &, edm::EventSetup const &) override
#define nullptr
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:2
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
Definition: config.py:1
GlobalAlgBlk const * results_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
L1uGTTreeProducer(edm::ParameterSet const &)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
~L1uGTTreeProducer() override
format
Some error handling for the usage.
bool isValid() const
Definition: HandleBase.h:74
void beginJob() override
const edm::EDGetTokenT< GlobalAlgBlkBxCollection > ugt_token_
unsigned long long cache_id_
const std::map< std::string, L1TUtmAlgorithm > & getAlgorithmMap() const
HLT enums.
edm::Service< TFileService > fs_
T get() const
Definition: EventSetup.h:71
void endJob() override
#define str(s)
Definition: event.py:1
const T & at(int bx, unsigned i) const