ATLAS Offline Software
Loading...
Searching...
No Matches
Ntup.cxx
Go to the documentation of this file.
1
2
3/*
4 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
5*/
6
7// Ntup.cxx
8// Implementation file for class Ntup
9// Author: S.Binet<binet@cern.ch>
11
12// AthExHistNtup includes
13#include "Ntup.h"
14
15// STL includes
16
17// FrameWork includes
18#include "Gaudi/Property.h"
19
20// ROOT includes
21#include "TTree.h"
22
23// event includes
25
26using namespace AthEx;
27
29// Public methods:
31
32// Constructors
34Ntup::Ntup( const std::string& name,
35 ISvcLocator* pSvcLocator ) :
36 ::AthAlgorithm( name, pSvcLocator ),
37 m_ntsvc("THistSvc/THistSvc", name),
38 m_size(0),
39 m_run(0),
40 m_event(0),
41 m_ntuple(0)
42{
43 //
44 // Property declaration
45 //
46
47 declareProperty( "EvtInfo",
48 m_evtInfoName = "",
49 "key to the event-info instance to ntuple-ize.");
50
51}
52
53// Destructor
57
58// Athena Algorithm's Hooks
60StatusCode Ntup::initialize()
61{
62 ATH_MSG_INFO ("Initializing " << name() << "...");
63 if (!m_ntsvc.retrieve().isSuccess()) {
64 ATH_MSG_ERROR("could not retrieve handle to ntuple svc");
65 return StatusCode::FAILURE;
66 }
67
68 // register our n-tuple with the svc
69 m_ntuple = new TTree("tree1", "tree title");
70 if (!m_ntsvc->regTree("/rec/trees/tree1", m_ntuple).isSuccess()) {
71 ATH_MSG_ERROR("could not register tree [tree1]");
72 delete m_ntuple; m_ntuple = 0;
73 return StatusCode::FAILURE;
74 }
75
76 // book branches
77 m_ntuple->Branch("size", &m_size, "size/i");
78 m_ntuple->Branch("run", &m_run, "run/i");
79 m_ntuple->Branch("rundata", &m_rundata);
80
81 return StatusCode::SUCCESS;
82}
83
84StatusCode Ntup::finalize()
85{
86 ATH_MSG_INFO ("Finalizing " << name() << "...");
87
88 return StatusCode::SUCCESS;
89}
90
91StatusCode Ntup::execute()
92{
93 ATH_MSG_DEBUG ("Executing " << name() << "...");
94
95 // clear data...
96 m_rundata.clear();
97 m_size = 0;
98 m_event = 0;
99 m_run = 0;
100
101 // get event data...
102 const xAOD::EventInfo* evt = 0;
103 if (!evtStore()->retrieve(evt, m_evtInfoName).isSuccess() ||
104 0==evt) {
105 ATH_MSG_ERROR("could not get event-info at [" << m_evtInfoName << "]");
106 return StatusCode::FAILURE;
107 }
108
109 m_event= evt->eventNumber();
110 m_size = 2 + (m_event % 3);
111 m_run = evt->runNumber();
112
113 m_rundata.resize(m_size);
114 m_rundata[0] = m_run;
115 m_rundata[1] = m_event;
116 for (unsigned int i=2; i < m_size; ++i) {
117 m_rundata[i] = i;
118 }
119
120 // fill n-tuple
121 if (m_ntuple->Fill() == -1) {
122 ATH_MSG_WARNING("problems writing n-tuple");
123 }
124
125 ATH_MSG_INFO("run: [" << m_run << "]" << endmsg <<
126 "size: [" << m_size << "]" << endmsg <<
127 "rundata-sz: [" << m_rundata.size() << "]");
128
129 return StatusCode::SUCCESS;
130}
#define endmsg
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
Ntup()
Default constructor:
virtual StatusCode execute()
Definition Ntup.cxx:91
std::string m_evtInfoName
key to the event-info
Definition Ntup.h:75
virtual StatusCode finalize()
Definition Ntup.cxx:84
unsigned int m_run
Definition Ntup.h:67
TTree * m_ntuple
pointer to the n-tuple
Definition Ntup.h:72
std::vector< long > m_rundata
Definition Ntup.h:69
virtual StatusCode initialize()
Definition Ntup.cxx:60
unsigned int m_event
Definition Ntup.h:68
unsigned int m_size
Definition Ntup.h:66
virtual ~Ntup()
Destructor:
Definition Ntup.cxx:55
ServiceHandle< ITHistSvc > m_ntsvc
handle to the n-tuple svc
Definition Ntup.h:63
Definition Hist.h:25
EventInfo_v1 EventInfo
Definition of the latest event info version.