CMS 3D CMS Logo

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

List of all members.

Classes

struct  Transients

Public Types

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

Public Member Functions

void addLabelAlias (BranchDescription const &productdesc, std::string const &labelAlias, std::string const &instanceAlias)
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 (ProductList const &productList, bool toBeFrozen=true)
 ProductRegistry ()
void setFrozen (bool initializeLookupInfo=true) const
void setProducedBranchListIndex (BranchListIndex blix) const
ProductList::size_type size () const
void updateFromInput (std::vector< BranchDescription > const &other)
void updateFromInput (ProductList 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 36 of file ProductRegistry.cc.

edm::ProductRegistry::ProductRegistry ( ProductList const &  productList,
bool  toBeFrozen = true 
) [explicit]

Definition at line 67 of file ProductRegistry.cc.

References frozen().

                                                                                  :
      productList_(productList),
      transient_() {
    frozen() = toBeFrozen;
  }
virtual edm::ProductRegistry::~ProductRegistry ( ) [inline, virtual]

Definition at line 52 of file ProductRegistry.h.

{}

Member Function Documentation

void edm::ProductRegistry::addCalled ( BranchDescription const &  ,
bool  iFromListener 
) [private, virtual]

Reimplemented in edm::SignallingProductRegistry.

Definition at line 156 of file ProductRegistry.cc.

Referenced by addLabelAlias(), and addProduct().

                                                           {
  }
void edm::ProductRegistry::addLabelAlias ( BranchDescription const &  productdesc,
std::string const &  labelAlias,
std::string const &  instanceAlias 
)

Definition at line 90 of file ProductRegistry.cc.

References addCalled(), edm::BranchDescription::branchID(), edm::BranchID::isValid(), edm::BranchDescription::produced(), productList_, run_regression::ret, and throwIfFrozen().

                                                                 {
    assert(productDesc.produced());
    assert(productDesc.branchID().isValid());
    throwIfFrozen();
    BranchDescription bd(productDesc, labelAlias, instanceAlias);
    std::pair<ProductList::iterator, bool> ret =
         productList_.insert(std::make_pair(BranchKey(bd), bd));
    assert(ret.second);
    addCalled(bd, false);
  }
void edm::ProductRegistry::addProduct ( BranchDescription const &  productdesc,
bool  iFromListener = false 
)

Definition at line 74 of file ProductRegistry.cc.

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

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

                                                 {
    assert(productDesc.produced());
    throwIfFrozen();
    checkDicts(productDesc);
    std::pair<ProductList::iterator, bool> ret =
         productList_.insert(std::make_pair(BranchKey(productDesc), productDesc));
    if(!ret.second) {
      throw Exception(errors::Configuration, "Duplicate Process")
        << "The process name " << productDesc.processName() << " was previously used on these products.\n"
        << "Please modify the configuration file to use a distinct process name.\n";
    }
    addCalled(productDesc, fromListener);
  }
std::vector< BranchDescription const * > edm::ProductRegistry::allBranchDescriptions ( ) const

Definition at line 171 of file ProductRegistry.cc.

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

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

                                               {
    std::vector<BranchDescription const*> result;
    result.reserve(productList().size());

    for(auto const& product : productList()) {
      result.push_back(&product.second);
    }
    return result;
  }
std::vector< std::string > edm::ProductRegistry::allBranchNames ( ) const

Definition at line 160 of file ProductRegistry.cc.

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

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

                                        {
    std::vector<std::string> result;
    result.reserve(productList().size());

    for(auto const& product : productList()) {
      result.push_back(product.second.branchName());
    }
    return result;
  }
bool edm::ProductRegistry::anyProductProduced ( ) const [inline]
bool edm::ProductRegistry::anyProducts ( BranchType const  brType) const

Definition at line 119 of file ProductRegistry.cc.

References productList_, and throwIfNotFrozen().

                                                      {
    throwIfNotFrozen();
    for(ProductList::const_iterator it = productList_.begin(), itEnd = productList_.end();
        it != itEnd; ++it) {
      if(it->second.branchType() == brType) {
        return true;
      }
    }
    return false;
  }
template<typename T >
void edm::ProductRegistry::callForEachBranch ( T const &  iFunc) [inline]

Definition at line 97 of file ProductRegistry.h.

References productList_.

Referenced by edm::ProducerBase::registerProducts(), and edm::EDAnalyzer::registerProductsAndCallbacks().

                                            {
      //NOTE: If implementation changes from a map, need to check that iterators are still valid
      // after an insert with the new container, else need to copy the container and iterate over the copy
      for(ProductRegistry::ProductList::const_iterator itEntry = productList_.begin(),
          itEntryEnd = productList_.end();
          itEntry != itEntryEnd; ++itEntry) {
        iFunc(itEntry->second);
      }
    }
ConstProductList& edm::ProductRegistry::constProductList ( ) const [inline]
void edm::ProductRegistry::copyProduct ( BranchDescription const &  productdesc)

Definition at line 104 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().

                                                                   {
    assert(!productDesc.produced());
    throwIfFrozen();
    productDesc.init();
    BranchKey k = BranchKey(productDesc);
    ProductList::iterator iter = productList_.find(k);
    if(iter == productList_.end()) {
      productList_.insert(std::make_pair(k, productDesc));
    } else {
      assert(combinable(iter->second, productDesc));
      iter->second.merge(productDesc);
    }
  }
TransientProductLookupMap& edm::ProductRegistry::elementLookup ( ) const [inline]
bool& edm::ProductRegistry::frozen ( ) const [inline, private]
ProductTransientIndex edm::ProductRegistry::indexFrom ( BranchID const &  iID) const

Definition at line 330 of file ProductRegistry.cc.

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

                                                                            {
    std::map<BranchID, ProductTransientIndex>::iterator itFind = transient_.branchIDToIndex_.find(iID);
    if(itFind == transient_.branchIDToIndex_.end()) {
      return kInvalidIndex;
    }
    return itFind->second;
  }
void edm::ProductRegistry::initializeLookupTables ( ) const [private]

Definition at line 251 of file ProductRegistry.cc.

References edm::ProductRegistry::Transients::branchIDToIndex_, edm::TypeWithDict::byName(), constProductList(), edm::copy_all(), elementLookup(), edm::TransientProductLookupMap::fillFrom(), edm::fillLookup(), edm::foundTypes(), getHLTprescales::index, edm::is_PtrVector(), edm::is_RefToBaseVector(), edm::is_RefVector(), combine::key, 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().

                                                     {
    StringSet savedMissingTypes;
    savedMissingTypes.swap(missingTypes());
    StringSet savedFoundTypes;
    savedFoundTypes.swap(foundTypes());
    constProductList().clear();
    transient_.branchIDToIndex_.clear();
    ProductTransientIndex index = 0;

    //NOTE it might be possible to remove the need for this temporary map because the productList is ordered by the
    // BranchKey and for the same C++ class type the BranchKey will sort just like CompareTypeInBranchTypeConstBranchDescription
    typedef TransientProductLookupMap::FillFromMap TempLookupMap;
    TempLookupMap tempProductLookupMap;
    TempLookupMap tempElementLookupMap;

    StringSet usedProcessNames;
    StringSet missingDicts;
    for(auto const& product : productList_) {
      auto const& key = product.first;
      auto const& desc = product.second;
      if(desc.produced()) {
        setProductProduced(desc.branchType());
      }

      //insert returns a pair<iterator, bool> and we want the address of the ConstBranchDescription that was created in the map
      // this is safe since items in a map always retain their memory address
      ConstBranchDescription const* pBD = &(constProductList().insert(std::make_pair(key, ConstBranchDescription(desc))).first->second);

      transient_.branchIDToIndex_[desc.branchID()] = index;

      usedProcessNames.insert(pBD->processName());

      //only do the following if the data is supposed to be available in the event
      if(desc.present()) {
        TypeWithDict type(TypeWithDict::byName(desc.className()));
        TypeWithDict wrappedType(TypeWithDict::byName(wrappedClassName(desc.className())));
        if(!bool(type) || !bool(wrappedType)) {
          missingDicts.insert(desc.className());
        } else {
          fillLookup(type, index, pBD, tempProductLookupMap);
  
          if(bool(type)) {
            // Here we look in the object named "type" for a typedef
            // named "value_type" and get the type for it.
            // Then check to ensure the dictionary is defined
            // for this value_type.
            // I do not throw an exception here if the check fails
            // because there are known cases where the dictionary does
            // not exist and we do not need to support those cases.
            TypeWithDict valueType;
            if((is_RefVector(type, valueType) ||
                is_PtrVector(type, valueType) ||
                is_RefToBaseVector(type, valueType) ||
                value_type_of(type, valueType))
                && bool(valueType)) {
  
              fillLookup(valueType, index, pBD, tempElementLookupMap);
  
              // Repeat this for all public base classes of the value_type
              std::vector<TypeWithDict> baseTypes;
              public_base_classes(valueType, baseTypes);
  
              for(TypeWithDict const& baseType : baseTypes) {
                fillLookup(baseType, index, pBD, tempElementLookupMap);
              }
            }
          }
        }
      }
      ++index;
    }
    missingDictionaries().reserve(missingDicts.size());
    copy_all(missingDicts, std::back_inserter(missingDictionaries()));
    productLookup().fillFrom(tempProductLookupMap);
    elementLookup().fillFrom(tempElementLookupMap);
    savedMissingTypes.swap(missingTypes());
    savedFoundTypes.swap(foundTypes());
  }
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 196 of file ProductRegistry.cc.

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

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

                                                      {
    std::ostringstream differences;

    ProductRegistry::ProductList::iterator j = productList_.begin();
    ProductRegistry::ProductList::iterator s = productList_.end();
    ProductRegistry::ProductList::const_iterator i = other.productList().begin();
    ProductRegistry::ProductList::const_iterator e = other.productList().end();

    // Loop over entries in the main product registry.
    while(j != s || i != e) {
      if(j != s && j->second.produced()) {
        // Ignore branches just produced (i.e. not in input file).
        ++j;
      } else if(j == s || (i != e && i->first < j->first)) {
        if(i->second.present()) {
          differences << "Branch '" << i->second.branchName() << "' is in file '" << fileName << "'\n";
          differences << "    but not in previous files.\n";
        } else {
          productList_.insert(*i);
        }
        ++i;
      } else if(i == e || (j != s && j->first < i->first)) {
        if(j->second.present() && branchesMustMatch == BranchDescription::Strict) {
          differences << "Branch '" << j->second.branchName() << "' is in previous files\n";
          differences << "    but not in file '" << fileName << "'.\n";
        }
        ++j;
      } else {
        std::string difs = match(j->second, i->second, fileName, parametersMustMatch);
        if(difs.empty()) {
          if(parametersMustMatch == BranchDescription::Permissive) j->second.merge(i->second);
        } else {
          differences << difs;
        }
        ++i;
        ++j;
      }
    }
    initializeLookupTables();
    return differences.str();
  }
std::vector<std::string>& edm::ProductRegistry::missingDictionaries ( ) const [inline]
void edm::ProductRegistry::print ( std::ostream &  os) const

Definition at line 338 of file ProductRegistry.cc.

References productList_.

Referenced by edm::operator<<().

                                                  {
    for(auto const& product: productList_) {
      os << product.second << "\n-----\n";
    }
  }
BranchListIndex edm::ProductRegistry::producedBranchListIndex ( ) const [inline]
ProductList const& edm::ProductRegistry::productList ( ) const [inline]
ProductList& edm::ProductRegistry::productListUpdator ( ) [inline]

Definition at line 78 of file ProductRegistry.h.

References productList_, and throwIfFrozen().

Referenced by edm::RootFile::RootFile().

                                      {
      throwIfFrozen();
      return productList_;
    }
TransientProductLookupMap& edm::ProductRegistry::productLookup ( ) const [inline]
bool edm::ProductRegistry::productProduced ( BranchType  branchType) const [inline]
void edm::ProductRegistry::setFrozen ( bool  initializeLookupInfo = true) const

Definition at line 131 of file ProductRegistry.cc.

References frozen(), and initializeLookupTables().

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

                                                            {
    if(frozen()) return;
    frozen() = true;
    if(initializeLookupInfo) {
      initializeLookupTables();
    }
  }
void edm::ProductRegistry::setProducedBranchListIndex ( BranchListIndex  blix) const [inline]
void edm::ProductRegistry::setProductProduced ( BranchType  branchType) const [inline, private]
ProductList::size_type edm::ProductRegistry::size ( void  ) const [inline]

Definition at line 106 of file ProductRegistry.h.

References productList_.

Referenced by allBranchDescriptions(), and allBranchNames().

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

Definition at line 140 of file ProductRegistry.cc.

References Exception, and frozen().

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

                                       {
    if(frozen()) {
      throw cms::Exception("ProductRegistry", "throwIfFrozen")
        << "cannot modify the ProductRegistry because it is frozen\n";
    }
  }
void edm::ProductRegistry::throwIfNotFrozen ( ) const [private]

Definition at line 148 of file ProductRegistry.cc.

References Exception, and frozen().

Referenced by anyProducts().

                                          {
    if(!frozen()) {
      throw cms::Exception("ProductRegistry", "throwIfNotFrozen")
        << "cannot read the ProductRegistry because it is not yet frozen\n";
    }
  }
void edm::ProductRegistry::updateFromInput ( std::vector< BranchDescription > const &  other)

Definition at line 189 of file ProductRegistry.cc.

References copyProduct().

                                                                            {
    for(BranchDescription const& branchDescription : other) {
      copyProduct(branchDescription);
    }
  }
void edm::ProductRegistry::updateFromInput ( ProductList const &  other)

Definition at line 182 of file ProductRegistry.cc.

References copyProduct().

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

                                                           {
    for(auto const& product : other) {
      copyProduct(product.second);
    }
  }

Member Data Documentation