ATLAS Offline Software
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>
26 #include <RootCoreUtils/Assert.h>
27 #include <RootCoreUtils/ThrowMsg.h>
28 #include <SampleHandler/Sample.h>
31 
32 //
33 // method implementations
34 //
35 
36 namespace 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 
143  {
144  RunEventList list;
145  std::unique_ptr<TChain> chain (sample.makeTChain ());
147  }
148 
149 
150 
152  {
153  for (SampleHandler::iterator sample = sh.begin(),
154  end = sh.end(); sample != end; ++ sample)
155  {
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 ());
170  }
171  }
172 }
SH::printDuplicateEventsSplit
void printDuplicateEventsSplit(const SampleHandler &sh)
effects: check each sample for duplicate events and then print them out guarantee: basic,...
Definition: ToolsDuplicates.cxx:151
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:162
SH::SampleHandler::iterator
std::vector< Sample * >::const_iterator iterator
the iterator to use
Definition: SampleHandler.h:475
get_generator_info.result
result
Definition: get_generator_info.py:21
runLayerRecalibration.chain
chain
Definition: runLayerRecalibration.py:175
tree
TChain * tree
Definition: tile_monitor.h:30
SampleHandler.h
Assert.h
ReweightUtils.message
message
Definition: ReweightUtils.py:15
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
runLayerRecalibration.branches
list branches
Definition: runLayerRecalibration.py:98
PlotCalibFromCool.nentries
nentries
Definition: PlotCalibFromCool.py:798
RCU_WARN_MSG
#define RCU_WARN_MSG(message)
Definition: PrintMsg.h:52
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
FullCPAlgorithmsTest_eljob.sample
sample
Definition: FullCPAlgorithmsTest_eljob.py:116
RCU::Shell
Definition: ShellExec.cxx:28
python.subdetectors.mmg.names
names
Definition: mmg.py:8
run
Definition: run.py:1
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
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:54
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
ThrowMsg.h
ToolsDuplicates.h
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:142
SH::SampleHandler
A class that manages a list of Sample objects.
Definition: SampleHandler.h:60
SH
This module provides a lot of global definitions, forward declarations and includes that are used by ...
Definition: PrunDriver.h:15
RCU_THROW_MSG
#define RCU_THROW_MSG(message)
Definition: PrintMsg.h:58
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211
checker_macros.h
Define macros for attributes used to control the static checker.
Sample.h