ATLAS Offline Software
Loading...
Searching...
No Matches
SampleHist.cxx File Reference
#include <SampleHandler/SampleHist.h>
#include <RootCoreUtils/Assert.h>
#include <RootCoreUtils/RootUtils.h>
#include <RootCoreUtils/ThrowMsg.h>
#include <SampleHandler/SamplePtr.h>
#include <TFile.h>
#include <memory>
Include dependency graph for SampleHist.cxx:

Go to the source code of this file.

Functions

 ClassImp (SH::SampleHist) namespace SH

Function Documentation

◆ ClassImp()

ClassImp ( SH::SampleHist )

Definition at line 31 of file SampleHist.cxx.

34{
35 void SampleHist ::
36 testInvariant () const
37 {
38 RCU_INVARIANT (!m_file.empty() || name() == "unnamed");
39 }
40
41
42
43 SampleHist ::
44 SampleHist ()
45 : Sample ("unnamed")
46 {
47 RCU_NEW_INVARIANT (this);
48 }
49
50
51
52 SampleHist ::
53 SampleHist (const std::string& name, const std::string& file)
54 : Sample (name), m_file (file)
55 {
56 RCU_NEW_INVARIANT (this);
57 }
58
59
60
61 std::size_t SampleHist ::
62 getNumFiles () const
63 {
64 RCU_READ_INVARIANT (this);
65 return 1;
66 }
67
68
69
70 std::string SampleHist ::
71 getFileName (const std::size_t
72#ifndef NDEBUG
73 index
74#endif
75 ) const
76 {
77 RCU_READ_INVARIANT (this);
78
79 RCU_INVARIANT (index == static_cast<std::size_t>(0));
80 return m_file;
81 }
82
83
84
85 SamplePtr SampleHist ::
86 doMakeLocal () const
87 {
88 RCU_READ_INVARIANT (this);
89 RCU_THROW_MSG ("Sample::makeLocal not supported for SampleHist");
90 return SamplePtr (); // compiler dummy
91 }
92
93
94
95 std::vector<std::string> SampleHist ::
96 doMakeFileList () const
97 {
98 RCU_READ_INVARIANT (this);
99
100 std::vector<std::string> result;
101 result.push_back (m_file);
102 return result;
103 }
104
105
106
107 void SampleHist ::
108 doUpdateLocation (const std::string& from, const std::string& to)
109 {
110 RCU_READ_INVARIANT (this);
111 if (strncmp (m_file.c_str(), from.c_str(), from.size()) == 0)
112 m_file = to + "/" + m_file.substr (from.size());
113 }
114
115
116
117 TObject *SampleHist ::
118 doReadHist (const std::string& name) const
119 {
120 RCU_READ_INVARIANT (this);
121
122 std::unique_ptr<TFile> file (TFile::Open (m_file.c_str(), "READ"));
123 if (file.get() == 0)
124 RCU_THROW_MSG ("could not open file " + m_file);
125 TObject *object = file->Get (name.c_str());
126 if (object != 0)
127 RCU::SetDirectory (object, 0);
128 return object;
129 }
130}
#define RCU_INVARIANT(x)
Definition Assert.h:201
#define RCU_NEW_INVARIANT(x)
Definition Assert.h:233
#define RCU_READ_INVARIANT(x)
Definition Assert.h:229
#define RCU_THROW_MSG(message)
Definition PrintMsg.h:58
CONT to(RANGE &&r)
Definition ranges.h:39
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:28
Definition index.py:1
TFile * file