CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Types | Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes
edm::ProductRegistry Class Reference

author Stefano ARGIRO author Bill Tanenbaum More...

#include "edm/ProductRegistry.h"

Inheritance diagram for edm::ProductRegistry:
edm::SignallingProductRegistry

Classes

struct  Transients
 

Public Types

typedef std::map< BranchKey,
ConstBranchDescription
ConstProductList
 
typedef std::map< BranchKey,
BranchDescription
ProductList
 

Public Member Functions

void addProduct (BranchDescription const &productdesc, bool iFromListener=false)
 
std::vector< BranchDescription
const * > 
allBranchDescriptions () const
 
std::vector< std::string > allBranchNames () const
 
bool anyProductProduced () const
 
bool anyProducts (BranchType const brType) const
 
template<typename T >
void callForEachBranch (T const &iFunc)
 
ConstProductListconstProductList () const
 
void copyProduct (BranchDescription const &productdesc)
 
TransientProductLookupMapelementLookup () const
 
ProductTransientIndex indexFrom (BranchID const &iID) const
 
void initializeTransients () const
 
std::string merge (ProductRegistry const &other, std::string const &fileName, BranchDescription::MatchMode parametersMustMatch=BranchDescription::Permissive, BranchDescription::MatchMode branchesMustMatch=BranchDescription::Permissive)
 
std::vector< std::string > & missingDictionaries () const
 
void print (std::ostream &os) const
 
BranchListIndex producedBranchListIndex () const
 
ProductList const & productList () const
 
ProductListproductListUpdator ()
 
TransientProductLookupMapproductLookup () const
 
bool productProduced (BranchType branchType) const
 
 ProductRegistry ()
 
 ProductRegistry (ProductList const &productList, bool toBeFrozen=true)
 
void setFrozen (bool initializeLookupInfo=true) const
 
void setProducedBranchListIndex (BranchListIndex blix) const
 
ProductList::size_type size () const
 
void updateFromInput (ProductList const &other)
 
void updateFromInput (std::vector< BranchDescription > const &other)
 
virtual ~ProductRegistry ()
 

Static Public Attributes

static ProductTransientIndex const kInvalidIndex = 0xFFFFFFFF
 

Private Member Functions

virtual void addCalled (BranchDescription const &, bool iFromListener)
 
bool & frozen () const
 
void initializeLookupTables () const
 
void setProductProduced (BranchType branchType) const
 
void throwIfFrozen () const
 
void throwIfNotFrozen () const
 

Private Attributes

ProductList productList_
 
Transients transient_
 

Detailed Description

author Stefano ARGIRO author Bill Tanenbaum

Date
19 Jul 2005

Definition at line 40 of file ProductRegistry.h.

Member Typedef Documentation

Definition at line 54 of file ProductRegistry.h.

Definition at line 43 of file ProductRegistry.h.

Constructor & Destructor Documentation

edm::ProductRegistry::ProductRegistry ( )

Definition at line 34 of file ProductRegistry.cc.

34  :
35  productList_(),
36  transient_() {
37  }
edm::ProductRegistry::ProductRegistry ( ProductList const &  productList,
bool  toBeFrozen = true 
)
explicit

Definition at line 65 of file ProductRegistry.cc.

References frozen().

65  :
67  transient_() {
68  frozen() = toBeFrozen;
69  }
ProductList const & productList() const
bool & frozen() const
virtual edm::ProductRegistry::~ProductRegistry ( )
inlinevirtual

Definition at line 52 of file ProductRegistry.h.

52 {}

Member Function Documentation

void edm::ProductRegistry::addCalled ( BranchDescription const &  ,
bool  iFromListener 
)
privatevirtual

Reimplemented in edm::SignallingProductRegistry.

Definition at line 140 of file ProductRegistry.cc.

Referenced by addProduct().

140  {
141  }
void edm::ProductRegistry::addProduct ( BranchDescription const &  productdesc,
bool  iFromListener = false 
)

Definition at line 72 of file ProductRegistry.cc.

References addCalled(), edm::errors::Configuration, edm::hlt::Exception, edm::BranchDescription::processName(), edm::BranchDescription::produced(), productList_, run_regression::ret, and throwIfFrozen().

Referenced by edm::ProductRegistryHelper::addToRegistry().

73  {
74  assert(productDesc.produced());
75  throwIfFrozen();
76  checkDicts(productDesc);
77  std::pair<ProductList::iterator, bool> ret =
78  productList_.insert(std::make_pair(BranchKey(productDesc), productDesc));
79  if(!ret.second) {
80  throw Exception(errors::Configuration, "Duplicate Process")
81  << "The process name " << productDesc.processName() << " was previously used on these products.\n"
82  << "Please modify the configuration file to use a distinct process name.\n";
83  }
84  addCalled(productDesc, fromListener);
85  }
virtual void addCalled(BranchDescription const &, bool iFromListener)
void throwIfFrozen() const
std::vector< BranchDescription const * > edm::ProductRegistry::allBranchDescriptions ( ) const

Definition at line 157 of file ProductRegistry.cc.

References end, productList(), query::result, and size().

Referenced by edm::ConstProductRegistry::allBranchDescriptions(), and edm::RootFile::dropOnInput().

157  {
158  std::vector<BranchDescription const*> result;
159  result.reserve(productList().size());
160 
161  ProductList::const_iterator it = productList().begin();
162  ProductList::const_iterator end = productList().end();
163 
164  for(; it != end; ++it) result.push_back(&(it->second));
165  return result;
166  }
ProductList::size_type size() const
ProductList const & productList() const
tuple result
Definition: query.py:137
#define end
Definition: vmac.h:38
std::vector< std::string > edm::ProductRegistry::allBranchNames ( ) const

Definition at line 144 of file ProductRegistry.cc.

References end, productList(), query::result, and size().

Referenced by edm::ConstProductRegistry::allBranchNames().

144  {
145  std::vector<std::string> result;
146  result.reserve(productList().size());
147 
148  ProductList::const_iterator it = productList().begin();
149  ProductList::const_iterator end = productList().end();
150 
151  for(; it != end; ++it) result.push_back(it->second.branchName());
152 
153  return result;
154  }
ProductList::size_type size() const
ProductList const & productList() const
tuple result
Definition: query.py:137
#define end
Definition: vmac.h:38
bool edm::ProductRegistry::anyProductProduced ( ) const
inline
bool edm::ProductRegistry::anyProducts ( BranchType const  brType) const

Definition at line 103 of file ProductRegistry.cc.

References productList_, and throwIfNotFrozen().

103  {
105  for(ProductList::const_iterator it = productList_.begin(), itEnd = productList_.end();
106  it != itEnd; ++it) {
107  if(it->second.branchType() == brType) {
108  return true;
109  }
110  }
111  return false;
112  }
void throwIfNotFrozen() const
template<typename T >
void edm::ProductRegistry::callForEachBranch ( T const &  iFunc)
inline

Definition at line 95 of file ProductRegistry.h.

References productList_.

Referenced by edm::ProducerBase::registerProducts().

95  {
96  //NOTE: If implementation changes from a map, need to check that iterators are still valid
97  // after an insert with the new container, else need to copy the container and iterate over the copy
98  for(ProductRegistry::ProductList::const_iterator itEntry = productList_.begin(),
99  itEntryEnd = productList_.end();
100  itEntry != itEntryEnd; ++itEntry) {
101  iFunc(itEntry->second);
102  }
103  }
ConstProductList& edm::ProductRegistry::constProductList ( ) const
inline

Definition at line 110 of file ProductRegistry.h.

References edm::ProductRegistry::Transients::constProductList_, and transient_.

Referenced by edm::Principal::adjustToNewProductRegistry(), and initializeLookupTables().

110  {
111  //throwIfNotFrozen();
113  }
void edm::ProductRegistry::copyProduct ( BranchDescription const &  productdesc)

Definition at line 88 of file ProductRegistry.cc.

References edm::combinable(), edm::BranchDescription::init(), gen::k, edm::BranchDescription::produced(), productList_, and throwIfFrozen().

Referenced by edm::DaqProvenanceHelper::daqInit(), edm::RootFile::RootFile(), and updateFromInput().

88  {
89  assert(!productDesc.produced());
90  throwIfFrozen();
91  productDesc.init();
92  BranchKey k = BranchKey(productDesc);
93  ProductList::iterator iter = productList_.find(k);
94  if(iter == productList_.end()) {
95  productList_.insert(std::make_pair(k, productDesc));
96  } else {
97  assert(combinable(iter->second, productDesc));
98  iter->second.merge(productDesc);
99  }
100  }
bool combinable(BranchDescription const &a, BranchDescription const &b)
int k[5][pyjets_maxn]
void throwIfFrozen() const
TransientProductLookupMap& edm::ProductRegistry::elementLookup ( ) const
inline

Definition at line 117 of file ProductRegistry.h.

References edm::ProductRegistry::Transients::elementLookup_, and transient_.

Referenced by initializeLookupTables().

117 {return transient_.elementLookup_;}
TransientProductLookupMap elementLookup_
bool& edm::ProductRegistry::frozen ( ) const
inlineprivate
ProductTransientIndex edm::ProductRegistry::indexFrom ( BranchID const &  iID) const

Definition at line 319 of file ProductRegistry.cc.

References edm::ProductRegistry::Transients::branchIDToIndex_, kInvalidIndex, and transient_.

319  {
320  std::map<BranchID, ProductTransientIndex>::iterator itFind = transient_.branchIDToIndex_.find(iID);
321  if(itFind == transient_.branchIDToIndex_.end()) {
322  return kInvalidIndex;
323  }
324  return itFind->second;
325  }
static ProductTransientIndex const kInvalidIndex
std::map< BranchID, ProductTransientIndex > branchIDToIndex_
void edm::ProductRegistry::initializeLookupTables ( ) const
private

Definition at line 240 of file ProductRegistry.cc.

References edm::ProductRegistry::Transients::branchIDToIndex_, constProductList(), edm::copy_all(), alignCSCRings::e, elementLookup(), edm::TransientProductLookupMap::fillFrom(), edm::fillLookup(), edm::foundTypes(), i, getHLTprescales::index, edm::is_PtrVector(), edm::is_RefToBaseVector(), edm::is_RefVector(), missingDictionaries(), edm::missingTypes(), edm::ConstBranchDescription::processName(), productList_, productLookup(), edm::public_base_classes(), setProductProduced(), transient_, edm::value_type_of(), and edm::wrappedClassName().

Referenced by merge(), and setFrozen().

240  {
241  StringSet savedMissingTypes;
242  savedMissingTypes.swap(missingTypes());
243  StringSet savedFoundTypes;
244  savedFoundTypes.swap(foundTypes());
245  constProductList().clear();
248 
249  //NOTE it might be possible to remove the need for this temporary map because the productList is ordered by the
250  // BranchKey and for the same C++ class type the BranchKey will sort just like CompareTypeInBranchTypeConstBranchDescription
251  typedef TransientProductLookupMap::FillFromMap TempLookupMap;
252  TempLookupMap tempProductLookupMap;
253  TempLookupMap tempElementLookupMap;
254 
255  StringSet usedProcessNames;
256  StringSet missingDicts;
257  for(ProductList::const_iterator i = productList_.begin(), e = productList_.end(); i != e; ++i, ++index) {
258  if(i->second.produced()) {
259  setProductProduced(i->second.branchType());
260  }
261 
262  //insert returns a pair<iterator, bool> and we want the address of the ConstBranchDescription that was created in the map
263  // this is safe since items in a map always retain their memory address
264  ConstBranchDescription const* pBD = &(constProductList().insert(std::make_pair(i->first, ConstBranchDescription(i->second))).first->second);
265 
266  transient_.branchIDToIndex_[i->second.branchID()] = index;
267 
268  usedProcessNames.insert(pBD->processName());
269 
270  //only do the following if the data is supposed to be available in the event
271  if(i->second.present()) {
272  Reflex::Type type(Reflex::Type::ByName(i->second.className()));
273  Reflex::Type wrappedType(Reflex::Type::ByName(wrappedClassName(i->second.className())));
274  if(!bool(type) || !bool(wrappedType)) {
275  missingDicts.insert(i->second.className());
276  continue;
277  }
278  fillLookup(type, index, pBD, tempProductLookupMap);
279 
280  if(bool(type)) {
281  // Here we look in the object named "type" for a typedef
282  // named "value_type" and get the Reflex::Type for it.
283  // Then check to ensure the Reflex dictionary is defined
284  // for this value_type.
285  // I do not throw an exception here if the check fails
286  // because there are known cases where the dictionary does
287  // not exist and we do not need to support those cases.
288  Reflex::Type valueType;
289  if((is_RefVector(type, valueType) ||
290  is_PtrVector(type, valueType) ||
291  is_RefToBaseVector(type, valueType) ||
292  value_type_of(type, valueType))
293  && bool(valueType)) {
294 
295  fillLookup(valueType, index, pBD, tempElementLookupMap);
296 
297  // Repeat this for all public base classes of the value_type
298  std::vector<Reflex::Type> baseTypes;
299  public_base_classes(valueType, baseTypes);
300 
301  for(std::vector<Reflex::Type>::iterator iter = baseTypes.begin(),
302  iend = baseTypes.end();
303  iter != iend;
304  ++iter) {
305  fillLookup(*iter, index, pBD, tempElementLookupMap);
306  }
307  }
308  }
309  }
310  }
311  missingDictionaries().reserve(missingDicts.size());
312  copy_all(missingDicts, std::back_inserter(missingDictionaries()));
313  productLookup().fillFrom(tempProductLookupMap);
314  elementLookup().fillFrom(tempElementLookupMap);
315  savedMissingTypes.swap(missingTypes());
316  savedFoundTypes.swap(foundTypes());
317  }
type
Definition: HCALResponse.h:22
int i
Definition: DBlmapReader.cc:9
bool is_RefToBaseVector(Reflex::Type const &possible_ref_vector, Reflex::Type &value_type)
Definition: ReflexTools.cc:86
void setProductProduced(BranchType branchType) const
ConstProductList & constProductList() const
bool is_PtrVector(Reflex::Type const &possible_ref_vector, Reflex::Type &value_type)
Definition: ReflexTools.cc:69
bool value_type_of(Reflex::Type const &t, Reflex::Type &found_type)
Definition: ReflexTools.h:31
void public_base_classes(Reflex::Type const &type, std::vector< Reflex::Type > &baseTypes)
TransientProductLookupMap & elementLookup() const
std::vector< std::string > & missingDictionaries() const
StringSet & missingTypes()
Definition: ReflexTools.cc:189
std::set< std::string > StringSet
Definition: ReflexTools.h:22
StringSet & foundTypes()
Definition: ReflexTools.cc:193
static void fillLookup(Reflex::Type const &type, ProductTransientIndex const &index, ConstBranchDescription const *branchDesc, TransientProductLookupMap::FillFromMap &oMap)
TransientProductLookupMap & productLookup() const
std::string wrappedClassName(std::string const &iFullName)
bool is_RefVector(Reflex::Type const &possible_ref_vector, Reflex::Type &value_type)
Definition: ReflexTools.cc:56
Func copy_all(ForwardSequence &s, Func f)
wrappers for copy
Definition: Algorithms.h:24
std::map< std::pair< TypeInBranchType, ConstBranchDescription const * >, ProductTransientIndex, CompareTypeInBranchTypeConstBranchDescription > FillFromMap
std::map< BranchID, ProductTransientIndex > branchIDToIndex_
void edm::ProductRegistry::initializeTransients ( ) const
inline
std::string edm::ProductRegistry::merge ( ProductRegistry const &  other,
std::string const &  fileName,
BranchDescription::MatchMode  parametersMustMatch = BranchDescription::Permissive,
BranchDescription::MatchMode  branchesMustMatch = BranchDescription::Permissive 
)

Definition at line 185 of file ProductRegistry.cc.

References alignCSCRings::e, i, initializeLookupTables(), j, edm::match(), edm::BranchDescription::Permissive, productList(), productList_, alignCSCRings::s, and edm::BranchDescription::Strict.

Referenced by edm::StreamerInputSource::mergeIntoRegistry(), edm::RootInputFileSequence::nextFile(), and edm::RootInputFileSequence::previousFile().

188  {
189  std::ostringstream differences;
190 
191  ProductRegistry::ProductList::iterator j = productList_.begin();
192  ProductRegistry::ProductList::iterator s = productList_.end();
193  ProductRegistry::ProductList::const_iterator i = other.productList().begin();
194  ProductRegistry::ProductList::const_iterator e = other.productList().end();
195 
196  // Loop over entries in the main product registry.
197  while(j != s || i != e) {
198  if(j != s && j->second.produced()) {
199  // Ignore branches just produced (i.e. not in input file).
200  ++j;
201  } else if(j == s || (i != e && i->first < j->first)) {
202  if(i->second.present()) {
203  differences << "Branch '" << i->second.branchName() << "' is in file '" << fileName << "'\n";
204  differences << " but not in previous files.\n";
205  } else {
206  productList_.insert(*i);
207  }
208  ++i;
209  } else if(i == e || (j != s && j->first < i->first)) {
210  if(j->second.present() && branchesMustMatch == BranchDescription::Strict) {
211  differences << "Branch '" << j->second.branchName() << "' is in previous files\n";
212  differences << " but not in file '" << fileName << "'.\n";
213  }
214  ++j;
215  } else {
216  std::string difs = match(j->second, i->second, fileName, parametersMustMatch);
217  if(difs.empty()) {
218  if(parametersMustMatch == BranchDescription::Permissive) j->second.merge(i->second);
219  } else {
220  differences << difs;
221  }
222  ++i;
223  ++j;
224  }
225  }
227  return differences.str();
228  }
int i
Definition: DBlmapReader.cc:9
std::string match(BranchDescription const &a, BranchDescription const &b, std::string const &fileName, BranchDescription::MatchMode m)
int j
Definition: DBlmapReader.cc:9
void initializeLookupTables() const
std::vector<std::string>& edm::ProductRegistry::missingDictionaries ( ) const
inline

Definition at line 131 of file ProductRegistry.h.

References edm::ProductRegistry::Transients::missingDictionaries_, and transient_.

Referenced by initializeLookupTables().

131  {
133  }
std::vector< std::string > missingDictionaries_
void edm::ProductRegistry::print ( std::ostream &  os) const

Definition at line 327 of file ProductRegistry.cc.

References alignCSCRings::e, i, and productList_.

Referenced by edm::operator<<().

327  {
328  for(ProductList::const_iterator i = productList_.begin(), e = productList_.end(); i != e; ++i) {
329  os << i->second << "\n-----\n";
330  }
331  }
int i
Definition: DBlmapReader.cc:9
BranchListIndex edm::ProductRegistry::producedBranchListIndex ( ) const
inline
ProductList const& edm::ProductRegistry::productList ( ) const
inline
ProductList& edm::ProductRegistry::productListUpdator ( )
inline

Definition at line 76 of file ProductRegistry.h.

References productList_, and throwIfFrozen().

Referenced by edm::RootFile::dropOnInput(), edm::PoolSource::PoolSource(), and edm::RootFile::RootFile().

76  {
77  throwIfFrozen();
78  return productList_;
79  }
void throwIfFrozen() const
TransientProductLookupMap& edm::ProductRegistry::productLookup ( ) const
inline

Definition at line 115 of file ProductRegistry.h.

References edm::ProductRegistry::Transients::productLookup_, and transient_.

Referenced by initializeLookupTables().

115 {return transient_.productLookup_;}
TransientProductLookupMap productLookup_
bool edm::ProductRegistry::productProduced ( BranchType  branchType) const
inline
void edm::ProductRegistry::setFrozen ( bool  initializeLookupInfo = true) const

Definition at line 115 of file ProductRegistry.cc.

References frozen(), and initializeLookupTables().

Referenced by edm::Schedule::Schedule().

115  {
116  if(frozen()) return;
117  frozen() = true;
118  if(initializeLookupInfo) {
120  }
121  }
void initializeLookupTables() const
bool & frozen() const
void edm::ProductRegistry::setProducedBranchListIndex ( BranchListIndex  blix) const
inline
void edm::ProductRegistry::setProductProduced ( BranchType  branchType) const
inlineprivate
ProductList::size_type edm::ProductRegistry::size ( void  ) const
inline

Definition at line 104 of file ProductRegistry.h.

References productList_.

Referenced by allBranchDescriptions(), and allBranchNames().

104 {return productList_.size();}
void edm::ProductRegistry::throwIfFrozen ( ) const
private

Definition at line 124 of file ProductRegistry.cc.

References edm::hlt::Exception, and frozen().

Referenced by addProduct(), copyProduct(), and productListUpdator().

124  {
125  if(frozen()) {
126  throw cms::Exception("ProductRegistry", "throwIfFrozen")
127  << "cannot modify the ProductRegistry because it is frozen\n";
128  }
129  }
bool & frozen() const
void edm::ProductRegistry::throwIfNotFrozen ( ) const
private

Definition at line 132 of file ProductRegistry.cc.

References edm::hlt::Exception, and frozen().

Referenced by anyProducts().

132  {
133  if(!frozen()) {
134  throw cms::Exception("ProductRegistry", "throwIfNotFrozen")
135  << "cannot read the ProductRegistry because it is not yet frozen\n";
136  }
137  }
bool & frozen() const
void edm::ProductRegistry::updateFromInput ( ProductList const &  other)

Definition at line 169 of file ProductRegistry.cc.

References copyProduct().

Referenced by edm::StreamerInputSource::mergeIntoRegistry(), and edm::RootInputFileSequence::RootInputFileSequence().

169  {
170  for(ProductList::const_iterator it = other.begin(), itEnd = other.end();
171  it != itEnd; ++it) {
172  copyProduct(it->second);
173  }
174  }
void copyProduct(BranchDescription const &productdesc)
void edm::ProductRegistry::updateFromInput ( std::vector< BranchDescription > const &  other)

Definition at line 177 of file ProductRegistry.cc.

References copyProduct().

177  {
178  for(std::vector<BranchDescription>::const_iterator it = other.begin(), itEnd = other.end();
179  it != itEnd; ++it) {
180  copyProduct(*it);
181  }
182  }
void copyProduct(BranchDescription const &productdesc)

Member Data Documentation

ProductTransientIndex const edm::ProductRegistry::kInvalidIndex = 0xFFFFFFFF
static
ProductList edm::ProductRegistry::productList_
private
Transients edm::ProductRegistry::transient_
mutableprivate