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 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  transient_(false),
29  wrappedType_(),
30  unwrappedType_(),
31  wrapperInterfaceBase_(nullptr),
32  splitLevel_(),
33  basketSize_() {
34  }
35 
36  void
39  }
40 
43  moduleLabel_(),
44  processName_(),
45  branchID_(),
51  transient_() {
52  // do not call init here! It will result in an exception throw.
53  }
54 
56  BranchType const& branchType,
57  std::string const& moduleLabel,
58  std::string const& processName,
59  std::string const& className,
60  std::string const& friendlyClassName,
61  std::string const& productInstanceName,
62  std::string const& moduleName,
63  ParameterSetID const& parameterSetID,
64  TypeWithDict const& theTypeWithDict,
65  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);
81  setUnwrappedType(theTypeWithDict);
82  init();
83  }
84 
86  BranchDescription const& aliasForBranch,
87  std::string const& moduleLabelAlias,
88  std::string const& productInstanceAlias) :
89  branchType_(aliasForBranch.branchType()),
90  moduleLabel_(moduleLabelAlias),
91  processName_(aliasForBranch.processName()),
92  branchID_(),
93  fullClassName_(aliasForBranch.className()),
94  friendlyClassName_(aliasForBranch.friendlyClassName()),
95  productInstanceName_(productInstanceAlias),
96  branchAliases_(aliasForBranch.branchAliases()),
97  aliasForBranchID_(aliasForBranch.branchID()),
98  transient_() {
99  setDropped(false);
100  setProduced(aliasForBranch.produced());
101  setOnDemand(aliasForBranch.onDemand());
102  transient_.moduleName_ = aliasForBranch.moduleName();
103  transient_.parameterSetID_ = aliasForBranch.parameterSetID();
104  setUnwrappedType(aliasForBranch.unwrappedType());
105  init();
106  }
107 
108  void
110  if(!branchName().empty()) {
111  return; // already called
112  }
113  throwIfInvalid_();
114 
115  char const underscore('_');
116  char const period('.');
117 
118  if(friendlyClassName_.find(underscore) != std::string::npos) {
119  throw cms::Exception("IllegalCharacter") << "Class name '" << friendlyClassName()
120  << "' contains an underscore ('_'), which is illegal in the name of a product.\n";
121  }
122 
123  if(moduleLabel_.find(underscore) != std::string::npos) {
124  throw cms::Exception("IllegalCharacter") << "Module label '" << moduleLabel()
125  << "' contains an underscore ('_'), which is illegal in a module label.\n";
126  }
127 
128  if(productInstanceName_.find(underscore) != std::string::npos) {
129  throw cms::Exception("IllegalCharacter") << "Product instance name '" << productInstanceName()
130  << "' contains an underscore ('_'), which is illegal in a product instance name.\n";
131  }
132 
133  if(processName_.find(underscore) != std::string::npos) {
134  throw cms::Exception("IllegalCharacter") << "Process name '" << processName()
135  << "' contains an underscore ('_'), which is illegal in a process name.\n";
136  }
137 
139  brName.reserve(friendlyClassName().size() +
140  moduleLabel().size() +
142  processName().size() + 4);
143  brName += friendlyClassName();
144  brName += underscore;
145  brName += moduleLabel();
146  brName += underscore;
147  brName += productInstanceName();
148  brName += underscore;
149  brName += processName();
150  brName += period;
151 
152  if(!branchID_.isValid()) {
153  branchID_.setID(brName);
154  }
155  }
156 
157  void
159  if(bool(wrappedType())) {
160  return; // already initialized;
161  }
162 
163  throwIfInvalid_();
164 
166 
167  // unwrapped type.
169  if(!bool(unwrappedType())) {
172  setTransient(false);
173  return;
174  }
175 
177  if(!bool(wrappedType())) {
180  return;
181  }
182  wrappedType().invokeByName(wrapperInterfaceBase(), "getInterface");
183  assert(wrapperInterfaceBase() != 0);
184  Reflex::PropertyList wp = Reflex::Type::ByTypeInfo(wrappedType().typeInfo()).Properties();
185  setTransient((wp.HasProperty("persistent") ? wp.PropertyAsString("persistent") == std::string("false") : false));
186  if(transient()) {
189  return;
190  }
191  if(wp.HasProperty("splitLevel")) {
192  setSplitLevel(strtol(wp.PropertyAsString("splitLevel").c_str(), 0, 0));
193  if(splitLevel() < 0) {
194  throw cms::Exception("IllegalSplitLevel") << "' An illegal ROOT split level of " <<
195  splitLevel() << " is specified for class " << wrappedName() << ".'\n";
196  }
197  setSplitLevel(splitLevel() + 1); //Compensate for wrapper
198  } else {
200  }
201  if(wp.HasProperty("basketSize")) {
202  setBasketSize(strtol(wp.PropertyAsString("basketSize").c_str(), 0, 0));
203  if(basketSize() <= 0) {
204  throw cms::Exception("IllegalBasketSize") << "' An illegal ROOT basket size of " <<
205  basketSize() << " is specified for class " << wrappedName() << "'.\n";
206  }
207  } else {
209  }
210  }
211 
212  void
214  branchAliases_.insert(other.branchAliases().begin(), other.branchAliases().end());
217  }
218 
219  void
220  BranchDescription::write(std::ostream& os) const {
221  os << "Branch Type = " << branchType() << std::endl;
222  os << "Process Name = " << processName() << std::endl;
223  os << "ModuleLabel = " << moduleLabel() << std::endl;
224  os << "Branch ID = " << branchID() << '\n';
225  os << "Class Name = " << fullClassName() << '\n';
226  os << "Friendly Class Name = " << friendlyClassName() << '\n';
227  os << "Product Instance Name = " << productInstanceName() << std::endl;
228  }
229 
230  void throwExceptionWithText(char const* txt) {
232  e << "Problem using an incomplete BranchDescription\n"
233  << txt
234  << "\nPlease report this error to the FWCore developers";
235  throw e;
236  }
237 
238  void
241  throwExceptionWithText("Illegal BranchType detected");
242 
243  if(moduleLabel_.empty())
244  throwExceptionWithText("Module label is not allowed to be empty");
245 
246  if(processName_.empty())
247  throwExceptionWithText("Process name is not allowed to be empty");
248 
249  if(fullClassName_.empty())
250  throwExceptionWithText("Full class name is not allowed to be empty");
251 
252  if(friendlyClassName_.empty())
253  throwExceptionWithText("Friendly class name is not allowed to be empty");
254 
255  if(produced() && !parameterSetID().isValid())
256  throwExceptionWithText("Invalid ParameterSetID detected");
257  }
258 
259  void
262  clearBranchName();
263  initBranchName();
264  }
265 
266  bool
268  if(a.processName() < b.processName()) return true;
269  if(b.processName() < a.processName()) return false;
270  if(a.fullClassName() < b.fullClassName()) return true;
271  if(b.fullClassName() < a.fullClassName()) return false;
272  if(a.friendlyClassName() < b.friendlyClassName()) return true;
273  if(b.friendlyClassName() < a.friendlyClassName()) return false;
274  if(a.productInstanceName() < b.productInstanceName()) return true;
275  if(b.productInstanceName() < a.productInstanceName()) return false;
276  if(a.moduleLabel() < b.moduleLabel()) return true;
277  if(b.moduleLabel() < a.moduleLabel()) return false;
278  if(a.branchType() < b.branchType()) return true;
279  if(b.branchType() < a.branchType()) return false;
280  if(a.branchID() < b.branchID()) return true;
281  if(b.branchID() < a.branchID()) return false;
282  if(a.branchAliases() < b.branchAliases()) return true;
283  if(b.branchAliases() < a.branchAliases()) return false;
284  if(a.present() < b.present()) return true;
285  if(b.present() < a.present()) return false;
286  return false;
287  }
288 
289  bool
291  return
292  (a.branchType() == b.branchType()) &&
293  (a.processName() == b.processName()) &&
294  (a.fullClassName() == b.fullClassName()) &&
295  (a.friendlyClassName() == b.friendlyClassName()) &&
297  (a.moduleLabel() == b.moduleLabel()) &&
298  (a.branchID() == b.branchID());
299  }
300 
301  bool
303  return combinable(a, b) &&
304  (a.dropped() == b.dropped()) &&
305  (a.branchAliases() == b.branchAliases());
306  }
307 
310  std::string const& fileName) {
311  std::ostringstream differences;
312  if(a.branchName() != b.branchName()) {
313  differences << "Branch name '" << b.branchName() << "' does not match '" << a.branchName() << "'.\n";
314  // Need not compare components of branch name individually.
315  // (a.friendlyClassName() != b.friendlyClassName())
316  // (a.moduleLabel() != b.moduleLabel())
317  // (a.productInstanceName() != b.productInstanceName())
318  // (a.processName() != b.processName())
319  }
320  if(a.branchType() != b.branchType()) {
321  differences << "Branch '" << b.branchName() << "' is a(n) '" << b.branchType() << "' branch\n";
322  differences << " in file '" << fileName << "', but a(n) '" << a.branchType() << "' branch in previous files.\n";
323  }
324  if(a.branchID() != b.branchID()) {
325  differences << "Branch '" << b.branchName() << "' has a branch ID of '" << b.branchID() << "'\n";
326  differences << " in file '" << fileName << "', but '" << a.branchID() << "' in previous files.\n";
327  }
328  if(a.fullClassName() != b.fullClassName()) {
329  differences << "Products on branch '" << b.branchName() << "' have type '" << b.fullClassName() << "'\n";
330  differences << " in file '" << fileName << "', but '" << a.fullClassName() << "' in previous files.\n";
331  }
332  if(!b.dropped() && a.dropped()) {
333  differences << "Branch '" << a.branchName() << "' was dropped in the first input file but is present in '" << fileName << "'.\n";
334  }
335  return differences.str();
336  }
337 
338  WrapperInterfaceBase const*
341  }
342 }
bool operator<(DetSet< T > const &x, DetSet< T > const &y)
Definition: DetSet.h:90
dictionary aliases
Definition: autoCond.py:23
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)
#define nullptr
std::string const & processName() const
void invokeByName(T &obj, std::string const &name) const
Definition: TypeWithDict.h:124
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)
WrapperInterfaceBase * wrapperInterfaceBase_
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
WrapperInterfaceBase const * getInterface() 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
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
WrapperInterfaceBase *& wrapperInterfaceBase()
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)