ATLAS Offline Software
SampleComposite.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 <RootCoreUtils/Assert.h>
21 #include <RootCoreUtils/ThrowMsg.h>
23 
24 //
25 // method implementations
26 //
27 
29 
30 namespace SH
31 {
33  testInvariant () const
34  {
35  for (SamplesIter sample = m_samples.begin(),
36  end = m_samples.end(); sample != end; ++ sample)
37  {
38  RCU_INVARIANT (!sample->empty());
39  };
40  }
41 
42 
43 
46  : Sample ("unnamed")
47  {
48  RCU_NEW_INVARIANT (this);
49  }
50 
51 
52 
54  SampleComposite (const std::string& name)
55  : Sample (name)
56  {
57  RCU_NEW_INVARIANT (this);
58  }
59 
60 
61 
63  add (const SamplePtr& sample)
64  {
65  RCU_CHANGE_INVARIANT (this);
66  RCU_REQUIRE_SOFT (!sample.empty());
67  if (contains (sample->name()))
68  RCU_THROW_MSG ("trying to add sample " + sample->name() + " to sample " + name() + ", which already contains a sample " + sample->name());
69  m_samples.push_back (sample);
70  }
71 
72 
73 
74  std::size_t SampleComposite ::
75  getNumFiles () const
76  {
77  RCU_READ_INVARIANT (this);
78  RCU_THROW_MSG ("Sample::numFiles not supported for SampleComposite");
79  return 0; // compiler dummy
80  }
81 
82 
83 
84  std::string SampleComposite ::
85  getFileName (const std::size_t /*index*/) const
86  {
87  RCU_READ_INVARIANT (this);
88  RCU_THROW_MSG ("Sample::fileName not supported for SampleComposite");
89  return ""; // compiler dummy
90  }
91 
92 
93 
94  std::vector<std::string> SampleComposite ::
95  doMakeFileList () const
96  {
97  RCU_READ_INVARIANT (this);
98 
99  std::vector<std::string> result;
100  for (SamplesIter sample = m_samples.begin(),
101  end = m_samples.end(); sample != end; ++ sample)
102  {
103  std::vector<std::string> subresult = (*sample)->makeFileList();
104  result.insert (result.end(), subresult.begin(), subresult.end());
105  }
106  return result;
107  }
108 
109 
110 
111  SamplePtr SampleComposite ::
112  doMakeLocal () const
113  {
114  RCU_READ_INVARIANT (this);
115  RCU_THROW_MSG ("Sample::makeLocal not supported for SampleComposite");
116  return 0; // compiler dummy
117  }
118 
119 
120 
121  void SampleComposite ::
122  doUpdateLocation (const std::string& from, const std::string& to)
123  {
124  RCU_READ_INVARIANT (this);
126  end = m_samples.end(); sample != end; ++ sample)
127  {
128  (*sample)->updateLocation (from, to);
129  }
130  }
131 
132 
133 
134  bool SampleComposite ::
135  getContains (const std::string& name) const
136  {
137  RCU_READ_INVARIANT (this);
138  for (SamplesIter sample = m_samples.begin(),
139  end = m_samples.end(); sample != end; ++ sample)
140  {
141  if ((*sample)->contains (name))
142  return true;
143  };
144  return false;
145  }
146 
147 
148 
149  void SampleComposite ::
150  doAddSamples (SampleHandler& result)
151  {
152  RCU_READ_INVARIANT (this);
154  end = m_samples.end(); sample != end; ++ sample)
155  {
156  (*sample)->addSamples (result);
157  };
158  }
159 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
get_generator_info.result
result
Definition: get_generator_info.py:21
SH::SampleComposite::getNumFiles
virtual std::size_t getNumFiles() const
the number of files in the sample
SH::SampleComposite::SampleComposite
SampleComposite()
standard constructor
SH::SampleComposite::getContains
virtual bool getContains(const std::string &name) const
whether this sample contains a sample of the given name
SH::SampleComposite::testInvariant
void testInvariant() const
test the invariant of this object
Assert.h
SH::SampleComposite::SamplesIter
std::vector< SamplePtr >::const_iterator SamplesIter
the iterator for m_samples
Definition: SampleComposite.h:124
SH::SampleComposite::doAddSamples
virtual void doAddSamples(SampleHandler &result)
add all samples this sample corresponds to to the given sample handler
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
SamplePtr.h
FullCPAlgorithmsTest_eljob.sample
sample
Definition: FullCPAlgorithmsTest_eljob.py:100
RCU_REQUIRE_SOFT
#define RCU_REQUIRE_SOFT(x)
Definition: Assert.h:153
ClassImp
ClassImp(SH::SampleComposite) namespace SH
Definition: SampleComposite.cxx:28
SH::SampleComposite::add
void add(const SamplePtr &sample)
add a sample to the list
SH::SampleComposite::doUpdateLocation
virtual void doUpdateLocation(const std::string &from, const std::string &to)
update all file references starting with from to to
SH::SampleComposite::getFileName
virtual std::string getFileName(std::size_t index) const
the name of the file with the given index
SH::SampleComposite::doMakeFileList
virtual std::vector< std::string > doMakeFileList() const
make a list of all files, prestaging them if necessary
RCU_INVARIANT
#define RCU_INVARIANT(x)
Definition: Assert.h:201
SH::Sample::name
const std::string & name() const
the name of the sample we are using
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
SH::Sample::contains
bool contains(const std::string &name) const
whether this sample contains a sample of the given name
ThrowMsg.h
CxxUtils::to
CONT to(RANGE &&r)
Definition: ranges.h:32
SH::SampleComposite::doMakeLocal
virtual SamplePtr doMakeLocal() const
Make this a local sample, i.e.
RCU_CHANGE_INVARIANT
#define RCU_CHANGE_INVARIANT(x)
Definition: Assert.h:231
SH::SampleComposite::m_samples
std::vector< SamplePtr > m_samples
the list of samples we use
Definition: SampleComposite.h:120
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
SH::SampleComposite
This module defines an implementation of Sample that contains composite samples.
Definition: SampleComposite.h:31
RCU_READ_INVARIANT
#define RCU_READ_INVARIANT(x)
Definition: Assert.h:229
SampleComposite.h
RCU_NEW_INVARIANT
#define RCU_NEW_INVARIANT(x)
Definition: Assert.h:233