ATLAS Offline Software
Loading...
Searching...
No Matches
Ntup.cxx
Go to the documentation of this file.
1
2
3/*
4 Copyright (C) 2002-2026 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// ROOT includes
16#include "TTree.h"
17
18using namespace AthEx;
19
21// Public methods:
23
24// Constructors
26Ntup::Ntup( const std::string& name,
27 ISvcLocator* pSvcLocator ) :
28 ::AthAlgorithm( name, pSvcLocator ),
29 m_size(0),
30 m_run(0),
31 m_event(0),
32 m_ntuple(0)
33{ }
34
35// Destructor
39
40// Athena Algorithm's Hooks
42StatusCode Ntup::initialize()
43{
44 ATH_MSG_INFO ("Initializing " << name() << "...");
45 ATH_CHECK( m_ntSvc.retrieve() );
46 ATH_CHECK( m_evt.initialize() );
47
48 // register our n-tuple with the svc
49 m_ntuple = new TTree("tree1", "tree title");
50 if (!m_ntSvc->regTree("/rec/trees/tree1", m_ntuple).isSuccess()) {
51 ATH_MSG_ERROR("could not register tree [tree1]");
52 delete m_ntuple; m_ntuple = 0;
53 return StatusCode::FAILURE;
54 }
55
56 // book branches
57 m_ntuple->Branch("size", &m_size, "size/i");
58 m_ntuple->Branch("run", &m_run, "run/i");
59 m_ntuple->Branch("rundata", &m_rundata);
60
61 return StatusCode::SUCCESS;
62}
63
64StatusCode Ntup::finalize()
65{
66 ATH_MSG_INFO ("Finalizing " << name() << "...");
67
68 return StatusCode::SUCCESS;
69}
70
71StatusCode Ntup::execute()
72{
73 ATH_MSG_DEBUG ("Executing " << name() << "...");
74
75 // clear data...
76 m_rundata.clear();
77 m_size = 0;
78 m_event = 0;
79 m_run = 0;
80
81 // get event data...
83 if (!evt.isValid()) {
84 ATH_MSG_ERROR ("Could not retrieve EventInfo obj");
85 return StatusCode::FAILURE;
86 }
87
88 m_event= evt->eventNumber();
89 m_size = 2 + (m_event % 3);
90 m_run = evt->runNumber();
91
92 m_rundata.resize(m_size);
93 m_rundata[0] = m_run;
94 m_rundata[1] = m_event;
95 for (unsigned int i=2; i < m_size; ++i) {
96 m_rundata[i] = i;
97 }
98
99 // fill n-tuple
100 if (m_ntuple->Fill() == -1) {
101 ATH_MSG_WARNING("problems writing n-tuple");
102 }
103
104 ATH_MSG_INFO("run: [" << m_run << "]" << endmsg <<
105 "size: [" << m_size << "]" << endmsg <<
106 "rundata-sz: [" << m_rundata.size() << "]");
107
108 return StatusCode::SUCCESS;
109}
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
#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:
Ntup()
Default constructor:
virtual StatusCode execute()
Definition Ntup.cxx:71
virtual StatusCode finalize()
Definition Ntup.cxx:64
SG::ReadHandleKey< xAOD::EventInfo > m_evt
key to the event-info
Definition Ntup.h:76
unsigned int m_run
Definition Ntup.h:68
TTree * m_ntuple
pointer to the n-tuple
Definition Ntup.h:73
std::vector< long > m_rundata
Definition Ntup.h:70
virtual StatusCode initialize()
Definition Ntup.cxx:42
unsigned int m_event
Definition Ntup.h:69
unsigned int m_size
Definition Ntup.h:67
virtual ~Ntup()
Destructor:
Definition Ntup.cxx:37
ServiceHandle< ITHistSvc > m_ntSvc
handle to the histogram service
Definition Ntup.h:64
Definition Hist.h:27