ATLAS Offline Software
Loading...
Searching...
No Matches
SampleHist.cxx File Reference
#include <SampleHandler/SampleHist.h>
#include <RootCoreUtils/Assert.h>
#include <RootCoreUtils/RootUtils.h>
#include <SampleHandler/SampleLocal.h>
#include <TFile.h>
#include <memory>
#include <stdexcept>
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 )
Author
Nils Krumnack

Definition at line 24 of file SampleHist.cxx.

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 RCU_REQUIRE (index == static_cast<std::size_t>(0));
72 return m_file;
73 }
74
75
76
77 std::unique_ptr<SampleLocal> SampleHist ::
78 doMakeLocal () const
79 {
80 RCU_READ_INVARIANT (this);
81 throw std::runtime_error ("Sample::makeLocal not supported for SampleHist");
82 }
83
84
85
86 std::vector<std::string> SampleHist ::
87 doMakeFileList () const
88 {
89 RCU_READ_INVARIANT (this);
90
91 std::vector<std::string> result;
92 result.push_back (m_file);
93 return result;
94 }
95
96
97
98 void SampleHist ::
99 doUpdateLocation (const std::string& from, const std::string& to)
100 {
102 // rationale: only replace the prefix on a path boundary (so that
103 // "/a/b" does not also match "/a/bc") and join without inserting
104 // a duplicate '/'.
105 if (m_file.starts_with (from) &&
106 (m_file.size() == from.size() || m_file[from.size()] == '/'))
107 {
108 std::string rest = m_file.substr (from.size());
109 if (!rest.empty() && rest.front() == '/')
110 rest.erase (0, 1);
111 m_file = rest.empty() ? to : to + "/" + rest;
112 }
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() == nullptr)
124 throw std::runtime_error ("could not open file " + m_file);
125 TObject *object = file->Get (name.c_str());
126 if (object != nullptr)
127 RCU::SetDirectory (object, nullptr);
128 return object;
129 }
130}
#define RCU_INVARIANT(x)
Definition Assert.h:187
#define RCU_CHANGE_INVARIANT(x)
Definition Assert.h:219
#define RCU_NEW_INVARIANT(x)
Definition Assert.h:221
#define RCU_REQUIRE(x)
Definition Assert.h:196
#define RCU_READ_INVARIANT(x)
Definition Assert.h:217
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:25
Definition index.py:1
TFile * file