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  }
34 
35  void
38  }
39 
42  moduleLabel_(),
43  processName_(),
44  branchID_(),
50  transient_(){
51  // do not call init here! It will result in an exception throw.
52  }
53 
55  BranchType const& branchType,
56  std::string const& moduleLabel,
57  std::string const& processName,
58  std::string const& className,
61  std::string const& moduleName,
63  TypeWithDict const& theTypeWithDict,
64  bool produced,
66  std::set<std::string> const& aliases) :
67  branchType_(branchType),
68  moduleLabel_(moduleLabel),
69  processName_(processName),
70  branchID_(),
71  fullClassName_(className),
72  friendlyClassName_(friendlyClassName),
73  productInstanceName_(productInstanceName),
74  branchAliases_(aliases),
75  transient_() {
76  setDropped(false);
77  setProduced(produced);
78  setOnDemand(false);
82  setUnwrappedType(theTypeWithDict);
83  init();
84  }
85 
87  BranchDescription const& aliasForBranch,
88  std::string const& moduleLabelAlias,
89  std::string const& productInstanceAlias) :
90  branchType_(aliasForBranch.branchType()),
91  moduleLabel_(moduleLabelAlias),
92  processName_(aliasForBranch.processName()),
93  branchID_(),
94  fullClassName_(aliasForBranch.className()),
95  friendlyClassName_(aliasForBranch.friendlyClassName()),
96  productInstanceName_(productInstanceAlias),
97  branchAliases_(aliasForBranch.branchAliases()),
98  aliasForBranchID_(aliasForBranch.branchID()),
99  transient_() {
100  setDropped(false);
101  setProduced(aliasForBranch.produced());
102  setOnDemand(aliasForBranch.onDemand());
104  transient_.moduleName_ = aliasForBranch.moduleName();
105  transient_.parameterSetID_ = aliasForBranch.parameterSetID();
106  setUnwrappedType(aliasForBranch.unwrappedType());
107  init();
108  }
109 
110  void
112  if(!branchName().empty()) {
113  return; // already called
114  }
115  throwIfInvalid_();
116 
117  char const underscore('_');
118  char const period('.');
119 
120  if(friendlyClassName_.find(underscore) != std::string::npos) {
121  throw cms::Exception("IllegalCharacter") << "Class name '" << friendlyClassName()
122  << "' contains an underscore ('_'), which is illegal in the name of a product.\n";
123  }
124 
125  // Module labels of non-persistent products are allowed to contain
126  // underscores. For module labels of persistent products, the module
127  // label is checked for underscores in the function initFromDictionary
128  // after we determine whether the product is persistent or not.
129 
130  if(productInstanceName_.find(underscore) != std::string::npos) {
131  throw cms::Exception("IllegalCharacter") << "Product instance name '" << productInstanceName()
132  << "' contains an underscore ('_'), which is illegal in a product instance name.\n";
133  }
134 
135  if(processName_.find(underscore) != std::string::npos) {
136  throw cms::Exception("IllegalCharacter") << "Process name '" << processName()
137  << "' contains an underscore ('_'), which is illegal in a process name.\n";
138  }
139 
141  brName.reserve(friendlyClassName().size() +
142  moduleLabel().size() +
144  processName().size() + 4);
145  brName += friendlyClassName();
146  brName += underscore;
147  brName += moduleLabel();
148  brName += underscore;
149  brName += productInstanceName();
150  brName += underscore;
151  brName += processName();
152  brName += period;
153 
154  if(!branchID_.isValid()) {
155  branchID_.setID(brName);
156  }
157  }
158 
159  void
161  if(bool(wrappedType())) {
162  return; // already initialized;
163  }
164 
165  throwIfInvalid_();
166 
167  try {
169  // unwrapped type.
171  if(!bool(unwrappedType())) {
174  setTransient(false);
175  return;
176  }
177  } catch( edm::Exception& caughtException) {
178  caughtException.addContext(std::string{"While initializing meta data for branch: "}+branchName());
179  throw;
180  }
181 
183  try {
184  setWrappedType(wrType);
185  if(!bool(wrappedType())) {
188  return;
189  }
190  } catch( edm::Exception& caughtException) {
191  caughtException.addContext(std::string{"While initializing meta data for branch: "}+branchName());
192  throw;
193  }
194 
195  setTransient(false);
198  TDictAttributeMap* wp = wrappedType().getClass()->GetAttributeMap();
199  if (wp && wp->HasKey("persistent") && !strcmp(wp->GetPropertyAsString("persistent"), "false")) {
200  // Set transient if persistent == "false".
201  setTransient(true);
202  return;
203  } else {
204  // Module labels of persistent products cannot contain underscores,
205  // but for non-persistent products it is allowed because path names
206  // are used as module labels for path status products and there
207  // are many path names that include underscores.
208  char const underscore('_');
209  if(moduleLabel_.find(underscore) != std::string::npos) {
210  throw cms::Exception("IllegalCharacter") << "Module label '" << moduleLabel()
211  << "' contains an underscore ('_'), which is illegal in a module label.\n";
212  }
213  }
214 
215  if (wp && wp->HasKey("splitLevel")) {
216  setSplitLevel(strtol(wp->GetPropertyAsString("splitLevel"), nullptr, 0));
217  if (splitLevel() < 0) {
218  throw cms::Exception("IllegalSplitLevel") << "' An illegal ROOT split level of " <<
219  splitLevel() << " is specified for class " << wrappedName() << ".'\n";
220  }
221  setSplitLevel(splitLevel() + 1); //Compensate for wrapper
222  }
223  if (wp && wp->HasKey("basketSize")) {
224  setBasketSize(strtol(wp->GetPropertyAsString("basketSize"), nullptr, 0));
225  if (basketSize() <= 0) {
226  throw cms::Exception("IllegalBasketSize") << "' An illegal ROOT basket size of " <<
227  basketSize() << " is specified for class " << wrappedName() << "'.\n";
228  }
229  }
230  }
231 
232  void
234  branchAliases_.insert(other.branchAliases().begin(), other.branchAliases().end());
237  }
238 
239  void
240  BranchDescription::write(std::ostream& os) const {
241  os << "Branch Type = " << branchType() << std::endl;
242  os << "Process Name = " << processName() << std::endl;
243  os << "ModuleLabel = " << moduleLabel() << std::endl;
244  os << "Branch ID = " << branchID() << '\n';
245  os << "Class Name = " << fullClassName() << '\n';
246  os << "Friendly Class Name = " << friendlyClassName() << '\n';
247  os << "Product Instance Name = " << productInstanceName() << std::endl;
248  }
249 
250  void throwExceptionWithText(char const* txt) {
252  e << "Problem using an incomplete BranchDescription\n"
253  << txt
254  << "\nPlease report this error to the FWCore developers";
255  throw e;
256  }
257 
258  void
261  throwExceptionWithText("Illegal BranchType detected");
262 
263  if(moduleLabel_.empty())
264  throwExceptionWithText("Module label is not allowed to be empty");
265 
266  if(processName_.empty())
267  throwExceptionWithText("Process name is not allowed to be empty");
268 
269  if(fullClassName_.empty())
270  throwExceptionWithText("Full class name is not allowed to be empty");
271 
272  if(friendlyClassName_.empty())
273  throwExceptionWithText("Friendly class name is not allowed to be empty");
274 
275  if(produced() && !parameterSetID().isValid())
276  throwExceptionWithText("Invalid ParameterSetID detected");
277  }
278 
279  void
282  clearBranchName();
283  initBranchName();
284  }
285 
286  bool
288  if(a.processName() < b.processName()) return true;
289  if(b.processName() < a.processName()) return false;
290  if(a.fullClassName() < b.fullClassName()) return true;
291  if(b.fullClassName() < a.fullClassName()) return false;
292  if(a.friendlyClassName() < b.friendlyClassName()) return true;
293  if(b.friendlyClassName() < a.friendlyClassName()) return false;
294  if(a.productInstanceName() < b.productInstanceName()) return true;
295  if(b.productInstanceName() < a.productInstanceName()) return false;
296  if(a.moduleLabel() < b.moduleLabel()) return true;
297  if(b.moduleLabel() < a.moduleLabel()) return false;
298  if(a.branchType() < b.branchType()) return true;
299  if(b.branchType() < a.branchType()) return false;
300  if(a.branchID() < b.branchID()) return true;
301  if(b.branchID() < a.branchID()) return false;
302  if(a.branchAliases() < b.branchAliases()) return true;
303  if(b.branchAliases() < a.branchAliases()) return false;
304  if(a.present() < b.present()) return true;
305  if(b.present() < a.present()) return false;
306  return false;
307  }
308 
309  bool
311  return
312  (a.branchType() == b.branchType()) &&
313  (a.processName() == b.processName()) &&
314  (a.fullClassName() == b.fullClassName()) &&
315  (a.friendlyClassName() == b.friendlyClassName()) &&
317  (a.moduleLabel() == b.moduleLabel()) &&
318  (a.branchID() == b.branchID());
319  }
320 
321  bool
323  return combinable(a, b) &&
324  (a.dropped() == b.dropped()) &&
325  (a.branchAliases() == b.branchAliases());
326  }
327 
330  std::string const& fileName) {
331  std::ostringstream differences;
332  if(a.branchName() != b.branchName()) {
333  differences << "Branch name '" << b.branchName() << "' does not match '" << a.branchName() << "'.\n";
334  // Need not compare components of branch name individually.
335  // (a.friendlyClassName() != b.friendlyClassName())
336  // (a.moduleLabel() != b.moduleLabel())
337  // (a.productInstanceName() != b.productInstanceName())
338  // (a.processName() != b.processName())
339  }
340  if(a.branchType() != b.branchType()) {
341  differences << "Branch '" << b.branchName() << "' is a(n) '" << b.branchType() << "' branch\n";
342  differences << " in file '" << fileName << "', but a(n) '" << a.branchType() << "' branch in previous files.\n";
343  }
344  if(a.branchID() != b.branchID()) {
345  differences << "Branch '" << b.branchName() << "' has a branch ID of '" << b.branchID() << "'\n";
346  differences << " in file '" << fileName << "', but '" << a.branchID() << "' in previous files.\n";
347  }
348  if(a.fullClassName() != b.fullClassName()) {
349  differences << "Products on branch '" << b.branchName() << "' have type '" << b.fullClassName() << "'\n";
350  differences << " in file '" << fileName << "', but '" << a.fullClassName() << "' in previous files.\n";
351  }
352  if(!b.dropped() && a.dropped()) {
353  differences << "Branch '" << a.branchName() << "' was dropped in the first input file but is present in '" << fileName << "'.\n";
354  }
355  return differences.str();
356  }
357 } // 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)