CMS 3D CMS Logo

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  wrappedType_(),
25  unwrappedType_(),
26  splitLevel_(),
27  basketSize_(),
28  produced_(false),
29  onDemand_(false),
30  dropped_(false),
31  transient_(false),
32  availableOnlyAtEndTransition_(false){
33  }
34 
35  void
38  }
39 
42  moduleLabel_(),
43  processName_(),
44  branchID_(),
50  transient_(){
51  // do not call init here! It will result in an exception throw.
52  }
53 
55  BranchType const& branchType,
56  std::string const& moduleLabel,
57  std::string const& processName,
58  std::string const& className,
61  std::string const& moduleName,
63  TypeWithDict const& theTypeWithDict,
64  bool produced,
66  std::set<std::string> const& aliases) :
67  branchType_(branchType),
68  moduleLabel_(moduleLabel),
69  processName_(processName),
70  branchID_(),
71  fullClassName_(className),
72  friendlyClassName_(friendlyClassName),
73  productInstanceName_(productInstanceName),
74  branchAliases_(aliases),
75  transient_() {
76  setDropped(false);
77  setProduced(produced);
78  setOnDemand(false);
82  setUnwrappedType(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  setDropped(false);
101  setProduced(aliasForBranch.produced());
102  setOnDemand(aliasForBranch.onDemand());
104  transient_.moduleName_ = aliasForBranch.moduleName();
105  transient_.parameterSetID_ = aliasForBranch.parameterSetID();
106  setUnwrappedType(aliasForBranch.unwrappedType());
107  init();
108  }
109 
110  void
112  if(!branchName().empty()) {
113  return; // already called
114  }
115  throwIfInvalid_();
116 
117  char const underscore('_');
118  char const period('.');
119 
120  if(friendlyClassName_.find(underscore) != std::string::npos) {
121  throw cms::Exception("IllegalCharacter") << "Class name '" << friendlyClassName()
122  << "' contains an underscore ('_'), which is illegal in the name of a product.\n";
123  }
124 
125  if(moduleLabel_.find(underscore) != std::string::npos) {
126  throw cms::Exception("IllegalCharacter") << "Module label '" << moduleLabel()
127  << "' contains an underscore ('_'), which is illegal in a module label.\n";
128  }
129 
130  if(productInstanceName_.find(underscore) != std::string::npos) {
131  throw cms::Exception("IllegalCharacter") << "Product instance name '" << productInstanceName()
132  << "' contains an underscore ('_'), which is illegal in a product instance name.\n";
133  }
134 
135  if(processName_.find(underscore) != std::string::npos) {
136  throw cms::Exception("IllegalCharacter") << "Process name '" << processName()
137  << "' contains an underscore ('_'), which is illegal in a process name.\n";
138  }
139 
141  brName.reserve(friendlyClassName().size() +
142  moduleLabel().size() +
144  processName().size() + 4);
145  brName += friendlyClassName();
146  brName += underscore;
147  brName += moduleLabel();
148  brName += underscore;
149  brName += productInstanceName();
150  brName += underscore;
151  brName += processName();
152  brName += period;
153 
154  if(!branchID_.isValid()) {
155  branchID_.setID(brName);
156  }
157  }
158 
159  void
161  if(bool(wrappedType())) {
162  return; // already initialized;
163  }
164 
165  throwIfInvalid_();
166 
167  try {
169  // unwrapped type.
171  if(!bool(unwrappedType())) {
174  setTransient(false);
175  return;
176  }
177  } catch( edm::Exception& caughtException) {
178  caughtException.addContext(std::string{"While initializing meta data for branch: "}+branchName());
179  throw;
180  }
181 
183  try {
184  setWrappedType(wrType);
185  if(!bool(wrappedType())) {
188  return;
189  }
190  } catch( edm::Exception& caughtException) {
191  caughtException.addContext(std::string{"While initializing meta data for branch: "}+branchName());
192  throw;
193  }
194 
195  setTransient(false);
198  TDictAttributeMap* wp = wrappedType().getClass()->GetAttributeMap();
199  if (wp && wp->HasKey("persistent") && !strcmp(wp->GetPropertyAsString("persistent"), "false")) {
200  // Set transient if persistent == "false".
201  setTransient(true);
202  return;
203  }
204  if (wp && wp->HasKey("splitLevel")) {
205  setSplitLevel(strtol(wp->GetPropertyAsString("splitLevel"), 0, 0));
206  if (splitLevel() < 0) {
207  throw cms::Exception("IllegalSplitLevel") << "' An illegal ROOT split level of " <<
208  splitLevel() << " is specified for class " << wrappedName() << ".'\n";
209  }
210  setSplitLevel(splitLevel() + 1); //Compensate for wrapper
211  }
212  if (wp && wp->HasKey("basketSize")) {
213  setBasketSize(strtol(wp->GetPropertyAsString("basketSize"), 0, 0));
214  if (basketSize() <= 0) {
215  throw cms::Exception("IllegalBasketSize") << "' An illegal ROOT basket size of " <<
216  basketSize() << " is specified for class " << wrappedName() << "'.\n";
217  }
218  }
219  }
220 
221  void
223  branchAliases_.insert(other.branchAliases().begin(), other.branchAliases().end());
226  }
227 
228  void
229  BranchDescription::write(std::ostream& os) const {
230  os << "Branch Type = " << branchType() << std::endl;
231  os << "Process Name = " << processName() << std::endl;
232  os << "ModuleLabel = " << moduleLabel() << std::endl;
233  os << "Branch ID = " << branchID() << '\n';
234  os << "Class Name = " << fullClassName() << '\n';
235  os << "Friendly Class Name = " << friendlyClassName() << '\n';
236  os << "Product Instance Name = " << productInstanceName() << std::endl;
237  }
238 
239  void throwExceptionWithText(char const* txt) {
241  e << "Problem using an incomplete BranchDescription\n"
242  << txt
243  << "\nPlease report this error to the FWCore developers";
244  throw e;
245  }
246 
247  void
250  throwExceptionWithText("Illegal BranchType detected");
251 
252  if(moduleLabel_.empty())
253  throwExceptionWithText("Module label is not allowed to be empty");
254 
255  if(processName_.empty())
256  throwExceptionWithText("Process name is not allowed to be empty");
257 
258  if(fullClassName_.empty())
259  throwExceptionWithText("Full class name is not allowed to be empty");
260 
261  if(friendlyClassName_.empty())
262  throwExceptionWithText("Friendly class name is not allowed to be empty");
263 
264  if(produced() && !parameterSetID().isValid())
265  throwExceptionWithText("Invalid ParameterSetID detected");
266  }
267 
268  void
271  clearBranchName();
272  initBranchName();
273  }
274 
275  bool
277  if(a.processName() < b.processName()) return true;
278  if(b.processName() < a.processName()) return false;
279  if(a.fullClassName() < b.fullClassName()) return true;
280  if(b.fullClassName() < a.fullClassName()) return false;
281  if(a.friendlyClassName() < b.friendlyClassName()) return true;
282  if(b.friendlyClassName() < a.friendlyClassName()) return false;
283  if(a.productInstanceName() < b.productInstanceName()) return true;
284  if(b.productInstanceName() < a.productInstanceName()) return false;
285  if(a.moduleLabel() < b.moduleLabel()) return true;
286  if(b.moduleLabel() < a.moduleLabel()) return false;
287  if(a.branchType() < b.branchType()) return true;
288  if(b.branchType() < a.branchType()) return false;
289  if(a.branchID() < b.branchID()) return true;
290  if(b.branchID() < a.branchID()) return false;
291  if(a.branchAliases() < b.branchAliases()) return true;
292  if(b.branchAliases() < a.branchAliases()) return false;
293  if(a.present() < b.present()) return true;
294  if(b.present() < a.present()) return false;
295  return false;
296  }
297 
298  bool
300  return
301  (a.branchType() == b.branchType()) &&
302  (a.processName() == b.processName()) &&
303  (a.fullClassName() == b.fullClassName()) &&
304  (a.friendlyClassName() == b.friendlyClassName()) &&
306  (a.moduleLabel() == b.moduleLabel()) &&
307  (a.branchID() == b.branchID());
308  }
309 
310  bool
312  return combinable(a, b) &&
313  (a.dropped() == b.dropped()) &&
314  (a.branchAliases() == b.branchAliases());
315  }
316 
319  std::string const& fileName) {
320  std::ostringstream differences;
321  if(a.branchName() != b.branchName()) {
322  differences << "Branch name '" << b.branchName() << "' does not match '" << a.branchName() << "'.\n";
323  // Need not compare components of branch name individually.
324  // (a.friendlyClassName() != b.friendlyClassName())
325  // (a.moduleLabel() != b.moduleLabel())
326  // (a.productInstanceName() != b.productInstanceName())
327  // (a.processName() != b.processName())
328  }
329  if(a.branchType() != b.branchType()) {
330  differences << "Branch '" << b.branchName() << "' is a(n) '" << b.branchType() << "' branch\n";
331  differences << " in file '" << fileName << "', but a(n) '" << a.branchType() << "' branch in previous files.\n";
332  }
333  if(a.branchID() != b.branchID()) {
334  differences << "Branch '" << b.branchName() << "' has a branch ID of '" << b.branchID() << "'\n";
335  differences << " in file '" << fileName << "', but '" << a.branchID() << "' in previous files.\n";
336  }
337  if(a.fullClassName() != b.fullClassName()) {
338  differences << "Products on branch '" << b.branchName() << "' have type '" << b.fullClassName() << "'\n";
339  differences << " in file '" << fileName << "', but '" << a.fullClassName() << "' in previous files.\n";
340  }
341  if(!b.dropped() && a.dropped()) {
342  differences << "Branch '" << a.branchName() << "' was dropped in the first input file but is present in '" << fileName << "'.\n";
343  }
344  return differences.str();
345  }
346 } // namespace edm
size
Write out results.
bool operator<(DetSet< T > const &x, DetSet< T > const &y)
Definition: DetSet.h:90
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)
TClass * getClass() const
std::string const & className() 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
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_
HLT enums.
bool isValid() const
Definition: Hash.h:151
double a
Definition: hdecay.h:121
bool availableOnlyAtEndTransition() const
void setUnwrappedType(TypeWithDict const &type)
void setBasketSize(int size)
void setProduced(bool isProduced)
std::string const & wrappedName() const
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)