ATLAS Offline Software
Loading...
Searching...
No Matches
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
19
20#include <stdexcept>
21
22//
23// method implementations
24//
25
27
28namespace EL
29{
30 void JobConfig ::
31 testInvariant () const
32 {}
33
34
35
36 JobConfig ::
37 JobConfig () noexcept
38 {
39 RCU_NEW_INVARIANT (this);
40 }
41
42
43
44 JobConfig ::
45 JobConfig (const JobConfig& that)
46 : TObject (that),
47 m_algorithmCount (that.m_algorithmCount),
48 m_algSequenceStartIndices (that.m_algSequenceStartIndices)
49 {
50 RCU_READ_INVARIANT (&that);
51
52 for (const auto& algorithm : that.m_algorithms)
53 {
54 if (algorithm != nullptr)
55 {
56 m_algorithms.push_back (algorithm->makeClone ());
57 } else
58 {
59 m_algorithms.emplace_back (nullptr);
60 }
61 }
62
63 RCU_NEW_INVARIANT (this);
64 }
65
66
67
68 JobConfig ::
69 JobConfig (JobConfig&& that) noexcept
70 : JobConfig ()
71 {
72 that.swap (*this);
73
74 // no invariant used
75 }
76
77
78
79 JobConfig ::
80 ~JobConfig () noexcept
81 {
83
84 // not actually doing anything here, but have to make the
85 // destructor explicit to break include dependencies.
86 }
87
88
89
90 JobConfig& JobConfig ::
91 operator = (const JobConfig& that)
92 {
93 // no invariant used
94 JobConfig (that).swap (*this);
95 return *this;
96 }
97
98
99
100 JobConfig& JobConfig ::
101 operator = (JobConfig&& that) noexcept
102 {
103 // no invariant used
104 that.swap (*this);
105 return *this;
106 }
107
108
109
110 void JobConfig ::
111 swap (JobConfig& that) noexcept
112 {
114 RCU_CHANGE_INVARIANT (&that);
115 std::swap (m_algorithmCount, that.m_algorithmCount);
116 m_algorithms.swap (that.m_algorithms);
117 m_algSequenceStartIndices.swap (that.m_algSequenceStartIndices);
118 }
119
120
121
122 ::StatusCode JobConfig ::
123 addAlgorithm (std::unique_ptr<IAlgorithmWrapper>&& val_algorithm)
124 {
125 using namespace msgEventLoop;
126
128 RCU_REQUIRE (val_algorithm != nullptr);
129
130 if (getAlgorithm (val_algorithm->getName()) != nullptr)
131 {
132 ANA_MSG_ERROR ("can't have two algorithms with the same name: " << val_algorithm->getName());
133 return ::StatusCode::FAILURE;
134 }
135
136 m_algorithms.push_back (std::move (val_algorithm));
137 ++ m_algorithmCount;
138 return ::StatusCode::SUCCESS;
139 }
140
141
142
143 const IAlgorithmWrapper *JobConfig ::
144 getAlgorithm (std::string_view name) const noexcept
145 {
146 RCU_READ_INVARIANT (this);
147 for (const auto& algorithm : m_algorithms)
148 {
149 if (algorithm != nullptr && algorithm->getName() == name)
150 return algorithm.get();
151 }
152 return nullptr;
153 }
154
155
156
157 std::vector<Detail::AlgorithmData> JobConfig ::
158 extractAlgorithms ()
159 {
161 if (m_algorithmCount != m_algorithms.size())
162 throw std::runtime_error ("JobConfig::extractAlgorithms: algorithm count missmatch. streaming error?");
163 for (const auto& algorithm : m_algorithms)
164 {
165 if (algorithm == nullptr)
166 throw std::runtime_error ("JobConfig::extractAlgorithms: algorithm null. streaming error?");
167 }
168 m_algorithmCount = 0;
169 std::vector<Detail::AlgorithmData> result;
170 result.reserve (m_algorithms.size());
171 for (auto& algorithm : m_algorithms)
172 result.emplace_back (std::move (algorithm));
173 m_algorithms.clear();
174 for (auto sequenceStartIndex : m_algSequenceStartIndices)
175 {
176 // need to check here, since the user could have added a new
177 // sequence start at the end of the list, without adding an
178 // algorithm for it.
179 if (sequenceStartIndex < result.size())
180 result[sequenceStartIndex].m_sequenceStart = true;
181 }
182 // clear the sequence starts as well, so that reusing this JobConfig
183 // after extraction does not reapply the old starts to newly added
184 // algorithms
185 m_algSequenceStartIndices.clear();
186 return result;
187 }
188
189
190
191 std::size_t JobConfig ::
192 numberOfAlgorithms () const noexcept
193 {
194 RCU_READ_INVARIANT (this);
195 return m_algorithms.size();
196 }
197
198
199
200 void
201 JobConfig ::
202 startNewAlgSequence ()
203 {
205 m_algSequenceStartIndices.push_back (m_algorithms.size());
206 }
207}
#define RCU_DESTROY_INVARIANT(x)
Definition Assert.h:223
#define RCU_CHANGE_INVARIANT(x)
Definition Assert.h:219
#define RCU_NEW_INVARIANT(x)
Definition Assert.h:221
#define RCU_REQUIRE(x)
Definition Assert.h:196
#define RCU_READ_INVARIANT(x)
Definition Assert.h:217
#define ANA_MSG_ERROR(xmsg,...)
Macro printing error messages.
ClassImp(EL::JobConfig) namespace EL
Definition JobConfig.cxx:26
the job configuration that is independent of driver and dataset
Definition JobConfig.h:45
std::string algorithm
Definition hcg.cxx:87
This module defines the arguments passed from the BATCH driver to the BATCH worker.
::StatusCode StatusCode
StatusCode definition for legacy code.
void swap(ElementLinkVector< DOBJ > &lhs, ElementLinkVector< DOBJ > &rhs)