CMS 3D CMS Logo

BranchDescription.cc
Go to the documentation of this file.
2 
9 
10 #include "TDictAttributeMap.h"
11 
12 #include <cassert>
13 #include <ostream>
14 #include <sstream>
15 
16 class TClass;
17 
18 namespace edm {
20  parameterSetID_(),
21  moduleName_(),
22  branchName_(),
23  wrappedName_(),
24  wrappedType_(),
25  unwrappedType_(),
26  splitLevel_(),
27  basketSize_(),
28  produced_(false),
29  onDemand_(false),
30  dropped_(false),
31  transient_(false),
32  availableOnlyAtEndTransition_(false),
33  isMergeable_(false) {
34  }
35 
36  void
39  }
40 
43  moduleLabel_(),
44  processName_(),
45  branchID_(),
51  transient_(){
52  // do not call init here! It will result in an exception throw.
53  }
54 
56  BranchType const& branchType,
57  std::string const& moduleLabel,
58  std::string const& processName,
59  std::string const& className,
62  std::string const& moduleName,
64  TypeWithDict const& theTypeWithDict,
65  bool produced,
67  std::set<std::string> const& aliases) :
68  branchType_(branchType),
69  moduleLabel_(moduleLabel),
70  processName_(processName),
71  branchID_(),
72  fullClassName_(className),
73  friendlyClassName_(friendlyClassName),
74  productInstanceName_(productInstanceName),
75  branchAliases_(aliases),
76  transient_() {
77  setDropped(false);
78  setProduced(produced);
79  setOnDemand(false);
83  setUnwrappedType(theTypeWithDict);
84  init();
85  }
86 
88  BranchDescription const& aliasForBranch,
89  std::string const& moduleLabelAlias,
90  std::string const& productInstanceAlias) :
91  branchType_(aliasForBranch.branchType()),
92  moduleLabel_(moduleLabelAlias),
93  processName_(aliasForBranch.processName()),
94  branchID_(),
95  fullClassName_(aliasForBranch.className()),
96  friendlyClassName_(aliasForBranch.friendlyClassName()),
97  productInstanceName_(productInstanceAlias),
98  branchAliases_(aliasForBranch.branchAliases()),
99  aliasForBranchID_(aliasForBranch.branchID()),
100  transient_() {
101  setDropped(false);
102  setProduced(aliasForBranch.produced());
103  setOnDemand(false); // will be re-set externally to the aliasForBranch.onDemand() after that one has been set
105  transient_.moduleName_ = aliasForBranch.moduleName();
106  transient_.parameterSetID_ = aliasForBranch.parameterSetID();
107  setUnwrappedType(aliasForBranch.unwrappedType());
108  init();
109  }
110 
111  void
113  if(!branchName().empty()) {
114  return; // already called
115  }
116  throwIfInvalid_();
117 
118  char const underscore('_');
119  char const period('.');
120 
121  if(friendlyClassName_.find(underscore) != std::string::npos) {
122  throw cms::Exception("IllegalCharacter") << "Class name '" << friendlyClassName()
123  << "' contains an underscore ('_'), which is illegal in the name of a product.\n";
124  }
125 
126  // Module labels of non-persistent products are allowed to contain
127  // underscores. For module labels of persistent products, the module
128  // label is checked for underscores in the function initFromDictionary
129  // after we determine whether the product is persistent or not.
130 
131  if(productInstanceName_.find(underscore) != std::string::npos) {
132  throw cms::Exception("IllegalCharacter") << "Product instance name '" << productInstanceName()
133  << "' contains an underscore ('_'), which is illegal in a product instance name.\n";
134  }
135 
136  if(processName_.find(underscore) != std::string::npos) {
137  throw cms::Exception("IllegalCharacter") << "Process name '" << processName()
138  << "' contains an underscore ('_'), which is illegal in a process name.\n";
139  }
140 
142  brName.reserve(friendlyClassName().size() +
143  moduleLabel().size() +
145  processName().size() + 4);
146  brName += friendlyClassName();
147  brName += underscore;
148  brName += moduleLabel();
149  brName += underscore;
150  brName += productInstanceName();
151  brName += underscore;
152  brName += processName();
153  brName += period;
154 
155  if(!branchID_.isValid()) {
156  branchID_.setID(brName);
157  }
158  }
159 
160  void
162  if(bool(wrappedType())) {
163  return; // already initialized;
164  }
165 
166  throwIfInvalid_();
167 
168  try {
170  // unwrapped type.
172  if(!bool(unwrappedType())) {
175  setTransient(false);
176  return;
177  }
178  } catch( edm::Exception& caughtException) {
179  caughtException.addContext(std::string{"While initializing meta data for branch: "}+branchName());
180  throw;
181  }
182 
184  try {
185  setWrappedType(wrType);
186  if(!bool(wrappedType())) {
189  return;
190  }
191  } catch( edm::Exception& caughtException) {
192  caughtException.addContext(std::string{"While initializing meta data for branch: "}+branchName());
193  throw;
194  }
195 
196  setTransient(false);
199  TDictAttributeMap* wp = wrappedType().getClass()->GetAttributeMap();
200  if (wp && wp->HasKey("persistent") && !strcmp(wp->GetPropertyAsString("persistent"), "false")) {
201  // Set transient if persistent == "false".
202  setTransient(true);
203  return;
204  } else {
205  // Module labels of persistent products cannot contain underscores,
206  // but for non-persistent products it is allowed because path names
207  // are used as module labels for path status products and there
208  // are many path names that include underscores.
209  char const underscore('_');
210  if(moduleLabel_.find(underscore) != std::string::npos) {
211  throw cms::Exception("IllegalCharacter") << "Module label '" << moduleLabel()
212  << "' contains an underscore ('_'), which is illegal in a module label.\n";
213  }
214  }
215 
216  if (wp && wp->HasKey("splitLevel")) {
217  setSplitLevel(strtol(wp->GetPropertyAsString("splitLevel"), nullptr, 0));
218  if (splitLevel() < 0) {
219  throw cms::Exception("IllegalSplitLevel") << "' An illegal ROOT split level of " <<
220  splitLevel() << " is specified for class " << wrappedName() << ".'\n";
221  }
222  setSplitLevel(splitLevel() + 1); //Compensate for wrapper
223  }
224  if (wp && wp->HasKey("basketSize")) {
225  setBasketSize(strtol(wp->GetPropertyAsString("basketSize"), nullptr, 0));
226  if (basketSize() <= 0) {
227  throw cms::Exception("IllegalBasketSize") << "' An illegal ROOT basket size of " <<
228  basketSize() << " is specified for class " << wrappedName() << "'.\n";
229  }
230  }
231  }
232 
233  void
235  branchAliases_.insert(other.branchAliases().begin(), other.branchAliases().end());
238  }
239 
240  void
242  if(branchType_ != aliasForBranch.branchType()) {
243  throw Exception(errors::LogicError) << "BranchDescription::setSwitchAliasForBranch: branchType ("
244  << branchType_ << ") differs from aliasForBranch ("
245  << aliasForBranch.branchType() << ").\nPlease report this error to the FWCore developers";
246  }
247  if(produced() != aliasForBranch.produced()) {
248  throw Exception(errors::LogicError) << "BranchDescription::setSwitchAliasForBranch: produced differs from aliasForBranch.\nPlease report this error to the FWCore developers";
249  }
250  if(unwrappedTypeID().typeInfo() != aliasForBranch.unwrappedType().typeInfo()) {
251  throw Exception(errors::LogicError) << "BranchDescription::setSwitchAliasForBranch: unwrapped type info ("
252  << unwrappedTypeID().name() << ") differs from aliasForBranch ("
253  << aliasForBranch.unwrappedType().typeInfo().name() << ").\nPlease report this error to the FWCore developers";
254  }
255 
256  branchAliases_ = aliasForBranch.branchAliases();
259  }
260 
261  void
262  BranchDescription::write(std::ostream& os) const {
263  os << "Branch Type = " << branchType() << std::endl;
264  os << "Process Name = " << processName() << std::endl;
265  os << "ModuleLabel = " << moduleLabel() << std::endl;
266  os << "Branch ID = " << branchID() << '\n';
267  os << "Class Name = " << fullClassName() << '\n';
268  os << "Friendly Class Name = " << friendlyClassName() << '\n';
269  os << "Product Instance Name = " << productInstanceName() << std::endl;
270  }
271 
272  void throwExceptionWithText(char const* txt) {
274  e << "Problem using an incomplete BranchDescription\n"
275  << txt
276  << "\nPlease report this error to the FWCore developers";
277  throw e;
278  }
279 
280  void
283  throwExceptionWithText("Illegal BranchType detected");
284 
285  if(moduleLabel_.empty())
286  throwExceptionWithText("Module label is not allowed to be empty");
287 
288  if(processName_.empty())
289  throwExceptionWithText("Process name is not allowed to be empty");
290 
291  if(fullClassName_.empty())
292  throwExceptionWithText("Full class name is not allowed to be empty");
293 
294  if(friendlyClassName_.empty())
295  throwExceptionWithText("Friendly class name is not allowed to be empty");
296 
297  if(produced() && !parameterSetID().isValid())
298  throwExceptionWithText("Invalid ParameterSetID detected");
299  }
300 
301  void
304  clearBranchName();
305  initBranchName();
306  }
307 
308  bool
310  if(a.processName() < b.processName()) return true;
311  if(b.processName() < a.processName()) return false;
312  if(a.fullClassName() < b.fullClassName()) return true;
313  if(b.fullClassName() < a.fullClassName()) return false;
314  if(a.friendlyClassName() < b.friendlyClassName()) return true;
315  if(b.friendlyClassName() < a.friendlyClassName()) return false;
316  if(a.productInstanceName() < b.productInstanceName()) return true;
317  if(b.productInstanceName() < a.productInstanceName()) return false;
318  if(a.moduleLabel() < b.moduleLabel()) return true;
319  if(b.moduleLabel() < a.moduleLabel()) return false;
320  if(a.branchType() < b.branchType()) return true;
321  if(b.branchType() < a.branchType()) return false;
322  if(a.branchID() < b.branchID()) return true;
323  if(b.branchID() < a.branchID()) return false;
324  if(a.branchAliases() < b.branchAliases()) return true;
325  if(b.branchAliases() < a.branchAliases()) return false;
326  if(a.present() < b.present()) return true;
327  if(b.present() < a.present()) return false;
328  return false;
329  }
330 
331  bool
333  return
334  (a.branchType() == b.branchType()) &&
335  (a.processName() == b.processName()) &&
336  (a.fullClassName() == b.fullClassName()) &&
337  (a.friendlyClassName() == b.friendlyClassName()) &&
339  (a.moduleLabel() == b.moduleLabel()) &&
340  (a.branchID() == b.branchID());
341  }
342 
343  bool
345  return combinable(a, b) &&
346  (a.dropped() == b.dropped()) &&
347  (a.branchAliases() == b.branchAliases());
348  }
349 
352  std::string const& fileName) {
353  std::ostringstream differences;
354  if(a.branchName() != b.branchName()) {
355  differences << "Branch name '" << b.branchName() << "' does not match '" << a.branchName() << "'.\n";
356  // Need not compare components of branch name individually.
357  // (a.friendlyClassName() != b.friendlyClassName())
358  // (a.moduleLabel() != b.moduleLabel())
359  // (a.productInstanceName() != b.productInstanceName())
360  // (a.processName() != b.processName())
361  }
362  if(a.branchType() != b.branchType()) {
363  differences << "Branch '" << b.branchName() << "' is a(n) '" << b.branchType() << "' branch\n";
364  differences << " in file '" << fileName << "', but a(n) '" << a.branchType() << "' branch in previous files.\n";
365  }
366  if(a.branchID() != b.branchID()) {
367  differences << "Branch '" << b.branchName() << "' has a branch ID of '" << b.branchID() << "'\n";
368  differences << " in file '" << fileName << "', but '" << a.branchID() << "' in previous files.\n";
369  }
370  if(a.fullClassName() != b.fullClassName()) {
371  differences << "Products on branch '" << b.branchName() << "' have type '" << b.fullClassName() << "'\n";
372  differences << " in file '" << fileName << "', but '" << a.fullClassName() << "' in previous files.\n";
373  }
374  if(!b.dropped() && a.dropped()) {
375  differences << "Branch '" << a.branchName() << "' was dropped in the first input file but is present in '" << fileName << "'.\n";
376  }
377  return differences.str();
378  }
379 } // namespace edm
size
Write out results.
bool operator<(DetSet< T > const &x, DetSet< T > const &y)
Definition: DetSet.h:92
std::string const & branchName() const
BranchType const & branchType() const
static int const invalidSplitLevel
static int const invalidBasketSize
void setOnDemand(bool isOnDemand)
std::string const & processName() const
bool isValid() const
Definition: BranchID.h:24
void write(std::ostream &os) const
BranchType
Definition: BranchType.h:11
void setWrappedType(TypeWithDict const &type)
static TypeWithDict byName(std::string const &name)
Definition: TypeWithDict.cc:74
void setTransient(bool isTransient)
bool operator==(debugging_allocator< X > const &, debugging_allocator< Y > const &) noexcept
TClass * getClass() const
std::string const & className() const
std::string friendlyName(std::string const &iFullName)
std::string const & moduleLabel() const
std::string const & productInstanceName() const
bool combinable(BranchDescription const &a, BranchDescription const &b)
TypeID unwrappedTypeID() const
void setWrappedName(std::string const &name)
void setSplitLevel(int level)
std::string const & friendlyClassName() const
BranchID const & branchID() const
TypeWithDict const & unwrappedType() const
void setDropped(bool isDropped)
std::type_info const & typeInfo() const
std::string const & moduleName() const
void throwExceptionWithText(char const *txt)
std::string const & fullClassName() const
ParameterSetID const & parameterSetID() const
std::string wrappedClassName(std::string const &iFullName)
double b
Definition: hdecay.h:120
void addContext(std::string const &context)
Definition: Exception.cc:165
std::set< std::string > const & branchAliases() const
std::set< std::string > branchAliases_
HLT enums.
bool isValid() const
Definition: Hash.h:154
double a
Definition: hdecay.h:121
BranchID const & originalBranchID() const
bool availableOnlyAtEndTransition() const
void setUnwrappedType(TypeWithDict const &type)
void setBasketSize(int size)
void setProduced(bool isProduced)
void setSwitchAliasForBranch(BranchDescription const &aliasForBranch)
const char * name() const
Definition: TypeIDBase.h:44
std::string const & wrappedName() const
TypeWithDict const & wrappedType() const
void setID(std::string const &branchName)
Definition: BranchID.h:22
std::string match(BranchDescription const &a, BranchDescription const &b, std::string const &fileName)
void merge(BranchDescription const &other)