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(aliasForBranch.onDemand());
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
241  BranchDescription::write(std::ostream& os) const {
242  os << "Branch Type = " << branchType() << std::endl;
243  os << "Process Name = " << processName() << std::endl;
244  os << "ModuleLabel = " << moduleLabel() << std::endl;
245  os << "Branch ID = " << branchID() << '\n';
246  os << "Class Name = " << fullClassName() << '\n';
247  os << "Friendly Class Name = " << friendlyClassName() << '\n';
248  os << "Product Instance Name = " << productInstanceName() << std::endl;
249  }
250 
251  void throwExceptionWithText(char const* txt) {
253  e << "Problem using an incomplete BranchDescription\n"
254  << txt
255  << "\nPlease report this error to the FWCore developers";
256  throw e;
257  }
258 
259  void
262  throwExceptionWithText("Illegal BranchType detected");
263 
264  if(moduleLabel_.empty())
265  throwExceptionWithText("Module label is not allowed to be empty");
266 
267  if(processName_.empty())
268  throwExceptionWithText("Process name is not allowed to be empty");
269 
270  if(fullClassName_.empty())
271  throwExceptionWithText("Full class name is not allowed to be empty");
272 
273  if(friendlyClassName_.empty())
274  throwExceptionWithText("Friendly class name is not allowed to be empty");
275 
276  if(produced() && !parameterSetID().isValid())
277  throwExceptionWithText("Invalid ParameterSetID detected");
278  }
279 
280  void
283  clearBranchName();
284  initBranchName();
285  }
286 
287  bool
289  if(a.processName() < b.processName()) return true;
290  if(b.processName() < a.processName()) return false;
291  if(a.fullClassName() < b.fullClassName()) return true;
292  if(b.fullClassName() < a.fullClassName()) return false;
293  if(a.friendlyClassName() < b.friendlyClassName()) return true;
294  if(b.friendlyClassName() < a.friendlyClassName()) return false;
295  if(a.productInstanceName() < b.productInstanceName()) return true;
296  if(b.productInstanceName() < a.productInstanceName()) return false;
297  if(a.moduleLabel() < b.moduleLabel()) return true;
298  if(b.moduleLabel() < a.moduleLabel()) return false;
299  if(a.branchType() < b.branchType()) return true;
300  if(b.branchType() < a.branchType()) return false;
301  if(a.branchID() < b.branchID()) return true;
302  if(b.branchID() < a.branchID()) return false;
303  if(a.branchAliases() < b.branchAliases()) return true;
304  if(b.branchAliases() < a.branchAliases()) return false;
305  if(a.present() < b.present()) return true;
306  if(b.present() < a.present()) return false;
307  return false;
308  }
309 
310  bool
312  return
313  (a.branchType() == b.branchType()) &&
314  (a.processName() == b.processName()) &&
315  (a.fullClassName() == b.fullClassName()) &&
316  (a.friendlyClassName() == b.friendlyClassName()) &&
318  (a.moduleLabel() == b.moduleLabel()) &&
319  (a.branchID() == b.branchID());
320  }
321 
322  bool
324  return combinable(a, b) &&
325  (a.dropped() == b.dropped()) &&
326  (a.branchAliases() == b.branchAliases());
327  }
328 
331  std::string const& fileName) {
332  std::ostringstream differences;
333  if(a.branchName() != b.branchName()) {
334  differences << "Branch name '" << b.branchName() << "' does not match '" << a.branchName() << "'.\n";
335  // Need not compare components of branch name individually.
336  // (a.friendlyClassName() != b.friendlyClassName())
337  // (a.moduleLabel() != b.moduleLabel())
338  // (a.productInstanceName() != b.productInstanceName())
339  // (a.processName() != b.processName())
340  }
341  if(a.branchType() != b.branchType()) {
342  differences << "Branch '" << b.branchName() << "' is a(n) '" << b.branchType() << "' branch\n";
343  differences << " in file '" << fileName << "', but a(n) '" << a.branchType() << "' branch in previous files.\n";
344  }
345  if(a.branchID() != b.branchID()) {
346  differences << "Branch '" << b.branchName() << "' has a branch ID of '" << b.branchID() << "'\n";
347  differences << " in file '" << fileName << "', but '" << a.branchID() << "' in previous files.\n";
348  }
349  if(a.fullClassName() != b.fullClassName()) {
350  differences << "Products on branch '" << b.branchName() << "' have type '" << b.fullClassName() << "'\n";
351  differences << " in file '" << fileName << "', but '" << a.fullClassName() << "' in previous files.\n";
352  }
353  if(!b.dropped() && a.dropped()) {
354  differences << "Branch '" << a.branchName() << "' was dropped in the first input file but is present in '" << fileName << "'.\n";
355  }
356  return differences.str();
357  }
358 } // namespace edm
size
Write out results.
bool operator<(DetSet< T > const &x, DetSet< T > const &y)
Definition: DetSet.h:90
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:82
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)
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::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:227
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
bool availableOnlyAtEndTransition() const
void setUnwrappedType(TypeWithDict const &type)
void setBasketSize(int size)
void setProduced(bool isProduced)
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)