CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ProductRegistry.cc
Go to the documentation of this file.
1 
12 
14 
20 
21 #include <iterator>
22 #include <limits>
23 #include <sstream>
24 #include <ostream>
25 
26 namespace edm {
27  namespace {
28  void checkDicts(BranchDescription const& productDesc) {
29  if(productDesc.transient()) {
30  checkDictionaries(productDesc.fullClassName(), true);
31  checkDictionaries(wrappedClassName(productDesc.fullClassName()), true);
32  } else {
33  checkDictionaries(wrappedClassName(productDesc.fullClassName()), false);
34  }
35  }
36  }
37 
39  productList_(),
40  transient_() {
41  }
42 
44  frozen_(false),
45  constProductList_(),
46  productProduced_(),
47  anyProductProduced_(false),
48  eventProductLookup_(new ProductHolderIndexHelper),
49  lumiProductLookup_(new ProductHolderIndexHelper),
50  runProductLookup_(new ProductHolderIndexHelper),
51  eventNextIndexValue_(0),
52  lumiNextIndexValue_(0),
53  runNextIndexValue_(0),
54 
55  branchIDToIndex_(),
56  producedBranchListIndex_(std::numeric_limits<BranchListIndex>::max()),
57  missingDictionaries_() {
58  for(bool& isProduced : productProduced_) isProduced = false;
59  }
60 
61  void
63  frozen_ = false;
64  constProductList_.clear();
65  for(bool& isProduced : productProduced_) isProduced = false;
66  anyProductProduced_ = false;
67  eventProductLookup_.reset(new ProductHolderIndexHelper);
68  lumiProductLookup_.reset(new ProductHolderIndexHelper);
69  runProductLookup_.reset(new ProductHolderIndexHelper);
70  eventNextIndexValue_ = 0;
71  lumiNextIndexValue_ = 0;
72  runNextIndexValue_ = 0;
73 
74  branchIDToIndex_.clear();
75  producedBranchListIndex_ = std::numeric_limits<BranchListIndex>::max();
76  missingDictionaries_.clear();
77  }
78 
80  productList_(productList),
81  transient_() {
82  frozen() = toBeFrozen;
83  }
84 
85  void
87  bool fromListener) {
88  assert(productDesc.produced());
89  throwIfFrozen();
90  checkDicts(productDesc);
91  std::pair<ProductList::iterator, bool> ret =
92  productList_.insert(std::make_pair(BranchKey(productDesc), productDesc));
93  if(!ret.second) {
94  throw Exception(errors::Configuration, "Duplicate Process")
95  << "The process name " << productDesc.processName() << " was previously used on these products.\n"
96  << "Please modify the configuration file to use a distinct process name.\n";
97  }
98  addCalled(productDesc, fromListener);
99  }
100 
101  void
103  std::string const& labelAlias,
104  std::string const& instanceAlias) {
105  assert(productDesc.produced());
106  assert(productDesc.branchID().isValid());
107  throwIfFrozen();
108  BranchDescription bd(productDesc, labelAlias, instanceAlias);
109  std::pair<ProductList::iterator, bool> ret =
110  productList_.insert(std::make_pair(BranchKey(bd), bd));
111  assert(ret.second);
112  addCalled(bd, false);
113  }
114 
115  void
117  assert(!productDesc.produced());
118  throwIfFrozen();
119  productDesc.init();
120  BranchKey k = BranchKey(productDesc);
121  ProductList::iterator iter = productList_.find(k);
122  if(iter == productList_.end()) {
123  productList_.insert(std::make_pair(k, productDesc));
124  } else {
125  assert(combinable(iter->second, productDesc));
126  iter->second.merge(productDesc);
127  }
128  }
129 
130  bool
133  for(ProductList::const_iterator it = productList_.begin(), itEnd = productList_.end();
134  it != itEnd; ++it) {
135  if(it->second.branchType() == brType) {
136  return true;
137  }
138  }
139  return false;
140  }
141 
142  boost::shared_ptr<ProductHolderIndexHelper> const&
144  if (branchType == InEvent) return transient_.eventProductLookup_;
145  if (branchType == InLumi) return transient_.lumiProductLookup_;
147  }
148 
149  void
150  ProductRegistry::setFrozen(bool initializeLookupInfo) const {
151  if(frozen()) return;
152  frozen() = true;
153  if(initializeLookupInfo) {
155  }
156  }
157 
158  void
160  if(frozen()) {
161  throw cms::Exception("ProductRegistry", "throwIfFrozen")
162  << "cannot modify the ProductRegistry because it is frozen\n";
163  }
164  }
165 
166  void
168  if(!frozen()) {
169  throw cms::Exception("ProductRegistry", "throwIfNotFrozen")
170  << "cannot read the ProductRegistry because it is not yet frozen\n";
171  }
172  }
173 
174  void
176  }
177 
178  std::vector<std::string>
180  std::vector<std::string> result;
181  result.reserve(productList().size());
182 
183  for(auto const& product : productList()) {
184  result.push_back(product.second.branchName());
185  }
186  return result;
187  }
188 
189  std::vector<BranchDescription const*>
191  std::vector<BranchDescription const*> result;
192  result.reserve(productList().size());
193 
194  for(auto const& product : productList()) {
195  result.push_back(&product.second);
196  }
197  return result;
198  }
199 
200  void
202  for(auto const& product : other) {
203  copyProduct(product.second);
204  }
205  }
206 
207  void
208  ProductRegistry::updateFromInput(std::vector<BranchDescription> const& other) {
209  for(BranchDescription const& branchDescription : other) {
210  copyProduct(branchDescription);
211  }
212  }
213 
216  std::string const& fileName,
217  BranchDescription::MatchMode parametersMustMatch,
218  BranchDescription::MatchMode branchesMustMatch) {
219  std::ostringstream differences;
220 
221  ProductRegistry::ProductList::iterator j = productList_.begin();
222  ProductRegistry::ProductList::iterator s = productList_.end();
223  ProductRegistry::ProductList::const_iterator i = other.productList().begin();
224  ProductRegistry::ProductList::const_iterator e = other.productList().end();
225 
226  // Loop over entries in the main product registry.
227  while(j != s || i != e) {
228  if(j != s && j->second.produced()) {
229  // Ignore branches just produced (i.e. not in input file).
230  ++j;
231  } else if(j == s || (i != e && i->first < j->first)) {
232  if(i->second.present()) {
233  differences << "Branch '" << i->second.branchName() << "' is in file '" << fileName << "'\n";
234  differences << " but not in previous files.\n";
235  } else {
236  productList_.insert(*i);
237  transient_.branchIDToIndex_[i->second.branchID()] = nextIndexValue(i->second.branchType());
238  ++nextIndexValue(i->second.branchType());
239  }
240  ++i;
241  } else if(i == e || (j != s && j->first < i->first)) {
242  if(j->second.present() && branchesMustMatch == BranchDescription::Strict) {
243  differences << "Branch '" << j->second.branchName() << "' is in previous files\n";
244  differences << " but not in file '" << fileName << "'.\n";
245  }
246  ++j;
247  } else {
248  std::string difs = match(j->second, i->second, fileName, parametersMustMatch);
249  if(difs.empty()) {
250  if(parametersMustMatch == BranchDescription::Permissive) j->second.merge(i->second);
251  } else {
252  differences << difs;
253  }
254  ++i;
255  ++j;
256  }
257  }
259  return differences.str();
260  }
261 
263  constProductList().clear();
264  for(auto const& product : productList_) {
265  auto const& key = product.first;
266  auto const& desc = product.second;
267  constProductList().insert(std::make_pair(key, ConstBranchDescription(desc)));
268  }
269  }
270 
272 
273  StringSet missingDicts;
275  constProductList().clear();
276 
277  for(auto const& product : productList_) {
278  auto const& key = product.first;
279  auto const& desc = product.second;
280 
281  constProductList().insert(std::make_pair(key, ConstBranchDescription(desc)));
282 
283  if(desc.produced()) {
284  setProductProduced(desc.branchType());
285  }
286 
287  //only do the following if the data is supposed to be available in the event
288  if(desc.present()) {
289  TypeWithDict type(TypeWithDict::byName(desc.className()));
290  TypeWithDict wrappedType(TypeWithDict::byName(wrappedClassName(desc.className())));
291  if(!bool(type) || !bool(wrappedType)) {
292  missingDicts.insert(desc.className());
293  } else {
295  productLookup(desc.branchType())->insert(type,
296  desc.moduleLabel().c_str(),
297  desc.productInstanceName().c_str(),
298  desc.processName().c_str());
299 
300  transient_.branchIDToIndex_[desc.branchID()] = index;
301  }
302  }
303  }
304  productLookup(InEvent)->setFrozen();
305  productLookup(InLumi)->setFrozen();
306  productLookup(InRun)->setFrozen();
307 
309  transient_.lumiNextIndexValue_ = productLookup(InLumi)->nextIndexValue();
310  transient_.runNextIndexValue_ = productLookup(InRun)->nextIndexValue();
311 
312  for(auto const& product : productList_) {
313  auto const& desc = product.second;
314  if (transient_.branchIDToIndex_.find(desc.branchID()) == transient_.branchIDToIndex_.end()) {
315  transient_.branchIDToIndex_[desc.branchID()] = nextIndexValue(desc.branchType());
316  ++nextIndexValue(desc.branchType());
317  }
318  }
319 
320  missingDictionaries().reserve(missingDicts.size());
321  copy_all(missingDicts, std::back_inserter(missingDictionaries()));
322  }
323 
325  std::map<BranchID, ProductHolderIndex>::iterator itFind = transient_.branchIDToIndex_.find(iID);
326  if(itFind == transient_.branchIDToIndex_.end()) {
328  }
329  return itFind->second;
330  }
331 
332  void ProductRegistry::print(std::ostream& os) const {
333  for(auto const& product: productList_) {
334  os << product.second << "\n-----\n";
335  }
336  }
337 
338  ProductHolderIndex const&
340  if (branchType == InEvent) return transient_.eventNextIndexValue_;
341  if (branchType == InLumi) return transient_.lumiNextIndexValue_;
343  }
344 
347  if (branchType == InEvent) return transient_.eventNextIndexValue_;
348  if (branchType == InLumi) return transient_.lumiNextIndexValue_;
350  }
351 }
type
Definition: HCALResponse.h:21
int i
Definition: DBlmapReader.cc:9
unsigned short BranchListIndex
static TypeWithDict byName(std::string const &className)
boost::shared_ptr< ProductHolderIndexHelper > lumiProductLookup_
void setProductProduced(BranchType branchType) const
ConstProductList & constProductList() const
void throwIfNotFrozen() const
std::vector< std::string > allBranchNames() const
std::map< BranchKey, BranchDescription > ProductList
ProductHolderIndex indexFrom(BranchID const &iID) const
bool & produced() const
bool anyProducts(BranchType const brType) const
std::string const & processName() const
std::string merge(ProductRegistry const &other, std::string const &fileName, BranchDescription::MatchMode parametersMustMatch=BranchDescription::Permissive, BranchDescription::MatchMode branchesMustMatch=BranchDescription::Permissive)
std::string match(BranchDescription const &a, BranchDescription const &b, std::string const &fileName, BranchDescription::MatchMode m)
ProductHolderIndex eventNextIndexValue_
unsigned int ProductHolderIndex
ProductList::size_type size() const
bool isValid() const
Definition: BranchID.h:24
ProductHolderIndex const & getNextIndexValue(BranchType branchType) const
void addLabelAlias(BranchDescription const &productdesc, std::string const &labelAlias, std::string const &instanceAlias)
BranchType
Definition: BranchType.h:11
virtual void addCalled(BranchDescription const &, bool iFromListener)
boost::shared_ptr< ProductHolderIndexHelper > const & productLookup(BranchType branchType) const
ProductList const & productList() const
const T & max(const T &a, const T &b)
std::vector< std::string > & missingDictionaries() const
bool combinable(BranchDescription const &a, BranchDescription const &b)
std::set< std::string > StringSet
tuple result
Definition: query.py:137
void checkDictionaries(std::string const &name, bool noComponents=false)
ProductHolderIndex lumiNextIndexValue_
int j
Definition: DBlmapReader.cc:9
std::vector< BranchDescription const * > allBranchDescriptions() const
boost::array< bool, NumBranchTypes > productProduced_
BranchID const & branchID() const
bool insert(Storage &iStorage, ItemType *iItem, const IdTag &iIdTag)
Definition: HCMethods.h:49
void print(std::ostream &os) const
ProductHolderIndex runNextIndexValue_
int k[5][pyjets_maxn]
void setFrozen(bool initializeLookupInfo=true) const
void initializeLookupTables() const
boost::shared_ptr< ProductHolderIndexHelper > runProductLookup_
std::string wrappedClassName(std::string const &iFullName)
list key
Definition: combine.py:13
Func copy_all(ForwardSequence &s, Func f)
wrappers for copy
Definition: Algorithms.h:24
void throwIfFrozen() const
void updateFromInput(ProductList const &other)
boost::shared_ptr< ProductHolderIndexHelper > eventProductLookup_
std::map< BranchID, ProductHolderIndex > branchIDToIndex_
bool & frozen() const
void addProduct(BranchDescription const &productdesc, bool iFromListener=false)
ProductHolderIndex & nextIndexValue(BranchType branchType) const
void copyProduct(BranchDescription const &productdesc)
EventID const & max(EventID const &lh, EventID const &rh)
Definition: EventID.h:137