CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
BranchDescription.cc
Go to the documentation of this file.
7 
8 #include <ostream>
9 #include <sstream>
10 #include <stdlib.h>
11 
12 class TClass;
13 /*----------------------------------------------------------------------
14 
15 
16 ----------------------------------------------------------------------*/
17 
18 namespace edm {
20  parameterSetID_(),
21  moduleName_(),
22  branchName_(),
23  wrappedName_(),
24  produced_(false),
25  onDemand_(false),
26  dropped_(false),
27  parameterSetIDs_(),
28  moduleNames_(),
29  transient_(false),
30  wrappedType_(),
31  unwrappedType_(),
32  wrapperInterfaceBase_(nullptr),
33  splitLevel_(),
34  basketSize_() {
35  }
36 
37  void
40  }
41 
44  moduleLabel_(),
45  processName_(),
46  branchID_(),
52  transient_() {
53  // do not call init here! It will result in an exception throw.
54  }
55 
57  BranchType const& branchType,
58  std::string const& moduleLabel,
59  std::string const& processName,
60  std::string const& className,
61  std::string const& friendlyClassName,
62  std::string const& productInstanceName,
63  std::string const& moduleName,
64  ParameterSetID const& parameterSetID,
65  TypeWithDict const& theTypeWithDict,
66  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  dropped() = false;
79  onDemand() = false;
82  unwrappedType() = 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  dropped() = false;
101  transient_.produced_ = aliasForBranch.produced(),
102  onDemand() = aliasForBranch.onDemand();
103  transient_.moduleName_ = aliasForBranch.moduleName();
104  transient_.parameterSetID_ = aliasForBranch.parameterSetID();
105  unwrappedType() = aliasForBranch.unwrappedType();
106  init();
107  }
108 
109  void
111  if(!branchName().empty()) {
112  return; // already called
113  }
114  throwIfInvalid_();
115 
116  char const underscore('_');
117  char const period('.');
118 
119  if(friendlyClassName_.find(underscore) != std::string::npos) {
120  throw cms::Exception("IllegalCharacter") << "Class name '" << friendlyClassName()
121  << "' contains an underscore ('_'), which is illegal in the name of a product.\n";
122  }
123 
124  if(moduleLabel_.find(underscore) != std::string::npos) {
125  throw cms::Exception("IllegalCharacter") << "Module label '" << moduleLabel()
126  << "' contains an underscore ('_'), which is illegal in a module label.\n";
127  }
128 
129  if(productInstanceName_.find(underscore) != std::string::npos) {
130  throw cms::Exception("IllegalCharacter") << "Product instance name '" << productInstanceName()
131  << "' contains an underscore ('_'), which is illegal in a product instance name.\n";
132  }
133 
134  if(processName_.find(underscore) != std::string::npos) {
135  throw cms::Exception("IllegalCharacter") << "Process name '" << processName()
136  << "' contains an underscore ('_'), which is illegal in a process name.\n";
137  }
138 
139  branchName().reserve(friendlyClassName().size() +
140  moduleLabel().size() +
142  processName().size() + 4);
144  branchName() += underscore;
145  branchName() += moduleLabel();
146  branchName() += underscore;
148  branchName() += underscore;
149  branchName() += processName();
150  branchName() += period;
151 
152  if(!branchID_.isValid()) {
154  }
155  }
156 
157  void
159  if(bool(wrappedType())) {
160  return; // already initialized;
161  }
162 
163  throwIfInvalid_();
164 
166 
167  // unwrapped type.
169  if(!bool(unwrappedType())) {
172  transient() = false;
173  return;
174  }
175 
177  if(!bool(wrappedType())) {
180  return;
181  }
182  Reflex::PropertyList wp = Reflex::Type::ByTypeInfo(wrappedType().typeInfo()).Properties();
183  transient() = (wp.HasProperty("persistent") ? wp.PropertyAsString("persistent") == std::string("false") : false);
184  if(transient()) {
187  return;
188  }
189  if(wp.HasProperty("splitLevel")) {
190  splitLevel() = strtol(wp.PropertyAsString("splitLevel").c_str(), 0, 0);
191  if(splitLevel() < 0) {
192  throw cms::Exception("IllegalSplitLevel") << "' An illegal ROOT split level of " <<
193  splitLevel() << " is specified for class " << wrappedName() << ".'\n";
194  }
195  ++splitLevel(); //Compensate for wrapper
196  } else {
198  }
199  if(wp.HasProperty("basketSize")) {
200  basketSize() = strtol(wp.PropertyAsString("basketSize").c_str(), 0, 0);
201  if(basketSize() <= 0) {
202  throw cms::Exception("IllegalBasketSize") << "' An illegal ROOT basket size of " <<
203  basketSize() << " is specified for class " << wrappedName() << "'.\n";
204  }
205  } else {
207  }
208  }
209 
210  ParameterSetID const&
212  assert(!parameterSetIDs().empty());
213  if(parameterSetIDs().size() != 1) {
214  throw cms::Exception("Ambiguous")
215  << "Your application requires all events on Branch '" << branchName()
216  << "'\n to have the same provenance. This file has events with mixed provenance\n"
217  << "on this branch. Use a different input file.\n";
218  }
219  return parameterSetIDs().begin()->second;
220  }
221 
222  void
224  parameterSetIDs().insert(other.parameterSetIDs().begin(), other.parameterSetIDs().end());
225  moduleNames().insert(other.moduleNames().begin(), other.moduleNames().end());
226  branchAliases_.insert(other.branchAliases().begin(), other.branchAliases().end());
227  if(splitLevel() == invalidSplitLevel) splitLevel() = other.splitLevel();
228  if(basketSize() == invalidBasketSize) basketSize() = other.basketSize();
229  }
230 
231  void
232  BranchDescription::write(std::ostream& os) const {
233  os << "Branch Type = " << branchType() << std::endl;
234  os << "Process Name = " << processName() << std::endl;
235  os << "ModuleLabel = " << moduleLabel() << std::endl;
236  os << "Branch ID = " << branchID() << '\n';
237  os << "Class Name = " << fullClassName() << '\n';
238  os << "Friendly Class Name = " << friendlyClassName() << '\n';
239  os << "Product Instance Name = " << productInstanceName() << std::endl;
240  }
241 
242  void throwExceptionWithText(char const* txt) {
244  e << "Problem using an incomplete BranchDescription\n"
245  << txt
246  << "\nPlease report this error to the FWCore developers";
247  throw e;
248  }
249 
250  void
253  throwExceptionWithText("Illegal BranchType detected");
254 
255  if(moduleLabel_.empty())
256  throwExceptionWithText("Module label is not allowed to be empty");
257 
258  if(processName_.empty())
259  throwExceptionWithText("Process name is not allowed to be empty");
260 
261  if(fullClassName_.empty())
262  throwExceptionWithText("Full class name is not allowed to be empty");
263 
264  if(friendlyClassName_.empty())
265  throwExceptionWithText("Friendly class name is not allowed to be empty");
266 
267  if(produced() && !parameterSetID().isValid())
268  throwExceptionWithText("Invalid ParameterSetID detected");
269  }
270 
271  void
274  branchName().clear();
275  initBranchName();
276  }
277 
278  bool
280  if(a.processName() < b.processName()) return true;
281  if(b.processName() < a.processName()) return false;
282  if(a.fullClassName() < b.fullClassName()) return true;
283  if(b.fullClassName() < a.fullClassName()) return false;
284  if(a.friendlyClassName() < b.friendlyClassName()) return true;
285  if(b.friendlyClassName() < a.friendlyClassName()) return false;
286  if(a.productInstanceName() < b.productInstanceName()) return true;
287  if(b.productInstanceName() < a.productInstanceName()) return false;
288  if(a.moduleLabel() < b.moduleLabel()) return true;
289  if(b.moduleLabel() < a.moduleLabel()) return false;
290  if(a.branchType() < b.branchType()) return true;
291  if(b.branchType() < a.branchType()) return false;
292  if(a.branchID() < b.branchID()) return true;
293  if(b.branchID() < a.branchID()) return false;
294  if(a.parameterSetIDs() < b.parameterSetIDs()) return true;
295  if(b.parameterSetIDs() < a.parameterSetIDs()) return false;
296  if(a.moduleNames() < b.moduleNames()) return true;
297  if(b.moduleNames() < a.moduleNames()) return false;
298  if(a.branchAliases() < b.branchAliases()) return true;
299  if(b.branchAliases() < a.branchAliases()) return false;
300  if(a.present() < b.present()) return true;
301  if(b.present() < a.present()) return false;
302  return false;
303  }
304 
305  bool
307  return
308  (a.branchType() == b.branchType()) &&
309  (a.processName() == b.processName()) &&
310  (a.fullClassName() == b.fullClassName()) &&
311  (a.friendlyClassName() == b.friendlyClassName()) &&
313  (a.moduleLabel() == b.moduleLabel()) &&
314  (a.branchID() == b.branchID());
315  }
316 
317  bool
319  return combinable(a, b) &&
320  (a.dropped() == b.dropped()) &&
321  (a.moduleNames() == b.moduleNames()) &&
322  (a.parameterSetIDs() == b.parameterSetIDs()) &&
323  (a.branchAliases() == b.branchAliases());
324  }
325 
328  std::string const& fileName,
330  std::ostringstream differences;
331  if(a.branchName() != b.branchName()) {
332  differences << "Branch name '" << b.branchName() << "' does not match '" << a.branchName() << "'.\n";
333  // Need not compare components of branch name individually.
334  // (a.friendlyClassName() != b.friendlyClassName())
335  // (a.moduleLabel() != b.moduleLabel())
336  // (a.productInstanceName() != b.productInstanceName())
337  // (a.processName() != b.processName())
338  }
339  if(a.branchType() != b.branchType()) {
340  differences << "Branch '" << b.branchName() << "' is a(n) '" << b.branchType() << "' branch\n";
341  differences << " in file '" << fileName << "', but a(n) '" << a.branchType() << "' branch in previous files.\n";
342  }
343  if(a.branchID() != b.branchID()) {
344  differences << "Branch '" << b.branchName() << "' has a branch ID of '" << b.branchID() << "'\n";
345  differences << " in file '" << fileName << "', but '" << a.branchID() << "' in previous files.\n";
346  }
347  if(a.fullClassName() != b.fullClassName()) {
348  differences << "Products on branch '" << b.branchName() << "' have type '" << b.fullClassName() << "'\n";
349  differences << " in file '" << fileName << "', but '" << a.fullClassName() << "' in previous files.\n";
350  }
351  if(!b.dropped() && a.dropped()) {
352  differences << "Branch '" << a.branchName() << "' was dropped in the first input file but is present in '" << fileName << "'.\n";
353  }
354  if(m == BranchDescription::Strict) {
355  if(b.parameterSetIDs().size() > 1) {
356  differences << "Branch '" << b.branchName() << "' uses more than one parameter set in file '" << fileName << "'.\n";
357  } else if(a.parameterSetIDs().size() > 1) {
358  differences << "Branch '" << a.branchName() << "' uses more than one parameter set in previous files.\n";
359  } else if(a.parameterSetIDs() != b.parameterSetIDs()) {
360  differences << "Branch '" << b.branchName() << "' uses different parameter sets in file '" << fileName << "'.\n";
361  differences << " than in previous files.\n";
362  }
363  }
364  return differences.str();
365  }
366 
367  WrapperInterfaceBase const*
369  if(wrapperInterfaceBase() == 0) {
370  // This could be done in init(), but we only want to do it on demand, for performance reasons.
372  type.invokeByName(wrapperInterfaceBase(), "getInterface");
373  assert(wrapperInterfaceBase() != 0);
374  }
375  return wrapperInterfaceBase();
376  }
377 }
bool operator<(DetSet< T > const &x, DetSet< T > const &y)
Definition: DetSet.h:91
type
Definition: HCALResponse.h:21
dictionary aliases
Definition: autoCond.py:22
BranchType const & branchType() const
static TypeWithDict byName(std::string const &className)
TypeWithDict & wrappedType() const
static int const invalidSplitLevel
std::string & branchName() const
TypeWithDict & unwrappedType() const
static int const invalidBasketSize
std::map< ProcessConfigurationID, std::string > & moduleNames() const
bool & produced() const
#define nullptr
bool & onDemand() const
std::string const & processName() const
std::string match(BranchDescription const &a, BranchDescription const &b, std::string const &fileName, BranchDescription::MatchMode m)
void invokeByName(T &obj, std::string const &name) const
Definition: TypeWithDict.h:124
bool isValid() const
Definition: BranchID.h:24
ParameterSetID const & psetID() const
void write(std::ostream &os) const
BranchType
Definition: BranchType.h:11
void initFromDictionary() 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)
bool operator==(debugging_allocator< X > const &, debugging_allocator< Y > const &)
WrapperInterfaceBase *& wrapperInterfaceBase() const
std::string const & friendlyClassName() const
BranchID const & branchID() const
WrapperInterfaceBase const * getInterface() const
std::string & wrappedName() const
std::string const & moduleName() const
void throwExceptionWithText(char const *txt)
std::string const & fullClassName() const
ParameterSetID const & parameterSetID() const
eventsetup::produce::Produce produced
Definition: ESProducts.cc:21
std::string wrappedClassName(std::string const &iFullName)
double b
Definition: hdecay.h:120
std::set< std::string > const & branchAliases() const
std::map< ProcessConfigurationID, ParameterSetID > & parameterSetIDs() const
std::set< std::string > branchAliases_
bool isValid() const
Definition: Hash.h:146
double a
Definition: hdecay.h:121
tuple size
Write out results.
std::string className(const T &t)
Definition: ClassName.h:30
void setID(std::string const &branchName)
Definition: BranchID.h:22
void merge(BranchDescription const &other)