The Gaudi Framework  v36r16 (ea80daf8)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
THistRead.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 // Include files
12 #include "THistRead.h"
13 
14 #include "GaudiKernel/ITHistSvc.h"
15 #include "GaudiKernel/MsgStream.h"
17 #include <math.h>
18 
19 #include "TDirectory.h"
20 #include "TError.h"
21 #include "TFile.h"
22 #include "TH1F.h"
23 #include "TH2F.h"
24 #include "TH3F.h"
25 #include "TKey.h"
26 #include "TTree.h"
27 
29 
30 //------------------------------------------------------------------------------
31 THistRead::THistRead( const std::string& name, ISvcLocator* pSvcLocator )
32  : Algorithm( name, pSvcLocator )
33  , m_ths( nullptr )
34 //------------------------------------------------------------------------------
35 {}
36 
37 //------------------------------------------------------------------------------
39 //------------------------------------------------------------------------------
40 {
41  if ( service( "THistSvc", m_ths ).isFailure() ) {
42  error() << "Couldn't get THistSvc" << endmsg;
43  return StatusCode::FAILURE;
44  }
45 
46  // stream read1, 1D in "/xxx"
47  StatusCode sc1a = m_ths->regHist( "/read1/xxx/1Dgauss" );
48  TH1* h1( nullptr );
49  StatusCode sc1b = m_ths->getHist( "/read1/xxx/1Dgauss", h1 );
50  if ( sc1a.isFailure() || sc1b.isFailure() || h1 == nullptr ) {
51  error() << "Couldn't read gauss1d" << endmsg;
52  } else {
53  info() << h1->GetName() << ": " << h1->GetEntries() << endmsg;
54  }
55 
56  // stream read2, 2D tree in "/"
57  StatusCode sc2a = m_ths->regHist( "/read2/2Dgauss" );
58  TH2* h2( nullptr );
59  StatusCode sc2b = m_ths->getHist( "/read2/2Dgauss", h2 );
60  if ( sc2a.isFailure() || sc2b.isFailure() || h2 == nullptr ) {
61  error() << "Couldn't read 2Dgauss" << endmsg;
62  } else {
63  info() << h2->GetName() << ": " << h2->GetEntries() << endmsg;
64  }
65 
66  // 3D tree in "/"
67  StatusCode sc3a = m_ths->regHist( "/read2/3Dgauss" );
68  TH3* h3( nullptr );
69  StatusCode sc3b = m_ths->getHist( "/read2/3Dgauss", h3 );
70  if ( sc3a.isFailure() || sc3b.isFailure() || h3 == nullptr ) {
71  error() << "Couldn't read 3Dgauss" << endmsg;
72  } else {
73  info() << h3->GetName() << ": " << h3->GetEntries() << endmsg;
74  }
75 
76  // Profile in "/"
77  StatusCode sc4a = m_ths->regHist( "/read2/profile" );
78  TH1* tp( nullptr );
79  StatusCode sc4b = m_ths->getHist( "/read2/profile", tp );
80  if ( sc4a.isFailure() || sc4b.isFailure() || tp == nullptr ) {
81  error() << "Couldn't read profile" << endmsg;
82  } else {
83  info() << tp->GetName() << ": " << tp->GetEntries() << endmsg;
84  }
85 
86  // Tree with branches in "/trees/stuff"
87  StatusCode sc5a = m_ths->regTree( "/read2/trees/stuff/treename" );
88  TTree* tr( nullptr );
89  StatusCode sc5b = m_ths->getTree( "/read2/trees/stuff/treename", tr );
90  if ( sc5a.isFailure() || sc5b.isFailure() || tr == nullptr ) {
91  error() << "Couldn't read tree" << endmsg;
92  } else {
93  info() << tr->GetName() << ": " << tr->GetEntries() << endmsg;
94  }
95  return StatusCode::SUCCESS;
96 }
97 
98 //------------------------------------------------------------------------------
100 //------------------------------------------------------------------------------
101 {
102  return StatusCode::SUCCESS;
103 }
104 
105 //------------------------------------------------------------------------------
107 //------------------------------------------------------------------------------
108 {
109  debug() << "Finalizing..." << endmsg;
110  return StatusCode::SUCCESS;
111 }
THistRead::execute
StatusCode execute() override
Definition: THistRead.cpp:99
RndmGenerators.h
ITHistSvc::regTree
virtual StatusCode regTree(const std::string &name)=0
Register a new TTree with a given name.
ISvcLocator
Definition: ISvcLocator.h:46
Algorithm
Alias for backward compatibility.
Definition: Algorithm.h:58
THistRead.h
THistRead
Definition: THistRead.h:21
TimingHistograms.name
name
Definition: TimingHistograms.py:25
StatusCode
Definition: StatusCode.h:65
THistRead::finalize
StatusCode finalize() override
Definition: THistRead.cpp:106
ITHistSvc::regHist
virtual StatusCode regHist(const std::string &name)=0
Register a new ROOT histogram TH*X with a name.
ITHistSvc::getHist
virtual StatusCode getHist(const std::string &name, TH1 *&, size_t index=0) const =0
Return histogram with given name as TH1*, THistSvcMT still owns object.
THistRead::m_ths
ITHistSvc * m_ths
Definition: THistRead.h:33
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:203
ITHistSvc.h
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:129
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
std
STL namespace.
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
Gaudi::Algorithm::service
StatusCode service(std::string_view name, T *&psvc, bool createIf=true) const
Access a service by name, creating it if it doesn't already exist.
Definition: Algorithm.h:205
HistoDumpEx.h1
h1
Definition: HistoDumpEx.py:22
THistRead::initialize
StatusCode initialize() override
Definition: THistRead.cpp:38
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
compareRootHistos.tp
tp
Definition: compareRootHistos.py:491
ITHistSvc::getTree
virtual StatusCode getTree(const std::string &name, TTree *&) const =0
Return TTree with given name.
MsgStream.h