ATLAS Offline Software
Loading...
Searching...
No Matches
SampleHist.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7//
8// includes
9//
10
12
17#include <TFile.h>
18#include <memory>
19
20//
21// method implementations
22//
23
25
26namespace SH
27{
28 void SampleHist ::
29 testInvariant () const
30 {
31 RCU_INVARIANT (!m_file.empty() || name() == "unnamed");
32 }
33
34
35
36 SampleHist ::
37 SampleHist ()
38 : Sample ("unnamed")
39 {
40 RCU_NEW_INVARIANT (this);
41 }
42
43
44
45 SampleHist ::
46 SampleHist (const std::string& name, const std::string& file)
47 : Sample (name), m_file (file)
48 {
49 RCU_NEW_INVARIANT (this);
50 }
51
52
53
54 std::size_t SampleHist ::
55 getNumFiles () const
56 {
57 RCU_READ_INVARIANT (this);
58 return 1;
59 }
60
61
62
63 std::string SampleHist ::
64 getFileName (const std::size_t
65#ifndef NDEBUG
66 index
67#endif
68 ) const
69 {
70 RCU_READ_INVARIANT (this);
71
72 RCU_INVARIANT (index == static_cast<std::size_t>(0));
73 return m_file;
74 }
75
76
77
78 std::unique_ptr<SampleLocal> SampleHist ::
79 doMakeLocal () const
80 {
81 RCU_READ_INVARIANT (this);
82 RCU_THROW_MSG ("Sample::makeLocal not supported for SampleHist");
83 return {}; // compiler dummy
84 }
85
86
87
88 std::vector<std::string> SampleHist ::
89 doMakeFileList () const
90 {
91 RCU_READ_INVARIANT (this);
92
93 std::vector<std::string> result;
94 result.push_back (m_file);
95 return result;
96 }
97
98
99
100 void SampleHist ::
101 doUpdateLocation (const std::string& from, const std::string& to)
102 {
103 RCU_READ_INVARIANT (this);
104 if (strncmp (m_file.c_str(), from.c_str(), from.size()) == 0)
105 m_file = to + "/" + m_file.substr (from.size());
106 }
107
108
109
110 TObject *SampleHist ::
111 doReadHist (const std::string& name) const
112 {
113 RCU_READ_INVARIANT (this);
114
115 std::unique_ptr<TFile> file (TFile::Open (m_file.c_str(), "READ"));
116 if (file.get() == 0)
117 RCU_THROW_MSG ("could not open file " + m_file);
118 TObject *object = file->Get (name.c_str());
119 if (object != 0)
120 RCU::SetDirectory (object, 0);
121 return object;
122 }
123}
#define RCU_INVARIANT(x)
Definition Assert.h:196
#define RCU_NEW_INVARIANT(x)
Definition Assert.h:228
#define RCU_READ_INVARIANT(x)
Definition Assert.h:224
#define RCU_THROW_MSG(message)
Definition PrintMsg.h:53
ClassImp(SH::SampleHist) namespace SH
A sample that represents a single histogram file.
Definition SampleHist.h:23
bool SetDirectory(TObject *object, TDirectory *directory)
effects: set the directory this object is associated with returns: whether the object type actively k...
Definition RootUtils.cxx:25
This module provides a lot of global definitions, forward declarations and includes that are used by ...
Definition PrunDriver.h:15
Definition index.py:1
TFile * file