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 RCU_INVARIANT (this != nullptr);
34 }
35
36
37
38 JobConfig ::
39 JobConfig () noexcept
40 {
41 RCU_NEW_INVARIANT (this);
42 }
43
44
45
46 JobConfig ::
47 JobConfig (const JobConfig& that)
48 : TObject (that),
49 m_algorithmCount (that.m_algorithmCount),
50 m_algSequenceStartIndices (that.m_algSequenceStartIndices)
51 {
52 RCU_READ_INVARIANT (&that);
53
54 for (const auto& algorithm : that.m_algorithms)
55 {
56 if (algorithm != nullptr)
57 {
58 m_algorithms.push_back (algorithm->makeClone ());
59 } else
60 {
61 m_algorithms.emplace_back (nullptr);
62 }
63 }
64
65 RCU_NEW_INVARIANT (this);
66 }
67
68
69
70 JobConfig ::
71 JobConfig (JobConfig&& that) noexcept
72 : JobConfig ()
73 {
74 that.swap (*this);
75
76 // no invariant used
77 }
78
79
80
81 JobConfig ::
82 ~JobConfig () noexcept
83 {
85
86 // not actually doing anything here, but have to make the
87 // destructor explicit to break include dependencies.
88 }
89
90
91
92 JobConfig& JobConfig ::
93 operator = (const JobConfig& that)
94 {
95 // no invariant used
96 JobConfig (that).swap (*this);
97 return *this;
98 }
99
100
101
102 JobConfig& JobConfig ::
103 operator = (JobConfig&& that) noexcept
104 {
105 // no invariant used
106 that.swap (*this);
107 return *this;
108 }
109
110
111
112 void JobConfig ::
113 swap (JobConfig& that) noexcept
114 {
116 RCU_CHANGE_INVARIANT (&that);
117 std::swap (m_algorithmCount, that.m_algorithmCount);
118 m_algorithms.swap (that.m_algorithms);
119 m_algSequenceStartIndices.swap (that.m_algSequenceStartIndices);
120 }
121
122
123
124 ::StatusCode JobConfig ::
125 addAlgorithm (std::unique_ptr<IAlgorithmWrapper>&& val_algorithm)
126 {
127 using namespace msgEventLoop;
128
130 RCU_REQUIRE (val_algorithm != nullptr);
131
132 if (getAlgorithm (val_algorithm->getName()) != nullptr)
133 {
134 ANA_MSG_ERROR ("can't have two algorithms with the same name: " << val_algorithm->getName());
135 return ::StatusCode::FAILURE;
136 }
137
138 m_algorithms.push_back (std::move (val_algorithm));
139 ++ m_algorithmCount;
140 return ::StatusCode::SUCCESS;
141 }
142
143
144
145 const IAlgorithmWrapper *JobConfig ::
146 getAlgorithm (std::string_view name) const noexcept
147 {
148 RCU_READ_INVARIANT (this);
149 for (const auto& algorithm : m_algorithms)
150 {
151 if (algorithm != nullptr && algorithm->getName() == name)
152 return algorithm.get();
153 }
154 return nullptr;
155 }
156
157
158
159 std::vector<Detail::AlgorithmData> JobConfig ::
160 extractAlgorithms ()
161 {
163 if (m_algorithmCount != m_algorithms.size())
164 throw std::runtime_error ("JobConfig::extractAlgorithms: algorithm count missmatch. streaming error?");
165 for (const auto& algorithm : m_algorithms)
166 {
167 if (algorithm == nullptr)
168 throw std::runtime_error ("JobConfig::extractAlgorithms: algorithm null. streaming error?");
169 }
170 m_algorithmCount = 0;
171 std::vector<Detail::AlgorithmData> result;
172 result.reserve (m_algorithms.size());
173 for (auto& algorithm : m_algorithms)
174 result.emplace_back (std::move (algorithm));
175 m_algorithms.clear();
176 for (auto sequenceStartIndex : m_algSequenceStartIndices)
177 {
178 // need to check here, since the user could have added a new
179 // sequence start at the end of the list, without adding an
180 // algorithm for it.
181 if (sequenceStartIndex < result.size())
182 result[sequenceStartIndex].m_sequenceStart = true;
183 }
184 return result;
185 }
186
187
188
189 std::size_t JobConfig ::
190 numberOfAlgorithms () const noexcept
191 {
192 RCU_READ_INVARIANT (this);
193 return m_algorithms.size();
194 }
195
196
197
198 void
199 JobConfig ::
200 startNewAlgSequence ()
201 {
203 m_algSequenceStartIndices.push_back (m_algorithms.size());
204 }
205}
#define RCU_INVARIANT(x)
Definition Assert.h:189
#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)