ATLAS Offline Software
Loading...
Searching...
No Matches
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
12
13#include <memory>
14#include <set>
15#include <sstream>
16#include <utility>
17#include <TChain.h>
18#include <TFile.h>
24
25//
26// method implementations
27//
28
29namespace SH
30{
31 namespace
32 {
34 typedef std::pair<UInt_t,UInt_t> RunEvent;
35
37 typedef std::set<RunEvent> RunEventList;
38
39
40
44 const std::set<std::string>& runNames ()
45 {
46 static const std::set<std::string> result =
47 { "RunNumber", "runNumber" };
48 return result;
49 }
50
51
52
56 const std::set<std::string>& eventNames ()
57 {
58 static const std::set<std::string> result =
59 { "EventNumber", "eventNumber" };
60 return result;
61 }
62
63
64
69 std::string
70 findBranch (const TTree& tree, const std::set<std::string>& names)
71 {
72 TTree& tree_nc ATLAS_THREAD_SAFE = const_cast<TTree&>(tree);
73 TObjArray *branches = tree_nc.GetListOfBranches();
74
75 for (std::set<std::string>::const_iterator name = names.begin(),
76 end = names.end(); name != end; ++ name)
77 {
78 if (branches->FindObject (name->c_str()) != 0)
79 return *name;
80 }
81 RCU_THROW_MSG ("failed to find branch of valid name");
82 return std::string (); // compiler dummy
83 }
84
85
86
92 void printDuplicateEvents (TTree& tree, RunEventList& list)
93 {
94 const Long64_t nentries = tree.GetEntries();
95 if (nentries < 0)
96 RCU_THROW_MSG ("failed to read number of events from n-tuple");
97 if (nentries == 0)
98 return;
99
100 const std::string runName = findBranch (tree, runNames());
101 const std::string eventName = findBranch (tree, eventNames());
102
103 tree.SetBranchStatus ("*", 0);
104 UInt_t run = 0;
105 tree.SetBranchStatus (runName.c_str(), 1);
106 tree.SetBranchAddress (runName.c_str(), static_cast<void*>(&run));
107 UInt_t event = 0;
108 tree.SetBranchStatus (eventName.c_str(), 1);
109 tree.SetBranchAddress (eventName.c_str(), static_cast<void*>(&event));
110
111 tree.SetCacheSize (10 * 1024 * 1024);
112 for (Long64_t entry = 0;
113 entry < nentries; ++ entry)
114 {
115 if (tree.GetEntry (entry) < 0)
116 RCU_THROW_MSG ("failed to read event");
117 RunEvent runEvent (run, event);
118 if (list.find (runEvent) == list.end())
119 {
120 list.insert (runEvent);
121 } else
122 {
123 std::ostringstream message;
124 message << "duplicate event run=" << run << " event=" << event
125 << " file=" << tree.GetCurrentFile()->GetName();
126
127 RCU_WARN_MSG (message.str());
128 }
129 }
130 }
131 }
132
133
134
135 void printDuplicateEvents (const Sample& sample)
136 {
137 RunEventList list;
138 std::unique_ptr<TChain> chain (sample.makeTChain ());
139 printDuplicateEvents (*chain, list);
140 }
141
142
143
145 {
146 for (SampleHandler::iterator sample = sh.begin(),
147 end = sh.end(); sample != end; ++ sample)
148 {
149 printDuplicateEvents (**sample);
150 }
151 }
152
153
154
156 {
157 RunEventList list;
158 for (SampleHandler::iterator sample = sh.begin(),
159 end = sh.end(); sample != end; ++ sample)
160 {
161 std::unique_ptr<TChain> chain ((*sample)->makeTChain ());
162 printDuplicateEvents (*chain, list);
163 }
164 }
165}
#define RCU_THROW_MSG(message)
Definition PrintMsg.h:53
#define RCU_WARN_MSG(message)
Definition PrintMsg.h:47
Define macros for attributes used to control the static checker.
#define ATLAS_THREAD_SAFE
A class that manages a list of Sample objects.
boost::transform_iterator< SamplePtrToRawSample, std::vector< std::shared_ptr< Sample > >::const_iterator > iterator
the iterator to use
a base class that manages a set of files belonging to a particular data set and the associated meta-d...
Definition Sample.h:49
This module provides a lot of global definitions, forward declarations and includes that are used by ...
Definition PrunDriver.h:15
void printDuplicateEventsSplit(const SampleHandler &sh)
effects: check each sample for duplicate events and then print them out guarantee: basic,...
void printDuplicateEvents(const Sample &sample)
effects: check the given sample for duplicate events and then print them out guarantee: basic,...
void printDuplicateEventsJoint(const SampleHandler &sh)
effects: check for duplicate events between all the samples and then print them out guarantee: basic,...
list(name, path='/')
Definition histSizes.py:38
TChain * tree
int run(int argc, char *argv[])