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 <cassert>
9 #include <ostream>
10 #include <sstream>
11 #include <cstdlib>
12 
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  transient_(false),
28  wrappedType_(),
29  unwrappedType_(),
30  splitLevel_(),
31  basketSize_() {
32  }
33 
34  void
37  }
38 
41  moduleLabel_(),
42  processName_(),
43  branchID_(),
49  transient_() {
50  // do not call init here! It will result in an exception throw.
51  }
52 
54  BranchType const& branchType,
55  std::string const& moduleLabel,
56  std::string const& processName,
57  std::string const& className,
58  std::string const& friendlyClassName,
59  std::string const& productInstanceName,
60  std::string const& moduleName,
61  ParameterSetID const& parameterSetID,
62  TypeWithDict const& theTypeWithDict,
63  bool produced,
64  std::set<std::string> const& aliases) :
65  branchType_(branchType),
66  moduleLabel_(moduleLabel),
67  processName_(processName),
68  branchID_(),
69  fullClassName_(className),
70  friendlyClassName_(friendlyClassName),
71  productInstanceName_(productInstanceName),
72  branchAliases_(aliases),
73  transient_() {
74  setDropped(false);
75  setProduced(produced);
76  setOnDemand(false);
79  setUnwrappedType(theTypeWithDict);
80  init();
81  }
82 
84  BranchDescription const& aliasForBranch,
85  std::string const& moduleLabelAlias,
86  std::string const& productInstanceAlias) :
87  branchType_(aliasForBranch.branchType()),
88  moduleLabel_(moduleLabelAlias),
89  processName_(aliasForBranch.processName()),
90  branchID_(),
91  fullClassName_(aliasForBranch.className()),
92  friendlyClassName_(aliasForBranch.friendlyClassName()),
93  productInstanceName_(productInstanceAlias),
94  branchAliases_(aliasForBranch.branchAliases()),
95  aliasForBranchID_(aliasForBranch.branchID()),
96  transient_() {
97  setDropped(false);
98  setProduced(aliasForBranch.produced());
99  setOnDemand(aliasForBranch.onDemand());
100  transient_.moduleName_ = aliasForBranch.moduleName();
101  transient_.parameterSetID_ = aliasForBranch.parameterSetID();
102  setUnwrappedType(aliasForBranch.unwrappedType());
103  init();
104  }
105 
106  void
108  if(!branchName().empty()) {
109  return; // already called
110  }
111  throwIfInvalid_();
112 
113  char const underscore('_');
114  char const period('.');
115 
116  if(friendlyClassName_.find(underscore) != std::string::npos) {
117  throw cms::Exception("IllegalCharacter") << "Class name '" << friendlyClassName()
118  << "' contains an underscore ('_'), which is illegal in the name of a product.\n";
119  }
120 
121  if(moduleLabel_.find(underscore) != std::string::npos) {
122  throw cms::Exception("IllegalCharacter") << "Module label '" << moduleLabel()
123  << "' contains an underscore ('_'), which is illegal in a module label.\n";
124  }
125 
126  if(productInstanceName_.find(underscore) != std::string::npos) {
127  throw cms::Exception("IllegalCharacter") << "Product instance name '" << productInstanceName()
128  << "' contains an underscore ('_'), which is illegal in a product instance name.\n";
129  }
130 
131  if(processName_.find(underscore) != std::string::npos) {
132  throw cms::Exception("IllegalCharacter") << "Process name '" << processName()
133  << "' contains an underscore ('_'), which is illegal in a process name.\n";
134  }
135 
137  brName.reserve(friendlyClassName().size() +
138  moduleLabel().size() +
140  processName().size() + 4);
141  brName += friendlyClassName();
142  brName += underscore;
143  brName += moduleLabel();
144  brName += underscore;
145  brName += productInstanceName();
146  brName += underscore;
147  brName += processName();
148  brName += period;
149 
150  if(!branchID_.isValid()) {
151  branchID_.setID(brName);
152  }
153  }
154 
155  void
157  if(bool(wrappedType())) {
158  return; // already initialized;
159  }
160 
161  throwIfInvalid_();
162 
163  try {
165 
166  // unwrapped type.
168  if(!bool(unwrappedType())) {
171  setTransient(false);
172  return;
173  }
174 
175 
177  if(!bool(wrappedType())) {
180  return;
181  }
182  } catch( edm::Exception& caughtException) {
183  caughtException.addContext(std::string{"While initializing meta data for branch: "}+branchName());
184  throw;
185  }
186  Reflex::PropertyList wp = Reflex::Type::ByTypeInfo(wrappedType().typeInfo()).Properties();
187  setTransient((wp.HasProperty("persistent") ? wp.PropertyAsString("persistent") == std::string("false") : false));
188  if(transient()) {
191  return;
192  }
193  if(wp.HasProperty("splitLevel")) {
194  setSplitLevel(strtol(wp.PropertyAsString("splitLevel").c_str(), 0, 0));
195  if(splitLevel() < 0) {
196  throw cms::Exception("IllegalSplitLevel") << "' An illegal ROOT split level of " <<
197  splitLevel() << " is specified for class " << wrappedName() << ".'\n";
198  }
199  setSplitLevel(splitLevel() + 1); //Compensate for wrapper
200  } else {
202  }
203  if(wp.HasProperty("basketSize")) {
204  setBasketSize(strtol(wp.PropertyAsString("basketSize").c_str(), 0, 0));
205  if(basketSize() <= 0) {
206  throw cms::Exception("IllegalBasketSize") << "' An illegal ROOT basket size of " <<
207  basketSize() << " is specified for class " << wrappedName() << "'.\n";
208  }
209  } else {
211  }
212  }
213 
214  void
216  branchAliases_.insert(other.branchAliases().begin(), other.branchAliases().end());
219  }
220 
221  void
222  BranchDescription::write(std::ostream& os) const {
223  os << "Branch Type = " << branchType() << std::endl;
224  os << "Process Name = " << processName() << std::endl;
225  os << "ModuleLabel = " << moduleLabel() << std::endl;
226  os << "Branch ID = " << branchID() << '\n';
227  os << "Class Name = " << fullClassName() << '\n';
228  os << "Friendly Class Name = " << friendlyClassName() << '\n';
229  os << "Product Instance Name = " << productInstanceName() << std::endl;
230  }
231 
232  void throwExceptionWithText(char const* txt) {
234  e << "Problem using an incomplete BranchDescription\n"
235  << txt
236  << "\nPlease report this error to the FWCore developers";
237  throw e;
238  }
239 
240  void
243  throwExceptionWithText("Illegal BranchType detected");
244 
245  if(moduleLabel_.empty())
246  throwExceptionWithText("Module label is not allowed to be empty");
247 
248  if(processName_.empty())
249  throwExceptionWithText("Process name is not allowed to be empty");
250 
251  if(fullClassName_.empty())
252  throwExceptionWithText("Full class name is not allowed to be empty");
253 
254  if(friendlyClassName_.empty())
255  throwExceptionWithText("Friendly class name is not allowed to be empty");
256 
257  if(produced() && !parameterSetID().isValid())
258  throwExceptionWithText("Invalid ParameterSetID detected");
259  }
260 
261  void
264  clearBranchName();
265  initBranchName();
266  }
267 
268  bool
270  if(a.processName() < b.processName()) return true;
271  if(b.processName() < a.processName()) return false;
272  if(a.fullClassName() < b.fullClassName()) return true;
273  if(b.fullClassName() < a.fullClassName()) return false;
274  if(a.friendlyClassName() < b.friendlyClassName()) return true;
275  if(b.friendlyClassName() < a.friendlyClassName()) return false;
276  if(a.productInstanceName() < b.productInstanceName()) return true;
277  if(b.productInstanceName() < a.productInstanceName()) return false;
278  if(a.moduleLabel() < b.moduleLabel()) return true;
279  if(b.moduleLabel() < a.moduleLabel()) return false;
280  if(a.branchType() < b.branchType()) return true;
281  if(b.branchType() < a.branchType()) return false;
282  if(a.branchID() < b.branchID()) return true;
283  if(b.branchID() < a.branchID()) return false;
284  if(a.branchAliases() < b.branchAliases()) return true;
285  if(b.branchAliases() < a.branchAliases()) return false;
286  if(a.present() < b.present()) return true;
287  if(b.present() < a.present()) return false;
288  return false;
289  }
290 
291  bool
293  return
294  (a.branchType() == b.branchType()) &&
295  (a.processName() == b.processName()) &&
296  (a.fullClassName() == b.fullClassName()) &&
297  (a.friendlyClassName() == b.friendlyClassName()) &&
299  (a.moduleLabel() == b.moduleLabel()) &&
300  (a.branchID() == b.branchID());
301  }
302 
303  bool
305  return combinable(a, b) &&
306  (a.dropped() == b.dropped()) &&
307  (a.branchAliases() == b.branchAliases());
308  }
309 
312  std::string const& fileName) {
313  std::ostringstream differences;
314  if(a.branchName() != b.branchName()) {
315  differences << "Branch name '" << b.branchName() << "' does not match '" << a.branchName() << "'.\n";
316  // Need not compare components of branch name individually.
317  // (a.friendlyClassName() != b.friendlyClassName())
318  // (a.moduleLabel() != b.moduleLabel())
319  // (a.productInstanceName() != b.productInstanceName())
320  // (a.processName() != b.processName())
321  }
322  if(a.branchType() != b.branchType()) {
323  differences << "Branch '" << b.branchName() << "' is a(n) '" << b.branchType() << "' branch\n";
324  differences << " in file '" << fileName << "', but a(n) '" << a.branchType() << "' branch in previous files.\n";
325  }
326  if(a.branchID() != b.branchID()) {
327  differences << "Branch '" << b.branchName() << "' has a branch ID of '" << b.branchID() << "'\n";
328  differences << " in file '" << fileName << "', but '" << a.branchID() << "' in previous files.\n";
329  }
330  if(a.fullClassName() != b.fullClassName()) {
331  differences << "Products on branch '" << b.branchName() << "' have type '" << b.fullClassName() << "'\n";
332  differences << " in file '" << fileName << "', but '" << a.fullClassName() << "' in previous files.\n";
333  }
334  if(!b.dropped() && a.dropped()) {
335  differences << "Branch '" << a.branchName() << "' was dropped in the first input file but is present in '" << fileName << "'.\n";
336  }
337  return differences.str();
338  }
339 }
bool operator<(DetSet< T > const &x, DetSet< T > const &y)
Definition: DetSet.h:90
dictionary aliases
Definition: autoCond.py:34
std::string const & branchName() const
BranchType const & branchType() const
static TypeWithDict byName(std::string const &className)
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)
void setTransient(bool isTransient)
std::string moduleName(Provenance const &provenance)
Definition: Provenance.cc:27
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 &)
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
eventsetup::produce::Produce produced
Definition: ESProducts.cc:20
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_
bool isValid() const
Definition: Hash.h:150
double a
Definition: hdecay.h:121
void setUnwrappedType(TypeWithDict const &type)
volatile std::atomic< bool > shutdown_flag false
void setBasketSize(int size)
moduleLabel_(iConfig.getParameter< string >("@module_label"))
void setProduced(bool isProduced)
std::string const & wrappedName() const
tuple size
Write out results.
std::string className(const T &t)
Definition: ClassName.h:30
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)