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
5//
6// Distributed under the Boost Software License, Version 1.0.
7// (See accompanying file LICENSE_1_0.txt or copy at
8// http://www.boost.org/LICENSE_1_0.txt)
9
10// Please feel free to contact me (krumnack@iastate.edu) for bug
11// reports, feature suggestions, praise and complaints.
12
13
14//
15// includes
16//
17
19
20#include <memory>
21#include <set>
22#include <sstream>
23#include <utility>
24#include <TChain.h>
25#include <TFile.h>
31
32//
33// method implementations
34//
35
36namespace SH
37{
38 namespace
39 {
41 typedef std::pair<UInt_t,UInt_t> RunEvent;
42
44 typedef std::set<RunEvent> RunEventList;
45
46
47
51 const std::set<std::string>& runNames ()
52 {
53 static const std::set<std::string> result =
54 { "RunNumber", "runNumber" };
55 return result;
56 }
57
58
59
63 const std::set<std::string>& eventNames ()
64 {
65 static const std::set<std::string> result =
66 { "EventNumber", "eventNumber" };
67 return result;
68 }
69
70
71
76 std::string
77 findBranch (const TTree& tree, const std::set<std::string>& names)
78 {
79 TTree& tree_nc ATLAS_THREAD_SAFE = const_cast<TTree&>(tree);
80 TObjArray *branches = tree_nc.GetListOfBranches();
81
82 for (std::set<std::string>::const_iterator name = names.begin(),
83 end = names.end(); name != end; ++ name)
84 {
85 if (branches->FindObject (name->c_str()) != 0)
86 return *name;
87 }
88 RCU_THROW_MSG ("failed to find branch of valid name");
89 return std::string (); // compiler dummy
90 }
91
92
93
99 void printDuplicateEvents (TTree& tree, RunEventList& list)
100 {
101 const Long64_t nentries = tree.GetEntries();
102 if (nentries < 0)
103 RCU_THROW_MSG ("failed to read number of events from n-tuple");
104 if (nentries == 0)
105 return;
106
107 const std::string runName = findBranch (tree, runNames());
108 const std::string eventName = findBranch (tree, eventNames());
109
110 tree.SetBranchStatus ("*", 0);
111 UInt_t run = 0;
112 tree.SetBranchStatus (runName.c_str(), 1);
113 tree.SetBranchAddress (runName.c_str(), static_cast<void*>(&run));
114 UInt_t event = 0;
115 tree.SetBranchStatus (eventName.c_str(), 1);
116 tree.SetBranchAddress (eventName.c_str(), static_cast<void*>(&event));
117
118 tree.SetCacheSize (10 * 1024 * 1024);
119 for (Long64_t entry = 0;
120 entry < nentries; ++ entry)
121 {
122 if (tree.GetEntry (entry) < 0)
123 RCU_THROW_MSG ("failed to read event");
124 RunEvent runEvent (run, event);
125 if (list.find (runEvent) == list.end())
126 {
127 list.insert (runEvent);
128 } else
129 {
130 std::ostringstream message;
131 message << "duplicate event run=" << run << " event=" << event
132 << " file=" << tree.GetCurrentFile()->GetName();
133
134 RCU_WARN_MSG (message.str());
135 }
136 }
137 }
138 }
139
140
141
142 void printDuplicateEvents (const Sample& sample)
143 {
144 RunEventList list;
145 std::unique_ptr<TChain> chain (sample.makeTChain ());
146 printDuplicateEvents (*chain, list);
147 }
148
149
150
152 {
153 for (SampleHandler::iterator sample = sh.begin(),
154 end = sh.end(); sample != end; ++ sample)
155 {
156 printDuplicateEvents (**sample);
157 }
158 }
159
160
161
163 {
164 RunEventList list;
165 for (SampleHandler::iterator sample = sh.begin(),
166 end = sh.end(); sample != end; ++ sample)
167 {
168 std::unique_ptr<TChain> chain ((*sample)->makeTChain ());
169 printDuplicateEvents (*chain, list);
170 }
171 }
172}
#define RCU_THROW_MSG(message)
Definition PrintMsg.h:58
#define RCU_WARN_MSG(message)
Definition PrintMsg.h:52
Define macros for attributes used to control the static checker.
#define ATLAS_THREAD_SAFE
A class that manages a list of Sample objects.
std::vector< 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:54
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