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.
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  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  // unwrapped type.
167  if(!bool(unwrappedType())) {
170  setTransient(false);
171  return;
172  }
173  } catch( edm::Exception& caughtException) {
174  caughtException.addContext(std::string{"While initializing meta data for branch: "}+branchName());
175  throw;
176  }
177 
179  try {
180  setWrappedType(wrType);
181  if(!bool(wrappedType())) {
184  return;
185  }
186  } catch( edm::Exception& caughtException) {
187  caughtException.addContext(std::string{"While initializing meta data for branch: "}+branchName());
188  throw;
189  }
190 
191  setTransient(false);
194  TDictAttributeMap* wp = wrappedType().getClass()->GetAttributeMap();
195  if (wp && wp->HasKey("persistent") && !strcmp(wp->GetPropertyAsString("persistent"), "false")) {
196  // Set transient if persistent == "false".
197  setTransient(true);
198  return;
199  }
200  if (wp && wp->HasKey("splitLevel")) {
201  setSplitLevel(strtol(wp->GetPropertyAsString("splitLevel"), 0, 0));
202  if (splitLevel() < 0) {
203  throw cms::Exception("IllegalSplitLevel") << "' An illegal ROOT split level of " <<
204  splitLevel() << " is specified for class " << wrappedName() << ".'\n";
205  }
206  setSplitLevel(splitLevel() + 1); //Compensate for wrapper
207  }
208  if (wp && wp->HasKey("basketSize")) {
209  setBasketSize(strtol(wp->GetPropertyAsString("basketSize"), 0, 0));
210  if (basketSize() <= 0) {
211  throw cms::Exception("IllegalBasketSize") << "' An illegal ROOT basket size of " <<
212  basketSize() << " is specified for class " << wrappedName() << "'.\n";
213  }
214  }
215  }
216 
217  void
219  branchAliases_.insert(other.branchAliases().begin(), other.branchAliases().end());
222  }
223 
224  void
225  BranchDescription::write(std::ostream& os) const {
226  os << "Branch Type = " << branchType() << std::endl;
227  os << "Process Name = " << processName() << std::endl;
228  os << "ModuleLabel = " << moduleLabel() << std::endl;
229  os << "Branch ID = " << branchID() << '\n';
230  os << "Class Name = " << fullClassName() << '\n';
231  os << "Friendly Class Name = " << friendlyClassName() << '\n';
232  os << "Product Instance Name = " << productInstanceName() << std::endl;
233  }
234 
235  void throwExceptionWithText(char const* txt) {
237  e << "Problem using an incomplete BranchDescription\n"
238  << txt
239  << "\nPlease report this error to the FWCore developers";
240  throw e;
241  }
242 
243  void
246  throwExceptionWithText("Illegal BranchType detected");
247 
248  if(moduleLabel_.empty())
249  throwExceptionWithText("Module label is not allowed to be empty");
250 
251  if(processName_.empty())
252  throwExceptionWithText("Process name is not allowed to be empty");
253 
254  if(fullClassName_.empty())
255  throwExceptionWithText("Full class name is not allowed to be empty");
256 
257  if(friendlyClassName_.empty())
258  throwExceptionWithText("Friendly class name is not allowed to be empty");
259 
260  if(produced() && !parameterSetID().isValid())
261  throwExceptionWithText("Invalid ParameterSetID detected");
262  }
263 
264  void
267  clearBranchName();
268  initBranchName();
269  }
270 
271  bool
273  if(a.processName() < b.processName()) return true;
274  if(b.processName() < a.processName()) return false;
275  if(a.fullClassName() < b.fullClassName()) return true;
276  if(b.fullClassName() < a.fullClassName()) return false;
277  if(a.friendlyClassName() < b.friendlyClassName()) return true;
278  if(b.friendlyClassName() < a.friendlyClassName()) return false;
279  if(a.productInstanceName() < b.productInstanceName()) return true;
280  if(b.productInstanceName() < a.productInstanceName()) return false;
281  if(a.moduleLabel() < b.moduleLabel()) return true;
282  if(b.moduleLabel() < a.moduleLabel()) return false;
283  if(a.branchType() < b.branchType()) return true;
284  if(b.branchType() < a.branchType()) return false;
285  if(a.branchID() < b.branchID()) return true;
286  if(b.branchID() < a.branchID()) return false;
287  if(a.branchAliases() < b.branchAliases()) return true;
288  if(b.branchAliases() < a.branchAliases()) return false;
289  if(a.present() < b.present()) return true;
290  if(b.present() < a.present()) return false;
291  return false;
292  }
293 
294  bool
296  return
297  (a.branchType() == b.branchType()) &&
298  (a.processName() == b.processName()) &&
299  (a.fullClassName() == b.fullClassName()) &&
300  (a.friendlyClassName() == b.friendlyClassName()) &&
302  (a.moduleLabel() == b.moduleLabel()) &&
303  (a.branchID() == b.branchID());
304  }
305 
306  bool
308  return combinable(a, b) &&
309  (a.dropped() == b.dropped()) &&
310  (a.branchAliases() == b.branchAliases());
311  }
312 
315  std::string const& fileName) {
316  std::ostringstream differences;
317  if(a.branchName() != b.branchName()) {
318  differences << "Branch name '" << b.branchName() << "' does not match '" << a.branchName() << "'.\n";
319  // Need not compare components of branch name individually.
320  // (a.friendlyClassName() != b.friendlyClassName())
321  // (a.moduleLabel() != b.moduleLabel())
322  // (a.productInstanceName() != b.productInstanceName())
323  // (a.processName() != b.processName())
324  }
325  if(a.branchType() != b.branchType()) {
326  differences << "Branch '" << b.branchName() << "' is a(n) '" << b.branchType() << "' branch\n";
327  differences << " in file '" << fileName << "', but a(n) '" << a.branchType() << "' branch in previous files.\n";
328  }
329  if(a.branchID() != b.branchID()) {
330  differences << "Branch '" << b.branchName() << "' has a branch ID of '" << b.branchID() << "'\n";
331  differences << " in file '" << fileName << "', but '" << a.branchID() << "' in previous files.\n";
332  }
333  if(a.fullClassName() != b.fullClassName()) {
334  differences << "Products on branch '" << b.branchName() << "' have type '" << b.fullClassName() << "'\n";
335  differences << " in file '" << fileName << "', but '" << a.fullClassName() << "' in previous files.\n";
336  }
337  if(!b.dropped() && a.dropped()) {
338  differences << "Branch '" << a.branchName() << "' was dropped in the first input file but is present in '" << fileName << "'.\n";
339  }
340  return differences.str();
341  }
342 } // namespace edm
bool operator<(DetSet< T > const &x, DetSet< T > const &y)
Definition: DetSet.h:90
dictionary aliases
Definition: autoCond.py:48
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:60
void setTransient(bool isTransient)
std::string moduleName(Provenance const &provenance)
Definition: Provenance.cc:27
TClass * getClass() 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 &)
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)