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 <cassert>
22 #include <iterator>
23 #include <limits>
24 #include <sstream>
25 #include <ostream>
26 
27 namespace edm {
28  namespace {
29  void checkDicts(BranchDescription const& productDesc) {
30  if(productDesc.transient()) {
31  checkDictionaries(productDesc.fullClassName(), true);
32  checkDictionaries(wrappedClassName(productDesc.fullClassName()), true);
33  } else {
34  checkDictionaries(wrappedClassName(productDesc.fullClassName()), false);
35  }
36  }
37  }
38 
40  productList_(),
41  transient_() {
42  }
43 
45  frozen_(false),
46  constProductList_(),
47  productProduced_(),
48  anyProductProduced_(false),
49  eventProductLookup_(new ProductHolderIndexHelper),
50  lumiProductLookup_(new ProductHolderIndexHelper),
51  runProductLookup_(new ProductHolderIndexHelper),
52  eventNextIndexValue_(0),
53  lumiNextIndexValue_(0),
54  runNextIndexValue_(0),
55 
56  branchIDToIndex_(),
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  missingDictionaries_.clear();
76  }
77 
79  productList_(productList),
80  transient_() {
81  freezeIt(toBeFrozen);
82  }
83 
84  void
86  bool fromListener) {
87  assert(productDesc.produced());
88  throwIfFrozen();
89  checkDicts(productDesc);
90  std::pair<ProductList::iterator, bool> ret =
91  productList_.insert(std::make_pair(BranchKey(productDesc), productDesc));
92  if(!ret.second) {
93  throw Exception(errors::Configuration, "Duplicate Process")
94  << "The process name " << productDesc.processName() << " was previously used on these products.\n"
95  << "Please modify the configuration file to use a distinct process name.\n";
96  }
97  addCalled(productDesc, fromListener);
98  }
99 
100  void
102  std::string const& labelAlias,
103  std::string const& instanceAlias) {
104  assert(productDesc.produced());
105  assert(productDesc.branchID().isValid());
106  throwIfFrozen();
107  BranchDescription bd(productDesc, labelAlias, instanceAlias);
108  std::pair<ProductList::iterator, bool> ret =
109  productList_.insert(std::make_pair(BranchKey(bd), bd));
110  assert(ret.second);
111  addCalled(bd, false);
112  }
113 
114  void
116  assert(!productDesc.produced());
117  throwIfFrozen();
118  BranchKey k = BranchKey(productDesc);
119  ProductList::iterator iter = productList_.find(k);
120  if(iter == productList_.end()) {
121  productList_.insert(std::make_pair(k, productDesc));
122  } else {
123  assert(combinable(iter->second, productDesc));
124  iter->second.merge(productDesc);
125  }
126  }
127 
128  bool
131  for(ProductList::const_iterator it = productList_.begin(), itEnd = productList_.end();
132  it != itEnd; ++it) {
133  if(it->second.branchType() == brType) {
134  return true;
135  }
136  }
137  return false;
138  }
139 
140  boost::shared_ptr<ProductHolderIndexHelper> const&
142  if (branchType == InEvent) return transient_.eventProductLookup_;
143  if (branchType == InLumi) return transient_.lumiProductLookup_;
145  }
146 
147  void
148  ProductRegistry::setFrozen(bool initializeLookupInfo) {
149  if(frozen()) return;
150  freezeIt();
151  if(initializeLookupInfo) {
153  }
154  }
155 
156  void
158  if(frozen()) {
159  throw cms::Exception("ProductRegistry", "throwIfFrozen")
160  << "cannot modify the ProductRegistry because it is frozen\n";
161  }
162  }
163 
164  void
166  if(!frozen()) {
167  throw cms::Exception("ProductRegistry", "throwIfNotFrozen")
168  << "cannot read the ProductRegistry because it is not yet frozen\n";
169  }
170  }
171 
172  void
174  }
175 
176  std::vector<std::string>
178  std::vector<std::string> result;
179  result.reserve(productList().size());
180 
181  for(auto const& product : productList()) {
182  result.push_back(product.second.branchName());
183  }
184  return result;
185  }
186 
187  std::vector<BranchDescription const*>
189  std::vector<BranchDescription const*> result;
190  result.reserve(productList().size());
191 
192  for(auto const& product : productList()) {
193  result.push_back(&product.second);
194  }
195  return result;
196  }
197 
198  void
200  for(auto const& product : other) {
201  copyProduct(product.second);
202  }
203  }
204 
205  void
206  ProductRegistry::updateFromInput(std::vector<BranchDescription> const& other) {
207  for(BranchDescription const& branchDescription : other) {
208  copyProduct(branchDescription);
209  }
210  }
211 
214  std::string const& fileName,
215  BranchDescription::MatchMode branchesMustMatch) {
216  std::ostringstream differences;
217 
218  ProductRegistry::ProductList::iterator j = productList_.begin();
219  ProductRegistry::ProductList::iterator s = productList_.end();
220  ProductRegistry::ProductList::const_iterator i = other.productList().begin();
221  ProductRegistry::ProductList::const_iterator e = other.productList().end();
222 
223  // Loop over entries in the main product registry.
224  while(j != s || i != e) {
225  if(j != s && j->second.produced()) {
226  // Ignore branches just produced (i.e. not in input file).
227  ++j;
228  } else if(j == s || (i != e && i->first < j->first)) {
229  if(i->second.present()) {
230  differences << "Branch '" << i->second.branchName() << "' is in file '" << fileName << "'\n";
231  differences << " but not in previous files.\n";
232  } else {
233  productList_.insert(*i);
234  transient_.branchIDToIndex_[i->second.branchID()] = getNextIndexValue(i->second.branchType());
235  ++nextIndexValue(i->second.branchType());
236  }
237  ++i;
238  } else if(i == e || (j != s && j->first < i->first)) {
239  if(j->second.present() && branchesMustMatch == BranchDescription::Strict) {
240  differences << "Branch '" << j->second.branchName() << "' is in previous files\n";
241  differences << " but not in file '" << fileName << "'.\n";
242  }
243  ++j;
244  } else {
245  std::string difs = match(j->second, i->second, fileName);
246  if(difs.empty()) {
247  j->second.merge(i->second);
248  } else {
249  differences << difs;
250  }
251  ++i;
252  ++j;
253  }
254  }
256  return differences.str();
257  }
258 
260  constProductList().clear();
261  for(auto const& product : productList_) {
262  auto const& key = product.first;
263  auto const& desc = product.second;
264  constProductList().insert(std::make_pair(key, BranchDescription(desc)));
265  }
266  }
267 
269 
270  StringSet missingDicts;
272  constProductList().clear();
273 
274  for(auto const& product : productList_) {
275  auto const& key = product.first;
276  auto const& desc = product.second;
277 
278  constProductList().insert(std::make_pair(key, BranchDescription(desc)));
279 
280  if(desc.produced()) {
281  setProductProduced(desc.branchType());
282  }
283 
284  //only do the following if the data is supposed to be available in the event
285  if(desc.present()) {
286  TypeWithDict type(TypeWithDict::byName(desc.className()));
287  TypeWithDict wrappedType(TypeWithDict::byName(wrappedClassName(desc.className())));
288  if(!bool(type) || !bool(wrappedType)) {
289  missingDicts.insert(desc.className());
290  } else {
292  productLookup(desc.branchType())->insert(type,
293  desc.moduleLabel().c_str(),
294  desc.productInstanceName().c_str(),
295  desc.processName().c_str());
296 
297  transient_.branchIDToIndex_[desc.branchID()] = index;
298  }
299  }
300  }
301  productLookup(InEvent)->setFrozen();
302  productLookup(InLumi)->setFrozen();
303  productLookup(InRun)->setFrozen();
304 
306  transient_.lumiNextIndexValue_ = productLookup(InLumi)->nextIndexValue();
307  transient_.runNextIndexValue_ = productLookup(InRun)->nextIndexValue();
308 
309  for(auto const& product : productList_) {
310  auto const& desc = product.second;
311  if (transient_.branchIDToIndex_.find(desc.branchID()) == transient_.branchIDToIndex_.end()) {
312  transient_.branchIDToIndex_[desc.branchID()] = getNextIndexValue(desc.branchType());
313  ++nextIndexValue(desc.branchType());
314  }
315  }
316 
317  missingDictionariesForUpdate().reserve(missingDicts.size());
318  copy_all(missingDicts, std::back_inserter(missingDictionariesForUpdate()));
319  }
320 
322  std::map<BranchID, ProductHolderIndex>::const_iterator itFind = transient_.branchIDToIndex_.find(iID);
323  if(itFind == transient_.branchIDToIndex_.end()) {
325  }
326  return itFind->second;
327  }
328 
329  void ProductRegistry::print(std::ostream& os) const {
330  for(auto const& product: productList_) {
331  os << product.second << "\n-----\n";
332  }
333  }
334 
335  ProductHolderIndex const&
337  if (branchType == InEvent) return transient_.eventNextIndexValue_;
338  if (branchType == InLumi) return transient_.lumiNextIndexValue_;
340  }
341 
344  if (branchType == InEvent) return transient_.eventNextIndexValue_;
345  if (branchType == InLumi) return transient_.lumiNextIndexValue_;
347  }
348 }
type
Definition: HCALResponse.h:21
int i
Definition: DBlmapReader.cc:9
void setProductProduced(BranchType branchType)
static TypeWithDict byName(std::string const &className)
boost::shared_ptr< ProductHolderIndexHelper > lumiProductLookup_
ProductHolderIndex & nextIndexValue(BranchType branchType)
void throwIfNotFrozen() const
std::vector< std::string > allBranchNames() const
std::map< BranchKey, BranchDescription > ProductList
ProductHolderIndex indexFrom(BranchID const &iID) const
bool anyProducts(BranchType const brType) const
std::string const & processName() const
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
ConstProductList & constProductList()
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
std::string merge(ProductRegistry const &other, std::string const &fileName, BranchDescription::MatchMode branchesMustMatch=BranchDescription::Permissive)
boost::array< bool, NumBranchTypes > productProduced_
BranchID const & branchID() const
bool insert(Storage &iStorage, ItemType *iItem, const IdTag &iIdTag)
Definition: HCMethods.h:49
void setFrozen(bool initializeLookupInfo=true)
void freezeIt(bool frozen=true)
void print(std::ostream &os) const
ProductHolderIndex runNextIndexValue_
int k[5][pyjets_maxn]
std::vector< std::string > & missingDictionariesForUpdate()
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_
volatile std::atomic< bool > shutdown_flag false
void addProduct(BranchDescription const &productdesc, bool iFromListener=false)
void copyProduct(BranchDescription const &productdesc)
std::string match(BranchDescription const &a, BranchDescription const &b, std::string const &fileName)