LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
BranchDescription.cc
Go to the documentation of this file.
2 // vim: set sw=2 expandtab :
3 
11 
12 #include <cassert>
13 #include <ostream>
14 
15 using namespace std;
16 
18 
19 namespace {
20 
21  [[noreturn]] void
22  throwExceptionWithText(char const* txt)
23  {
25  << "Problem using an incomplete BranchDescription\n"
26  << txt << "\nPlease report this error to the ART developers\n";
27  }
28 
29 } // unnamed namespace
30 
31 namespace art {
32 
33  BranchDescription::BranchDescription() = default;
34  BranchDescription::BranchDescription(BranchDescription const&) = default;
35  BranchDescription::BranchDescription(BranchDescription&&) = default;
36  BranchDescription& BranchDescription::operator=(BranchDescription const&) =
37  default;
38  BranchDescription& BranchDescription::operator=(BranchDescription&&) =
39  default;
40  BranchDescription::~BranchDescription() = default;
41 
42  BranchDescription::BranchDescription(
43  BranchType const bt,
44  TypeLabel const& tl,
45  std::string const& moduleLabel,
46  ParameterSetID const& modulePSetID,
47  ProcessConfiguration const& processConfig)
48  : BranchDescription{bt,
49  tl.hasEmulatedModule() ? tl.emulatedModule() :
51  processConfig.processName(),
52  tl.className(),
54  modulePSetID,
55  processConfig.id(),
58  tl.supportsView(),
59  tl.transient()}
60  {}
61 
63  BranchType const branchType,
64  std::string const& moduleLabel,
65  std::string const& processName,
66  std::string const& producedClassName,
67  std::string const& productInstanceName,
69  ProcessConfigurationID const& processConfigurationID,
70  Transients::validity_state const validity,
71  bool const supportsView,
72  bool const transient)
73  : branchType_{branchType}
80  {
81  guts().validity_ = validity;
82  guts().transient_ = transient;
83  psetIDs_.insert(psetID);
84  processConfigurationIDs_.insert(processConfigurationID);
88  }
89 
90  void
92  {
93  if (!transientsFluffed_()) {
94  return;
95  }
96  if (!productID_.isValid()) {
97  productID_.setID(guts().branchName_);
98  }
99  }
100 
101  void
103  {
104  if (transientsFluffed_()) {
105  return;
106  }
107  transients_.get().branchName_ = canonicalProductName(
109  transients_.get().wrappedName_ = wrappedClassName(producedClassName_);
110  }
111 
112  ParameterSetID const&
114  {
115  assert(!psetIDs().empty());
116  if (psetIDs().size() != 1) {
117  throw Exception(errors::Configuration, "AmbiguousProvenance")
118  << "Your application requires all events on Branch '"
119  << guts().branchName_
120  << "'\n to have the same provenance. This file has events with "
121  "mixed provenance\n"
122  << "on this branch. Use a different input file.\n";
123  }
124  return *psetIDs().begin();
125  }
126 
127  void
129  {
130  psetIDs_.insert(other.psetIDs().begin(), other.psetIDs().end());
131  processConfigurationIDs_.insert(other.processConfigurationIDs().begin(),
132  other.processConfigurationIDs().end());
134  guts().splitLevel_ = other.guts().splitLevel_;
135  }
136  if (guts().basketSize_ == invalidBasketSize) {
137  guts().basketSize_ = other.guts().basketSize_;
138  }
139  // FIXME: This is probably wrong! We are going from defaulted compression
140  // to a possibly different compression, bad.
141  if (guts().compression_ == invalidCompression) {
142  guts().compression_ = other.guts().compression_;
143  }
144  }
145 
146  void
147  BranchDescription::write(ostream& os) const
148  {
149  os << "Branch Type = " << branchType_ << endl;
150  os << "Process Name = " << processName() << endl;
151  os << "ModuleLabel = " << moduleLabel() << endl;
152  os << "Product ID = " << productID() << '\n';
153  os << "Class Name = " << producedClassName() << '\n';
154  os << "Friendly Class Name = " << friendlyClassName() << '\n';
155  os << "Product Instance Name = " << productInstanceName() << endl;
156  }
157 
158  void
160  {
161  using std::swap;
162  swap(branchType_, other.branchType_);
165  swap(productID_, other.productID_);
170  swap(psetIDs_, other.psetIDs_);
172  swap(transients_, other.transients_);
173  }
174 
175  // Note: throws
176  void
178  {
179  constexpr char underscore('_');
180  if (transientsFluffed_()) {
181  return;
182  }
183  if (branchType_ >= NumBranchTypes) {
184  throwExceptionWithText("Illegal BranchType detected");
185  }
186  if (moduleLabel_.empty()) {
187  throwExceptionWithText("Module label is not allowed to be empty");
188  }
189  if (processName_.empty()) {
190  throwExceptionWithText("Process name is not allowed to be empty");
191  }
192  if (producedClassName_.empty()) {
193  throwExceptionWithText("Full class name is not allowed to be empty");
194  }
195  if (friendlyClassName_.empty()) {
196  throwExceptionWithText("Friendly class name is not allowed to be empty");
197  }
198  if (friendlyClassName_.find(underscore) != string::npos) {
199  throw Exception(errors::LogicError, "IllegalCharacter")
200  << "Class name '" << friendlyClassName()
201  << "' contains an underscore ('_'), which is illegal in the "
202  << "name of a product.\n";
203  }
204  if (moduleLabel_.find(underscore) != string::npos) {
205  throw Exception(errors::Configuration, "IllegalCharacter")
206  << "Module label '" << moduleLabel()
207  << "' contains an underscore ('_'), which is illegal in a "
208  << "module label.\n";
209  }
210  if (productInstanceName_.find(underscore) != string::npos) {
211  throw Exception(errors::Configuration, "IllegalCharacter")
212  << "Product instance name '" << productInstanceName()
213  << "' contains an underscore ('_'), which is illegal in a "
214  << "product instance name.\n";
215  }
216  if (processName_.find(underscore) != string::npos) {
217  throw Exception(errors::Configuration, "IllegalCharacter")
218  << "Process name '" << processName()
219  << "' contains an underscore ('_'), which is illegal in a "
220  << "process name.\n";
221  }
222  }
223 
224  bool
226  {
227  return !guts().branchName_.empty();
228  }
229 
230  bool
232  {
233  return psetIDs().size() == 1;
234  }
235 
236  set<ProcessConfigurationID> const&
238  {
240  }
241 
244  {
245  return transients_.get();
246  }
247 
249  BranchDescription::guts() const noexcept
250  {
251  return transients_.get();
252  }
253 
254  bool
256  {
257  if (a.processName() < b.processName()) {
258  return true;
259  }
260  if (b.processName() < a.processName()) {
261  return false;
262  }
263  if (a.producedClassName() < b.producedClassName()) {
264  return true;
265  }
266  if (b.producedClassName() < a.producedClassName()) {
267  return false;
268  }
269  if (a.friendlyClassName() < b.friendlyClassName()) {
270  return true;
271  }
272  if (b.friendlyClassName() < a.friendlyClassName()) {
273  return false;
274  }
276  return true;
277  }
279  return false;
280  }
281  if (a.moduleLabel() < b.moduleLabel()) {
282  return true;
283  }
284  if (b.moduleLabel() < a.moduleLabel()) {
285  return false;
286  }
287  if (a.branchType() < b.branchType()) {
288  return true;
289  }
290  if (b.branchType() < a.branchType()) {
291  return false;
292  }
293  if (a.productID() < b.productID()) {
294  return true;
295  }
296  if (b.productID() < a.productID()) {
297  return false;
298  }
299  if (a.psetIDs() < b.psetIDs()) {
300  return true;
301  }
302  if (b.psetIDs() < a.psetIDs()) {
303  return false;
304  }
306  return true;
307  }
309  return false;
310  }
311  return false;
312  }
313 
314  bool
316  {
317  return (a.branchType() == b.branchType()) &&
318  (a.processName() == b.processName()) &&
319  (a.producedClassName() == b.producedClassName()) &&
320  (a.friendlyClassName() == b.friendlyClassName()) &&
322  (a.moduleLabel() == b.moduleLabel()) &&
323  (a.productID() == b.productID());
324  }
325 
326  bool
328  {
329  return combinable(a, b) && (a.psetIDs() == b.psetIDs()) &&
331  }
332 
333  std::ostream&
334  operator<<(std::ostream& os, BranchDescription const& p)
335  {
336  p.write(os);
337  return os;
338  }
339 
340 } // namespace art
std::string const & productInstanceName() const
Definition: TypeLabel.h:52
fhicl::ParameterSetID const & psetID() const
std::string const & emulatedModule() const
Definition: TypeLabel.cc:33
void merge(BranchDescription const &other)
std::set< fhicl::ParameterSetID > const & psetIDs() const noexcept
bool hasEmulatedModule() const
Definition: TypeLabel.h:57
std::string wrappedClassName(std::string const &className)
static int constexpr invalidCompression
STL namespace.
bool supportsView() const noexcept
friend bool operator<(BranchDescription const &, BranchDescription const &)
std::set< ProcessConfigurationID > processConfigurationIDs_
std::set< ProcessConfigurationID > const & processConfigurationIDs() const noexcept
bool supportsView() const
Definition: TypeLabel.h:62
ProcessConfigurationID id() const
std::string const & processName() const noexcept
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:101
BranchType branchType() const noexcept
std::ostream & operator<<(std::ostream &os, const GroupSelector &gs)
constexpr bool isValid() const noexcept
Definition: ProductID.h:34
static int constexpr invalidSplitLevel
void swap(BranchDescription &other)
std::string canonicalProductName(std::string const &friendlyClassName, std::string const &moduleLabel, std::string const &productInstanceName, std::string const &processName)
void setID(std::string const &canonicalProductName)
Definition: ProductID.cc:13
void write(std::ostream &os) const
std::string friendlyName(std::string const &iFullName)
std::string const & moduleLabel() const noexcept
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
std::set< fhicl::ParameterSetID > psetIDs_
bool transientsFluffed_() const noexcept
bool isPsetIDUnique() const noexcept
bool transient() const
Definition: TypeLabel.h:67
std::string const & productInstanceName() const noexcept
BranchType
Definition: BranchType.h:20
std::string const & producedClassName() const noexcept
void swap(lar::deep_const_fwd_iterator_nested< CITER, INNERCONTEXTRACT > &a, lar::deep_const_fwd_iterator_nested< CITER, INNERCONTEXTRACT > &b)
Definition: MVAAlg.h:12
std::string const & processName() const noexcept
friend bool combinable(BranchDescription const &, BranchDescription const &)
std::string const & friendlyClassName() const noexcept
static int constexpr invalidBasketSize
std::string className() const
Definition: TypeLabel.h:41
friend bool operator==(BranchDescription const &, BranchDescription const &)
Transient< Transients > transients_
ProductID productID() const noexcept
Transients & guts() noexcept
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.
Definition: StdUtils.h:109
Definition: Hash.h:34