ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
D3PDTools
SampleHandler
Root
ToolsDuplicates.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3
*/
4
6
7
//
8
// includes
9
//
10
11
#include <
SampleHandler/ToolsDuplicates.h
>
12
13
#include <memory>
14
#include <set>
15
#include <sstream>
16
#include <stdexcept>
17
#include <utility>
18
#include <TChain.h>
19
#include <TFile.h>
20
#include <TLeaf.h>
21
#include <TTree.h>
22
#include <
RootCoreUtils/Assert.h
>
23
#include <
SampleHandler/MessageCheck.h
>
24
#include <
SampleHandler/Sample.h
>
25
#include <
SampleHandler/SampleHandler.h
>
26
#include <
CxxUtils/checker_macros.h
>
27
28
//
29
// method implementations
30
//
31
32
namespace
SH
33
{
34
namespace
35
{
41
using
RunEvent = std::pair<ULong64_t,ULong64_t>;
42
44
using
RunEventList = std::set<RunEvent>;
45
46
47
55
struct
NumberBranch
56
{
57
ULong64_t m_value64 = 0;
58
UInt_t m_value32 = 0;
59
bool
m_is64 =
false
;
60
61
void
connect
(TTree&
tree
,
const
std::string& name)
62
{
63
TLeaf *leaf =
tree
.GetLeaf (
name
.c_str());
64
if
(leaf ==
nullptr
)
65
throw
std::runtime_error (
"failed to find leaf: "
+ name);
66
const
std::string
type
= leaf->GetTypeName();
67
m_is64 = (
type
==
"ULong64_t"
||
type
==
"Long64_t"
);
68
tree
.SetBranchStatus (
name
.c_str(), 1);
69
const
Int_t
rc
= m_is64
70
?
tree
.SetBranchAddress (
name
.c_str(), &m_value64)
71
:
tree
.SetBranchAddress (
name
.c_str(), &m_value32);
72
if
(
rc
< 0)
73
throw
std::runtime_error (
"failed to set branch address for: "
+ name);
74
}
75
76
ULong64_t
value
()
const
77
{
78
return
m_is64 ? m_value64 : ULong64_t (m_value32);
79
}
80
};
81
82
83
87
const
std::set<std::string>& runNames ()
88
{
89
static
const
std::set<std::string>
result
=
90
{
"RunNumber"
,
"runNumber"
};
91
return
result
;
92
}
93
94
95
99
const
std::set<std::string>& eventNames ()
100
{
101
static
const
std::set<std::string>
result
=
102
{
"EventNumber"
,
"eventNumber"
};
103
return
result
;
104
}
105
106
107
112
std::string
113
findBranch (
const
TTree&
tree
,
const
std::set<std::string>& names)
114
{
115
TTree& tree_nc
ATLAS_THREAD_SAFE
=
const_cast<
TTree&
>
(
tree
);
116
TObjArray *
branches
= tree_nc.GetListOfBranches();
117
118
for
(
const
auto
& name : names)
119
{
120
if
(
branches
->FindObject (
name
.c_str()) != 0)
121
return
name
;
122
}
123
throw
std::runtime_error (
"failed to find branch of valid name"
);
124
}
125
126
127
133
void
printDuplicateEvents
(TTree&
tree
, RunEventList& list)
134
{
135
using namespace
msgDuplicates;
136
137
const
Long64_t
nentries
=
tree
.GetEntries();
138
if
(nentries < 0)
139
throw
std::runtime_error (
"failed to read number of events from n-tuple"
);
140
if
(nentries == 0)
141
return
;
142
143
const
std::string runName = findBranch (
tree
, runNames());
144
const
std::string eventName = findBranch (
tree
, eventNames());
145
146
tree
.SetBranchStatus (
"*"
, 0);
147
NumberBranch
run
;
148
run
.connect (
tree
, runName);
149
NumberBranch
event
;
150
event
.connect (
tree
, eventName);
151
152
tree
.SetCacheSize (10 * 1024 * 1024);
153
for
(Long64_t entry = 0;
154
entry
<
nentries
; ++
entry
)
155
{
156
if
(
tree
.GetEntry (entry) < 0)
157
throw
std::runtime_error (
"failed to read event"
);
158
RunEvent runEvent (
run
.value(),
event
.value());
159
if
(
list
.find (runEvent) ==
list
.end())
160
{
161
list
.insert (runEvent);
162
}
else
163
{
164
ANA_MSG_WARNING
(
"duplicate event run="
<<
run
.value() <<
" event="
<<
event
.value() <<
" file="
<<
tree
.GetCurrentFile()->GetName());
165
}
166
}
167
}
168
}
169
170
171
172
void
printDuplicateEvents
(
const
Sample
& sample)
173
{
174
RunEventList list;
175
std::unique_ptr<TChain> chain (sample.makeTChain ());
176
printDuplicateEvents
(*chain, list);
177
}
178
179
180
181
void
printDuplicateEventsSplit
(
const
SampleHandler
&
sh
)
182
{
183
for
(
auto
*sample :
sh
)
184
{
185
printDuplicateEvents
(*sample);
186
}
187
}
188
189
190
191
void
printDuplicateEventsJoint
(
const
SampleHandler
&
sh
)
192
{
193
RunEventList list;
194
for
(
auto
*sample :
sh
)
195
{
196
std::unique_ptr<TChain> chain (sample->makeTChain ());
197
printDuplicateEvents
(*chain, list);
198
}
199
}
200
}
Assert.h
ANA_MSG_WARNING
#define ANA_MSG_WARNING(xmsg,...)
Macro printing warning messages.
Definition
Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:293
rc
static Double_t rc
Definition
LArPhysWaveHECTool.cxx:37
MessageCheck.h
SampleHandler.h
Sample.h
ToolsDuplicates.h
checker_macros.h
Define macros for attributes used to control the static checker.
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition
checker_macros.h:211
SH::SampleHandler
A class that manages a list of Sample objects.
Definition
SampleHandler.h:53
SH::Sample
a base class that manages a set of files belonging to a particular data set and the associated meta-d...
Definition
Sample.h:49
GetAllXsec.entry
list entry
Definition
GetAllXsec.py:132
PlotCalibFromCool.nentries
nentries
Definition
PlotCalibFromCool.py:798
RCU::Shell
Definition
ShellExec.cxx:26
SH
This module provides a lot of global definitions, forward declarations and includes that are used by ...
Definition
DiskList.cxx:21
SH::printDuplicateEventsSplit
void printDuplicateEventsSplit(const SampleHandler &sh)
effects: check each sample for duplicate events and then print them out guarantee: basic,...
Definition
ToolsDuplicates.cxx:181
SH::printDuplicateEvents
void printDuplicateEvents(const Sample &sample)
effects: check the given sample for duplicate events and then print them out guarantee: basic,...
Definition
ToolsDuplicates.cxx:172
SH::printDuplicateEventsJoint
void printDuplicateEventsJoint(const SampleHandler &sh)
effects: check for duplicate events between all the samples and then print them out guarantee: basic,...
Definition
ToolsDuplicates.cxx:191
TRT::Track::event
@ event
Definition
InnerDetector/InDetCalibEvent/TRT_CalibData/TRT_CalibData/TrackInfo.h:52
athena.value
value
Definition
athena.py:126
extractSporadic.name
name
Definition
extractSporadic.py:101
fillPileUpNoiseLumi.connect
str connect
Definition
fillPileUpNoiseLumi.py:70
get_generator_info.result
result
Definition
get_generator_info.py:21
histSizes.list
list(name, path='/')
Definition
histSizes.py:38
python.CaloAddPedShiftConfig.type
type
Definition
CaloAddPedShiftConfig.py:42
runLayerRecalibration.branches
list branches
Definition
runLayerRecalibration.py:98
tree
TChain * tree
Definition
tile_monitor.h:30
run
int run(int argc, char *argv[])
Definition
ttree2hdf5.cxx:28
Generated on
for ATLAS Offline Software by
1.17.0