ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
D3PDTools
SampleHandler
Root
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
11
#include <
SampleHandler/SampleHist.h
>
12
13
#include <
RootCoreUtils/Assert.h
>
14
#include <
RootCoreUtils/RootUtils.h
>
15
#include <
SampleHandler/SampleLocal.h
>
16
#include <TFile.h>
17
#include <memory>
18
#include <stdexcept>
19
20
//
21
// method implementations
22
//
23
24
ClassImp
(
SH::SampleHist
)
25
26
namespace
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
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
{
101
RCU_CHANGE_INVARIANT
(
this
);
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
}
Assert.h
RCU_INVARIANT
#define RCU_INVARIANT(x)
Definition
Assert.h:187
RCU_CHANGE_INVARIANT
#define RCU_CHANGE_INVARIANT(x)
Definition
Assert.h:219
RCU_NEW_INVARIANT
#define RCU_NEW_INVARIANT(x)
Definition
Assert.h:221
RCU_REQUIRE
#define RCU_REQUIRE(x)
Definition
Assert.h:196
RCU_READ_INVARIANT
#define RCU_READ_INVARIANT(x)
Definition
Assert.h:217
RootUtils.h
ClassImp
ClassImp(SH::SampleHist) namespace SH
Definition
SampleHist.cxx:24
SampleHist.h
SampleLocal.h
SH::SampleHist
A sample that represents a single histogram file.
Definition
SampleHist.h:23
RCU::SetDirectory
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
SH
This module provides a lot of global definitions, forward declarations and includes that are used by ...
Definition
DiskList.cxx:21
index
Definition
index.py:1
file
TFile * file
Definition
tile_monitor.h:29
Generated on
for ATLAS Offline Software by
1.17.0