ATLAS Offline Software
Ntup.cxx
Go to the documentation of this file.
1 
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 
26 using namespace AthEx;
27 
29 // Public methods:
31 
32 // Constructors
34 Ntup::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
56 {}
57 
58 // Athena Algorithm's Hooks
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 
85 {
86  ATH_MSG_INFO ("Finalizing " << name() << "...");
87 
88  return StatusCode::SUCCESS;
89 }
90 
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 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
AthEx::Ntup::m_evtInfoName
std::string m_evtInfoName
key to the event-info
Definition: Ntup.h:75
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
AthEx::Ntup::execute
virtual StatusCode execute()
Definition: Ntup.cxx:91
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
AthEx::Ntup::finalize
virtual StatusCode finalize()
Definition: Ntup.cxx:84
LArG4FSStartPointFilter.evt
evt
Definition: LArG4FSStartPointFilter.py:42
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
AthEx::Ntup::m_size
unsigned int m_size
Definition: Ntup.h:66
AthEx::Ntup::~Ntup
virtual ~Ntup()
Destructor:
Definition: Ntup.cxx:55
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
AthEx::Ntup::m_rundata
std::vector< long > m_rundata
Definition: Ntup.h:69
lumiFormat.i
int i
Definition: lumiFormat.py:85
AthEx::Ntup::initialize
virtual StatusCode initialize()
Definition: Ntup.cxx:60
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
AthEx
Definition: Hist.h:25
AthEx::Ntup::m_run
unsigned int m_run
Definition: Ntup.h:67
AthEx::Ntup::m_event
unsigned int m_event
Definition: Ntup.h:68
AthAlgorithm
Definition: AthAlgorithm.h:47
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
AthEx::Ntup::m_ntuple
TTree * m_ntuple
pointer to the n-tuple
Definition: Ntup.h:72
Ntup.h
EventInfo.h
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
AthEx::Ntup::m_ntsvc
ServiceHandle< ITHistSvc > m_ntsvc
handle to the n-tuple svc
Definition: Ntup.h:63
AthEx::Ntup::Ntup
Ntup()
Default constructor:
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32