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.
6 
7 #include "Reflex/Member.h"
8 
9 #include <ostream>
10 #include <sstream>
11 #include <stdlib.h>
12 
13 class TClass;
14 /*----------------------------------------------------------------------
15 
16 
17 ----------------------------------------------------------------------*/
18 
19 namespace edm {
21  parameterSetID_(),
22  moduleName_(),
23  branchName_(),
24  wrappedName_(),
25  produced_(false),
26  onDemand_(false),
27  dropped_(false),
28  parameterSetIDs_(),
29  moduleNames_(),
30  transient_(false),
31  type_(),
32  typeID_(),
33  wrapperInterfaceBase_(0),
34  splitLevel_(),
35  basketSize_() {
36  }
37 
38  void
41  }
42 
45  moduleLabel_(),
46  processName_(),
47  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  TypeID const& theTypeID,
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  typeID() = theTypeID;
83  init();
84  }
85 
86  void
88  if(!branchName().empty()) {
89  return; // already called
90  }
92 
93  char const underscore('_');
94  char const period('.');
95 
96  if(friendlyClassName_.find(underscore) != std::string::npos) {
97  throw cms::Exception("IllegalCharacter") << "Class name '" << friendlyClassName()
98  << "' contains an underscore ('_'), which is illegal in the name of a product.\n";
99  }
100 
101  if(moduleLabel_.find(underscore) != std::string::npos) {
102  throw cms::Exception("IllegalCharacter") << "Module label '" << moduleLabel()
103  << "' contains an underscore ('_'), which is illegal in a module label.\n";
104  }
105 
106  if(productInstanceName_.find(underscore) != std::string::npos) {
107  throw cms::Exception("IllegalCharacter") << "Product instance name '" << productInstanceName()
108  << "' contains an underscore ('_'), which is illegal in a product instance name.\n";
109  }
110 
111  if(processName_.find(underscore) != std::string::npos) {
112  throw cms::Exception("IllegalCharacter") << "Process name '" << processName()
113  << "' contains an underscore ('_'), which is illegal in a process name.\n";
114  }
115 
116  branchName().reserve(friendlyClassName().size() +
117  moduleLabel().size() +
119  processName().size() + 4);
121  branchName() += underscore;
122  branchName() += moduleLabel();
123  branchName() += underscore;
125  branchName() += underscore;
126  branchName() += processName();
127  branchName() += period;
128 
129  if(!branchID_.isValid()) {
131  }
132  }
133 
134  void
136  Reflex::Type null;
137 
138  if(type() != null) {
139  return; // already initialized;
140  }
141 
142  throwIfInvalid_();
143 
145 
146  Reflex::Type t = Reflex::Type::ByName(fullClassName());
147  if(t == null) {
150  transient() = false;
151  return;
152  }
153  typeID() = TypeID(t.TypeInfo()); // unwrapped type.
154  type() = Reflex::Type::ByName(wrappedName());
155  if(type() == null) {
158  return;
159  }
160  Reflex::PropertyList wp = type().Properties();
161  transient() = (wp.HasProperty("persistent") ? wp.PropertyAsString("persistent") == std::string("false") : false);
162  if(transient()) {
165  return;
166  }
167  if(wp.HasProperty("splitLevel")) {
168  splitLevel() = strtol(wp.PropertyAsString("splitLevel").c_str(), 0, 0);
169  if(splitLevel() < 0) {
170  throw cms::Exception("IllegalSplitLevel") << "' An illegal ROOT split level of " <<
171  splitLevel() << " is specified for class " << wrappedName() << ".'\n";
172  }
173  ++splitLevel(); //Compensate for wrapper
174  } else {
176  }
177  if(wp.HasProperty("basketSize")) {
178  basketSize() = strtol(wp.PropertyAsString("basketSize").c_str(), 0, 0);
179  if(basketSize() <= 0) {
180  throw cms::Exception("IllegalBasketSize") << "' An illegal ROOT basket size of " <<
181  basketSize() << " is specified for class " << wrappedName() << "'.\n";
182  }
183  } else {
185  }
186  }
187 
188  ParameterSetID const&
190  assert(!parameterSetIDs().empty());
191  if(parameterSetIDs().size() != 1) {
192  throw cms::Exception("Ambiguous")
193  << "Your application requires all events on Branch '" << branchName()
194  << "'\n to have the same provenance. This file has events with mixed provenance\n"
195  << "on this branch. Use a different input file.\n";
196  }
197  return parameterSetIDs().begin()->second;
198  }
199 
200  void
202  parameterSetIDs().insert(other.parameterSetIDs().begin(), other.parameterSetIDs().end());
203  moduleNames().insert(other.moduleNames().begin(), other.moduleNames().end());
204  branchAliases_.insert(other.branchAliases().begin(), other.branchAliases().end());
205  if(splitLevel() == invalidSplitLevel) splitLevel() = other.splitLevel();
206  if(basketSize() == invalidBasketSize) basketSize() = other.basketSize();
207  }
208 
209  void
210  BranchDescription::write(std::ostream& os) const {
211  os << "Branch Type = " << branchType() << std::endl;
212  os << "Process Name = " << processName() << std::endl;
213  os << "ModuleLabel = " << moduleLabel() << std::endl;
214  os << "Branch ID = " << branchID() << '\n';
215  os << "Class Name = " << fullClassName() << '\n';
216  os << "Friendly Class Name = " << friendlyClassName() << '\n';
217  os << "Product Instance Name = " << productInstanceName() << std::endl;
218  }
219 
220  void throwExceptionWithText(char const* txt) {
222  e << "Problem using an incomplete BranchDescription\n"
223  << txt
224  << "\nPlease report this error to the FWCore developers";
225  throw e;
226  }
227 
228  void
231  throwExceptionWithText("Illegal BranchType detected");
232 
233  if(moduleLabel_.empty())
234  throwExceptionWithText("Module label is not allowed to be empty");
235 
236  if(processName_.empty())
237  throwExceptionWithText("Process name is not allowed to be empty");
238 
239  if(fullClassName_.empty())
240  throwExceptionWithText("Full class name is not allowed to be empty");
241 
242  if(friendlyClassName_.empty())
243  throwExceptionWithText("Friendly class name is not allowed to be empty");
244 
245  if(produced() && !parameterSetID().isValid())
246  throwExceptionWithText("Invalid ParameterSetID detected");
247  }
248 
249  void
252  branchName().clear();
253  initBranchName();
254  }
255 
256  bool
258  if(a.processName() < b.processName()) return true;
259  if(b.processName() < a.processName()) return false;
260  if(a.fullClassName() < b.fullClassName()) return true;
261  if(b.fullClassName() < a.fullClassName()) return false;
262  if(a.friendlyClassName() < b.friendlyClassName()) return true;
263  if(b.friendlyClassName() < a.friendlyClassName()) return false;
264  if(a.productInstanceName() < b.productInstanceName()) return true;
265  if(b.productInstanceName() < a.productInstanceName()) return false;
266  if(a.moduleLabel() < b.moduleLabel()) return true;
267  if(b.moduleLabel() < a.moduleLabel()) return false;
268  if(a.branchType() < b.branchType()) return true;
269  if(b.branchType() < a.branchType()) return false;
270  if(a.branchID() < b.branchID()) return true;
271  if(b.branchID() < a.branchID()) return false;
272  if(a.parameterSetIDs() < b.parameterSetIDs()) return true;
273  if(b.parameterSetIDs() < a.parameterSetIDs()) return false;
274  if(a.moduleNames() < b.moduleNames()) return true;
275  if(b.moduleNames() < a.moduleNames()) return false;
276  if(a.branchAliases() < b.branchAliases()) return true;
277  if(b.branchAliases() < a.branchAliases()) return false;
278  if(a.present() < b.present()) return true;
279  if(b.present() < a.present()) return false;
280  return false;
281  }
282 
283  bool
285  return
286  (a.branchType() == b.branchType()) &&
287  (a.processName() == b.processName()) &&
288  (a.fullClassName() == b.fullClassName()) &&
289  (a.friendlyClassName() == b.friendlyClassName()) &&
291  (a.moduleLabel() == b.moduleLabel()) &&
292  (a.branchID() == b.branchID());
293  }
294 
295  bool
297  return combinable(a, b) &&
298  (a.dropped() == b.dropped()) &&
299  (a.moduleNames() == b.moduleNames()) &&
300  (a.parameterSetIDs() == b.parameterSetIDs()) &&
301  (a.branchAliases() == b.branchAliases());
302  }
303 
304  std::string
306  std::string const& fileName,
308  std::ostringstream differences;
309  if(a.branchName() != b.branchName()) {
310  differences << "Branch name '" << b.branchName() << "' does not match '" << a.branchName() << "'.\n";
311  // Need not compare components of branch name individually.
312  // (a.friendlyClassName() != b.friendlyClassName())
313  // (a.moduleLabel() != b.moduleLabel())
314  // (a.productInstanceName() != b.productInstanceName())
315  // (a.processName() != b.processName())
316  }
317  if(a.branchType() != b.branchType()) {
318  differences << "Branch '" << b.branchName() << "' is a(n) '" << b.branchType() << "' branch\n";
319  differences << " in file '" << fileName << "', but a(n) '" << a.branchType() << "' branch in previous files.\n";
320  }
321  if(a.branchID() != b.branchID()) {
322  differences << "Branch '" << b.branchName() << "' has a branch ID of '" << b.branchID() << "'\n";
323  differences << " in file '" << fileName << "', but '" << a.branchID() << "' in previous files.\n";
324  }
325  if(a.fullClassName() != b.fullClassName()) {
326  differences << "Products on branch '" << b.branchName() << "' have type '" << b.fullClassName() << "'\n";
327  differences << " in file '" << fileName << "', but '" << a.fullClassName() << "' in previous files.\n";
328  }
329  if(!b.dropped() && a.dropped()) {
330  differences << "Branch '" << a.branchName() << "' was dropped in the first input file but is present in '" << fileName << "'.\n";
331  }
332  if(m == BranchDescription::Strict) {
333  if(b.parameterSetIDs().size() > 1) {
334  differences << "Branch '" << b.branchName() << "' uses more than one parameter set in file '" << fileName << "'.\n";
335  } else if(a.parameterSetIDs().size() > 1) {
336  differences << "Branch '" << a.branchName() << "' uses more than one parameter set in previous files.\n";
337  } else if(a.parameterSetIDs() != b.parameterSetIDs()) {
338  differences << "Branch '" << b.branchName() << "' uses different parameter sets in file '" << fileName << "'.\n";
339  differences << " than in previous files.\n";
340  }
341  }
342  return differences.str();
343  }
344 
345  WrapperInterfaceBase const*
347  if(wrapperInterfaceBase() == 0) {
348  // This could be done in init(), but we only want to do it on demand, for performance reasons.
349  Reflex::Type type = Reflex::Type::ByName(wrappedName());
350  Reflex::Member getTheInterface = type.FunctionMemberByName(std::string("getInterface"));
351  getTheInterface.Invoke(wrapperInterfaceBase());
352  assert(wrapperInterfaceBase() != 0);
353  }
354  return wrapperInterfaceBase();
355  }
356 }
bool operator<(DetSet< T > const &x, DetSet< T > const &y)
Definition: DetSet.h:91
type
Definition: HCALResponse.h:22
BranchType const & branchType() const
TypeID & typeID() const
Reflex::Type & type() const
static int const invalidSplitLevel
std::string & branchName() const
static int const invalidBasketSize
std::map< ProcessConfigurationID, std::string > & moduleNames() const
bool & produced() const
bool & onDemand() const
std::string const & processName() const
std::string match(BranchDescription const &a, BranchDescription const &b, std::string const &fileName, BranchDescription::MatchMode m)
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)