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 
21 
22 #include <cassert>
23 #include <iterator>
24 #include <limits>
25 #include <sstream>
26 #include <ostream>
27 
28 namespace edm {
29 
31  productList_(),
32  transient_() {
33  }
34 
36  frozen_(false),
37  productProduced_(),
38  anyProductProduced_(false),
39  eventProductLookup_(new ProductHolderIndexHelper),
40  lumiProductLookup_(new ProductHolderIndexHelper),
41  runProductLookup_(new ProductHolderIndexHelper),
42  eventNextIndexValue_(0),
43  lumiNextIndexValue_(0),
44  runNextIndexValue_(0),
45 
46  branchIDToIndex_(),
47  missingDictionaries_() {
48  for(bool& isProduced : productProduced_) isProduced = false;
49  }
50 
51  void
53  frozen_ = false;
54  for(bool& isProduced : productProduced_) isProduced = false;
55  anyProductProduced_ = false;
56 
57  // propagate_const<T> has no reset() function
58  eventProductLookup_ = std::make_unique<ProductHolderIndexHelper>();
59  lumiProductLookup_ = std::make_unique<ProductHolderIndexHelper>();
60  runProductLookup_ = std::make_unique<ProductHolderIndexHelper>();
61 
62  eventNextIndexValue_ = 0;
63  lumiNextIndexValue_ = 0;
64  runNextIndexValue_ = 0;
65 
66  branchIDToIndex_.clear();
67  missingDictionaries_.clear();
68  }
69 
71  productList_(productList),
72  transient_() {
73  freezeIt(toBeFrozen);
74  }
75 
76  void
78  bool fromListener) {
79  assert(productDesc.produced());
80  throwIfFrozen();
81  std::pair<ProductList::iterator, bool> ret =
82  productList_.insert(std::make_pair(BranchKey(productDesc), productDesc));
83  if(!ret.second) {
84  throw Exception(errors::Configuration, "Duplicate Process")
85  << "The process name " << productDesc.processName() << " was previously used on these products.\n"
86  << "Please modify the configuration file to use a distinct process name.\n";
87  }
88  addCalled(productDesc, fromListener);
89  }
90 
91  void
93  std::string const& labelAlias,
94  std::string const& instanceAlias) {
95  assert(productDesc.produced());
96  assert(productDesc.branchID().isValid());
97  throwIfFrozen();
98  BranchDescription bd(productDesc, labelAlias, instanceAlias);
99  std::pair<ProductList::iterator, bool> ret =
100  productList_.insert(std::make_pair(BranchKey(bd), bd));
101  assert(ret.second);
102  transient_.aliasToOriginal_.emplace_back(labelAlias,
103  productDesc.moduleLabel());
104  addCalled(bd, false);
105  }
106 
107  void
109  assert(!productDesc.produced());
110  throwIfFrozen();
111  BranchKey k = BranchKey(productDesc);
112  ProductList::iterator iter = productList_.find(k);
113  if(iter == productList_.end()) {
114  productList_.insert(std::make_pair(k, productDesc));
115  } else {
116  assert(combinable(iter->second, productDesc));
117  iter->second.merge(productDesc);
118  }
119  }
120 
121  bool
124  for(ProductList::const_iterator it = productList_.begin(), itEnd = productList_.end();
125  it != itEnd; ++it) {
126  if(it->second.branchType() == brType) {
127  return true;
128  }
129  }
130  return false;
131  }
132 
133  std::shared_ptr<ProductHolderIndexHelper const>
135  if (branchType == InEvent) return transient_.eventProductLookup();
136  if (branchType == InLumi) return transient_.lumiProductLookup();
137  return transient_.runProductLookup();
138  }
139 
140  std::shared_ptr<ProductHolderIndexHelper>
142  if (branchType == InEvent) return transient_.eventProductLookup();
143  if (branchType == InLumi) return transient_.lumiProductLookup();
144  return transient_.runProductLookup();
145  }
146 
147  void
148  ProductRegistry::setFrozen(bool initializeLookupInfo) {
149  if(frozen()) return;
150  freezeIt();
151  if(initializeLookupInfo) {
153  }
155  }
156 
157  void
159  if(frozen()) {
160  throw cms::Exception("ProductRegistry", "throwIfFrozen")
161  << "cannot modify the ProductRegistry because it is frozen\n";
162  }
163  }
164 
165  void
167  if(!frozen()) {
168  throw cms::Exception("ProductRegistry", "throwIfNotFrozen")
169  << "cannot read the ProductRegistry because it is not yet frozen\n";
170  }
171  }
172 
173  void
175  }
176 
177  std::vector<std::string>
179  std::vector<std::string> result;
180  result.reserve(productList().size());
181 
182  for(auto const& product : productList()) {
183  result.push_back(product.second.branchName());
184  }
185  return result;
186  }
187 
188  std::vector<BranchDescription const*>
190  std::vector<BranchDescription const*> result;
191  result.reserve(productList().size());
192 
193  for(auto const& product : productList()) {
194  result.push_back(&product.second);
195  }
196  return result;
197  }
198 
199  void
201  for(auto const& product : other) {
202  copyProduct(product.second);
203  }
204  }
205 
206  void
207  ProductRegistry::updateFromInput(std::vector<BranchDescription> const& other) {
208  for(BranchDescription const& branchDescription : other) {
209  copyProduct(branchDescription);
210  }
211  }
212 
215  std::string const& fileName,
216  BranchDescription::MatchMode branchesMustMatch) {
217  std::ostringstream differences;
218 
219  ProductRegistry::ProductList::iterator j = productList_.begin();
220  ProductRegistry::ProductList::iterator s = productList_.end();
221  ProductRegistry::ProductList::const_iterator i = other.productList().begin();
222  ProductRegistry::ProductList::const_iterator e = other.productList().end();
223 
224  // Loop over entries in the main product registry.
225  while(j != s || i != e) {
226  if(j != s && j->second.produced()) {
227  // Ignore branches just produced (i.e. not in input file).
228  ++j;
229  } else if(j == s || (i != e && i->first < j->first)) {
230  if(i->second.present()) {
231  differences << "Branch '" << i->second.branchName() << "' is in file '" << fileName << "'\n";
232  differences << " but not in previous files.\n";
233  } else {
234  productList_.insert(*i);
235  transient_.branchIDToIndex_[i->second.branchID()] = getNextIndexValue(i->second.branchType());
236  ++nextIndexValue(i->second.branchType());
237  }
238  ++i;
239  } else if(i == e || (j != s && j->first < i->first)) {
240  if(j->second.present() && branchesMustMatch == BranchDescription::Strict) {
241  differences << "Branch '" << j->second.branchName() << "' is in previous files\n";
242  differences << " but not in file '" << fileName << "'.\n";
243  }
244  ++j;
245  } else {
246  std::string difs = match(j->second, i->second, fileName);
247  if(difs.empty()) {
248  j->second.merge(i->second);
249  } else {
250  differences << difs;
251  }
252  ++i;
253  ++j;
254  }
255  }
256  return differences.str();
257  }
258 
260 
261  std::map<TypeID, TypeID> containedTypeMap;
262  TypeSet missingDicts;
263 
265 
266  for(auto const& product : productList_) {
267  auto const& desc = product.second;
268 
269  if(desc.produced()) {
270  setProductProduced(desc.branchType());
271  }
272 
273  //only do the following if the data is supposed to be available in the event
274  if(desc.present()) {
275  if(!bool(desc.unwrappedType())) {
276  missingDicts.insert(TypeID(desc.unwrappedType().typeInfo()));
277  } else if(!bool(desc.wrappedType())) {
278  missingDicts.insert(TypeID(desc.wrappedType().typeInfo()));
279  } else {
280  TypeID wrappedTypeID(desc.wrappedType().typeInfo());
281  TypeID typeID(desc.unwrappedType().typeInfo());
282  TypeID containedTypeID;
283  auto const& iter = containedTypeMap.find(typeID);
284  if(iter != containedTypeMap.end()) {
285  containedTypeID = iter->second;
286  } else {
287  containedTypeID = productholderindexhelper::getContainedTypeFromWrapper(wrappedTypeID, typeID.className());
288  containedTypeMap.emplace(typeID, containedTypeID);
289  }
291  productLookup(desc.branchType())->insert(typeID,
292  desc.moduleLabel().c_str(),
293  desc.productInstanceName().c_str(),
294  desc.processName().c_str(),
295  containedTypeID);
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 }
int i
Definition: DBlmapReader.cc:9
tuple ret
prodAgent to be discontinued
void setProductProduced(BranchType branchType)
ProductHolderIndex & nextIndexValue(BranchType branchType)
std::vector< TypeID > & missingDictionariesForUpdate()
void throwIfNotFrozen() const
TypeID getContainedTypeFromWrapper(TypeID const &wrappedtypeID, std::string const &className)
std::shared_ptr< ProductHolderIndexHelper const > runProductLookup() const
std::vector< std::string > allBranchNames() const
std::map< BranchKey, BranchDescription > ProductList
ProductHolderIndex indexFrom(BranchID const &iID) const
assert(m_qm.get())
bool anyProducts(BranchType const brType) const
std::string const & processName() const
ProductHolderIndex eventNextIndexValue_
std::shared_ptr< ProductHolderIndexHelper const > productLookup(BranchType branchType) const
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)
tuple result
Definition: mps_fire.py:84
ProductList const & productList() const
std::shared_ptr< ProductHolderIndexHelper const > lumiProductLookup() const
std::string const & moduleLabel() const
std::set< TypeID > TypeSet
bool combinable(BranchDescription const &a, BranchDescription const &b)
ProductHolderIndex lumiNextIndexValue_
std::shared_ptr< ProductHolderIndexHelper const > eventProductLookup() const
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_
void sort_all(RandomAccessSequence &s)
wrappers for std::sort
Definition: Algorithms.h:120
std::vector< std::pair< std::string, std::string > > aliasToOriginal_
Func copy_all(ForwardSequence &s, Func f)
wrappers for copy
Definition: Algorithms.h:24
void throwIfFrozen() const
void updateFromInput(ProductList const &other)
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)