ATLAS Offline Software
JobConfig.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 
8 
9 //
10 // includes
11 //
12 
13 #include <EventLoop/JobConfig.h>
14 
16 #include <EventLoop/MessageCheck.h>
17 #include <RootCoreUtils/Assert.h>
18 #include <RootCoreUtils/ThrowMsg.h>
19 
20 //
21 // method implementations
22 //
23 
25 
26 namespace EL
27 {
28  void JobConfig ::
29  testInvariant () const
30  {
31  RCU_INVARIANT (this != nullptr);
32  }
33 
34 
35 
37  JobConfig () noexcept
38  {
39  RCU_NEW_INVARIANT (this);
40  }
41 
42 
43 
45  JobConfig (const JobConfig& that)
46  : TObject (that),
47  m_algorithmCount (that.m_algorithmCount)
48  {
49  RCU_READ_INVARIANT (&that);
50 
51  for (const auto& algorithm : that.m_algorithms)
52  {
53  if (algorithm != nullptr)
54  {
55  m_algorithms.push_back (algorithm->makeClone ());
56  } else
57  {
58  m_algorithms.emplace_back (nullptr);
59  }
60  }
61 
62  RCU_NEW_INVARIANT (this);
63  }
64 
65 
66 
68  JobConfig (JobConfig&& that) noexcept
69  : JobConfig ()
70  {
71  that.swap (*this);
72 
73  // no invariant used
74  }
75 
76 
77 
79  ~JobConfig () noexcept
80  {
81  RCU_DESTROY_INVARIANT (this);
82 
83  // not actually doing anything here, but have to make the
84  // destructor explicit to break include dependencies.
85  }
86 
87 
88 
90  operator = (const JobConfig& that)
91  {
92  // no invariant used
93  JobConfig (that).swap (*this);
94  return *this;
95  }
96 
97 
98 
100  operator = (JobConfig&& that) noexcept
101  {
102  // no invariant used
103  that.swap (*this);
104  return *this;
105  }
106 
107 
108 
109  void JobConfig ::
110  swap (JobConfig& that) noexcept
111  {
112  RCU_CHANGE_INVARIANT (this);
113  RCU_CHANGE_INVARIANT (&that);
114  std::swap (m_algorithmCount, that.m_algorithmCount);
115  m_algorithms.swap (that.m_algorithms);
116  }
117 
118 
119 
121  addAlgorithm (std::unique_ptr<IAlgorithmWrapper>&& val_algorithm)
122  {
123  using namespace msgEventLoop;
124 
125  RCU_CHANGE_INVARIANT (this);
126  RCU_REQUIRE (val_algorithm != nullptr);
127 
128  if (getAlgorithm (val_algorithm->getName()) != nullptr)
129  {
130  ANA_MSG_ERROR ("can't have two algorithms with the same name: " << val_algorithm->getName());
131  return ::StatusCode::FAILURE;
132  }
133 
134  m_algorithms.push_back (std::move (val_algorithm));
135  ++ m_algorithmCount;
136  return ::StatusCode::SUCCESS;
137  }
138 
139 
140 
141  const IAlgorithmWrapper *JobConfig ::
142  getAlgorithm (std::string_view name) const noexcept
143  {
144  RCU_READ_INVARIANT (this);
145  for (const auto& algorithm : m_algorithms)
146  {
147  if (algorithm != nullptr && algorithm->getName() == name)
148  return algorithm.get();
149  }
150  return nullptr;
151  }
152 
153 
154 
155  std::vector<std::unique_ptr<EL::IAlgorithmWrapper>> JobConfig ::
157  {
158  RCU_CHANGE_INVARIANT (this);
159  if (m_algorithmCount != m_algorithms.size())
160  RCU_THROW_MSG ("algorithm count missmatch. streaming error?");
161  for (const auto& algorithm : m_algorithms)
162  {
163  if (algorithm == nullptr)
164  RCU_THROW_MSG ("algorithm null. streaming error?");
165  }
166  m_algorithmCount = 0;
167  return std::move (m_algorithms);
168  }
169 
170 
171 
172  std::size_t JobConfig ::
173  numberOfAlgorithms () const noexcept
174  {
175  RCU_READ_INVARIANT (this);
176  return m_algorithms.size();
177  }
178 }
EL::JobConfig::getAlgorithm
const IAlgorithmWrapper * getAlgorithm(std::string_view name) const noexcept
get the algorithm with the given name, or nullptr if there is no algorithm with that name
algorithm
std::string algorithm
Definition: hcg.cxx:82
EL::JobConfig::~JobConfig
virtual ~JobConfig() noexcept
standard destructor
EL::JobConfig::testInvariant
void testInvariant() const
test the invariant of this object
EL::JobConfig::JobConfig
JobConfig() noexcept
standard constructor
RCU_REQUIRE
#define RCU_REQUIRE(x)
Definition: Assert.h:208
EL::JobConfig::operator=
JobConfig & operator=(const JobConfig &that)
standard assignment operator
ClassImp
ClassImp(EL::JobConfig) namespace EL
Definition: JobConfig.cxx:24
ANA_MSG_ERROR
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:294
EL::JobConfig::m_algorithms
std::vector< std::unique_ptr< EL::IAlgorithmWrapper > > m_algorithms
the list of algorithms added
Definition: JobConfig.h:163
Assert.h
MessageCheck.h
JobConfig
Definition: CoolFix.cxx:83
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
JobConfig.h
EL
This module defines the arguments passed from the BATCH driver to the BATCH worker.
Definition: AlgorithmWorkerData.h:24
WriteCalibToCool.swap
swap
Definition: WriteCalibToCool.py:94
RCU_INVARIANT
#define RCU_INVARIANT(x)
Definition: Assert.h:201
EL::JobConfig::addAlgorithm
::StatusCode addAlgorithm(std::unique_ptr< IAlgorithmWrapper > &&val_algorithm)
add an algorithm
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
ThrowMsg.h
EL::JobConfig
the job configuration that is independent of driver and dataset
Definition: JobConfig.h:39
RCU_DESTROY_INVARIANT
#define RCU_DESTROY_INVARIANT(x)
Definition: Assert.h:235
EL::JobConfig::numberOfAlgorithms
std::size_t numberOfAlgorithms() const noexcept
get the number of algorithms configured
RCU_CHANGE_INVARIANT
#define RCU_CHANGE_INVARIANT(x)
Definition: Assert.h:231
RCU_THROW_MSG
#define RCU_THROW_MSG(message)
Definition: PrintMsg.h:58
RCU_READ_INVARIANT
#define RCU_READ_INVARIANT(x)
Definition: Assert.h:229
EL::JobConfig::swap
void swap(JobConfig &that) noexcept
standard swap
EL::JobConfig::extractAlgorithms
std::vector< std::unique_ptr< EL::IAlgorithmWrapper > > extractAlgorithms()
extract the list of algorithms from this object
IAlgorithmWrapper.h
EL::JobConfig::m_algorithmCount
std::size_t m_algorithmCount
the number of algorithms added
Definition: JobConfig.h:155
RCU_NEW_INVARIANT
#define RCU_NEW_INVARIANT(x)
Definition: Assert.h:233