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 #include <ostream>
8 #include <sstream>
9 #include <stdlib.h>
10 
11 /*----------------------------------------------------------------------
12 
13 
14 ----------------------------------------------------------------------*/
15 
16 namespace edm {
18  parameterSetID_(),
19  branchName_(),
20  wrappedName_(),
21  produced_(false),
22  onDemand_(false),
23  dropped_(false),
24  parameterSetIDs_(),
25  moduleNames_(),
26  transient_(false),
27  type_(),
28  typeID_(),
29  splitLevel_(),
30  basketSize_() {
31  }
32 
35  moduleLabel_(),
36  processName_(),
37  branchID_(),
38  productID_(),
43  transients_() {
44  // do not call init here! It will result in an exception throw.
45  }
46 
48  BranchType const& branchType,
49  std::string const& mdLabel,
50  std::string const& procName,
51  std::string const& name,
52  std::string const& fName,
53  std::string const& pin,
54  ModuleDescription const& modDesc,
55  TypeID const& theTypeID,
56  std::set<std::string> const& aliases) :
57  branchType_(branchType),
58  moduleLabel_(mdLabel),
59  processName_(procName),
60  branchID_(),
61  productID_(),
62  fullClassName_(name),
63  friendlyClassName_(fName),
64  productInstanceName_(pin),
65  branchAliases_(aliases),
66  transients_() {
67  dropped() = false;
68  produced() = true;
69  onDemand() = false;
70  typeID() = theTypeID;
71  transients_.get().parameterSetID_ = modDesc.parameterSetID();
72  transients_.get().moduleName_ = modDesc.moduleName();
73  init();
74  }
75 
76  void
78  if (!branchName().empty()) {
79  return; // already called
80  }
82 
83  char const underscore('_');
84  char const period('.');
85 
86  if (friendlyClassName_.find(underscore) != std::string::npos) {
87  throw cms::Exception("IllegalCharacter") << "Class name '" << friendlyClassName()
88  << "' contains an underscore ('_'), which is illegal in the name of a product.\n";
89  }
90 
91  if (moduleLabel_.find(underscore) != std::string::npos) {
92  throw cms::Exception("IllegalCharacter") << "Module label '" << moduleLabel()
93  << "' contains an underscore ('_'), which is illegal in a module label.\n";
94  }
95 
96  if (productInstanceName_.find(underscore) != std::string::npos) {
97  throw cms::Exception("IllegalCharacter") << "Product instance name '" << productInstanceName()
98  << "' contains an underscore ('_'), which is illegal in a product instance name.\n";
99  }
100 
101  if (processName_.find(underscore) != std::string::npos) {
102  throw cms::Exception("IllegalCharacter") << "Process name '" << processName()
103  << "' contains an underscore ('_'), which is illegal in a process name.\n";
104  }
105 
106  branchName().reserve(friendlyClassName().size() +
107  moduleLabel().size() +
109  processName().size() + 4);
111  branchName() += underscore;
112  branchName() += moduleLabel();
113  branchName() += underscore;
115  branchName() += underscore;
116  branchName() += processName();
117  branchName() += period;
118 
119  if (!branchID_.isValid()) {
121  }
122  }
123 
124  void
126  Reflex::Type null;
127 
128  if (type() != null) {
129  return; // already initialized;
130  }
131 
132  throwIfInvalid_();
133 
135 
136  Reflex::Type t = Reflex::Type::ByName(fullClassName());
137  if (t == null) {
140  transient() = false;
141  return;
142  }
143  Reflex::PropertyList p = t.Properties();
144  transient() = (p.HasProperty("persistent") ? p.PropertyAsString("persistent") == std::string("false") : false);
145  if (transient()) {
148  type() = t;
149  return;
150  }
151  type() = Reflex::Type::ByName(wrappedName());
152  if (type() == null) {
155  return;
156  }
157  Reflex::PropertyList wp = type().Properties();
158  if (wp.HasProperty("splitLevel")) {
159  splitLevel() = strtol(wp.PropertyAsString("splitLevel").c_str(), 0, 0);
160  if (splitLevel() < 0) {
161  throw cms::Exception("IllegalSplitLevel") << "' An illegal ROOT split level of " <<
162  splitLevel() << " is specified for class " << wrappedName() << ".'\n";
163  }
164  ++splitLevel(); //Compensate for wrapper
165  } else {
167  }
168  if (wp.HasProperty("basketSize")) {
169  basketSize() = strtol(wp.PropertyAsString("basketSize").c_str(), 0, 0);
170  if (basketSize() <= 0) {
171  throw cms::Exception("IllegalBasketSize") << "' An illegal ROOT basket size of " <<
172  basketSize() << " is specified for class " << wrappedName() << "'.\n";
173  }
174  } else {
176  }
177  }
178 
179  ParameterSetID const&
181  assert(!parameterSetIDs().empty());
182  if (parameterSetIDs().size() != 1) {
183  throw cms::Exception("Ambiguous")
184  << "Your application requires all events on Branch '" << branchName()
185  << "'\n to have the same provenance. This file has events with mixed provenance\n"
186  << "on this branch. Use a different input file.\n";
187  }
188  return parameterSetIDs().begin()->second;
189  }
190 
191  void
193  parameterSetIDs().insert(other.parameterSetIDs().begin(), other.parameterSetIDs().end());
194  moduleNames().insert(other.moduleNames().begin(), other.moduleNames().end());
195  branchAliases_.insert(other.branchAliases().begin(), other.branchAliases().end());
196  if (splitLevel() == invalidSplitLevel) splitLevel() = other.splitLevel();
197  if (basketSize() == invalidBasketSize) basketSize() = other.basketSize();
198  }
199 
200  void
201  BranchDescription::write(std::ostream& os) const {
202  os << "Branch Type = " << branchType() << std::endl;
203  os << "Process Name = " << processName() << std::endl;
204  os << "ModuleLabel = " << moduleLabel() << std::endl;
205  os << "Branch ID = " << branchID() << '\n';
206  os << "Class Name = " << fullClassName() << '\n';
207  os << "Friendly Class Name = " << friendlyClassName() << '\n';
208  os << "Product Instance Name = " << productInstanceName() << std::endl;
209  }
210 
211  void throwExceptionWithText(char const* txt) {
213  e << "Problem using an incomplete BranchDescription\n"
214  << txt
215  << "\nPlease report this error to the FWCore developers";
216  throw e;
217  }
218 
219  void
222  throwExceptionWithText("Illegal BranchType detected");
223 
224  if (moduleLabel_.empty())
225  throwExceptionWithText("Module label is not allowed to be empty");
226 
227  if (processName_.empty())
228  throwExceptionWithText("Process name is not allowed to be empty");
229 
230  if (fullClassName_.empty())
231  throwExceptionWithText("Full class name is not allowed to be empty");
232 
233  if (friendlyClassName_.empty())
234  throwExceptionWithText("Friendly class name is not allowed to be empty");
235 
236  if (produced() && !parameterSetID().isValid())
237  throwExceptionWithText("Invalid ParameterSetID detected");
238  }
239 
240  void
243  branchName().clear();
244  initBranchName();
245  }
246 
247  bool
249  if (a.processName() < b.processName()) return true;
250  if (b.processName() < a.processName()) return false;
251  if (a.fullClassName() < b.fullClassName()) return true;
252  if (b.fullClassName() < a.fullClassName()) return false;
253  if (a.friendlyClassName() < b.friendlyClassName()) return true;
254  if (b.friendlyClassName() < a.friendlyClassName()) return false;
255  if (a.productInstanceName() < b.productInstanceName()) return true;
256  if (b.productInstanceName() < a.productInstanceName()) return false;
257  if (a.moduleLabel() < b.moduleLabel()) return true;
258  if (b.moduleLabel() < a.moduleLabel()) return false;
259  if (a.branchType() < b.branchType()) return true;
260  if (b.branchType() < a.branchType()) return false;
261  if (a.branchID() < b.branchID()) return true;
262  if (b.branchID() < a.branchID()) return false;
263  if (a.parameterSetIDs() < b.parameterSetIDs()) return true;
264  if (b.parameterSetIDs() < a.parameterSetIDs()) return false;
265  if (a.moduleNames() < b.moduleNames()) return true;
266  if (b.moduleNames() < a.moduleNames()) return false;
267  if (a.branchAliases() < b.branchAliases()) return true;
268  if (b.branchAliases() < a.branchAliases()) return false;
269  if (a.present() < b.present()) return true;
270  if (b.present() < a.present()) return false;
271  return false;
272  }
273 
274  bool
276  return
277  (a.branchType() == b.branchType()) &&
278  (a.processName() == b.processName()) &&
279  (a.fullClassName() == b.fullClassName()) &&
280  (a.friendlyClassName() == b.friendlyClassName()) &&
282  (a.moduleLabel() == b.moduleLabel()) &&
283  (a.branchID() == b.branchID());
284  }
285 
286  bool
288  return combinable(a, b) &&
289  (a.dropped() == b.dropped()) &&
290  (a.moduleNames() == b.moduleNames()) &&
291  (a.parameterSetIDs() == b.parameterSetIDs()) &&
292  (a.branchAliases() == b.branchAliases());
293  }
294 
295  std::string
297  std::string const& fileName,
299  std::ostringstream differences;
300  if (a.branchName() != b.branchName()) {
301  differences << "Branch name '" << b.branchName() << "' does not match '" << a.branchName() << "'.\n";
302  // Need not compare components of branch name individually.
303  // (a.friendlyClassName() != b.friendlyClassName())
304  // (a.moduleLabel() != b.moduleLabel())
305  // (a.productInstanceName() != b.productInstanceName())
306  // (a.processName() != b.processName())
307  }
308  if (a.branchType() != b.branchType()) {
309  differences << "Branch '" << b.branchName() << "' is a(n) '" << b.branchType() << "' branch\n";
310  differences << " in file '" << fileName << "', but a(n) '" << a.branchType() << "' branch in previous files.\n";
311  }
312  if (a.branchID() != b.branchID()) {
313  differences << "Branch '" << b.branchName() << "' has a branch ID of '" << b.branchID() << "'\n";
314  differences << " in file '" << fileName << "', but '" << a.branchID() << "' in previous files.\n";
315  }
316  if (a.fullClassName() != b.fullClassName()) {
317  differences << "Products on branch '" << b.branchName() << "' have type '" << b.fullClassName() << "'\n";
318  differences << " in file '" << fileName << "', but '" << a.fullClassName() << "' in previous files.\n";
319  }
320  if (!b.dropped() && a.dropped()) {
321  differences << "Branch '" << a.branchName() << "' was dropped in the first input file but is present in '" << fileName << "'.\n";
322  }
323  if (m == BranchDescription::Strict) {
324  if (b.parameterSetIDs().size() > 1) {
325  differences << "Branch '" << b.branchName() << "' uses more than one parameter set in file '" << fileName << "'.\n";
326  } else if (a.parameterSetIDs().size() > 1) {
327  differences << "Branch '" << a.branchName() << "' uses more than one parameter set in previous files.\n";
328  } else if (a.parameterSetIDs() != b.parameterSetIDs()) {
329  differences << "Branch '" << b.branchName() << "' uses different parameter sets in file '" << fileName << "'.\n";
330  differences << " than in previous files.\n";
331  }
332  }
333  return differences.str();
334  }
335 }
bool operator<(DetSet< T > const &x, DetSet< T > const &y)
Definition: DetSet.h:77
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 & moduleName() 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 &)
std::string const & friendlyClassName() const
BranchID const & branchID() const
std::string & wrappedName() 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
std::set< std::string > const & branchAliases() const
std::map< ProcessConfigurationID, ParameterSetID > & parameterSetIDs() const
std::set< std::string > branchAliases_
bool isValid() const
Definition: Hash.h:136
double a
Definition: hdecay.h:121
ParameterSetID const & parameterSetID() const
tuple size
Write out results.
void setID(std::string const &branchName)
Definition: BranchID.h:22
void merge(BranchDescription const &other)
Transient< Transients > transients_