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 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 (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 34 of file ProductRegistry.cc.

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

Definition at line 65 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 140 of file ProductRegistry.cc.

Referenced by addProduct().

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

Definition at line 72 of file ProductRegistry.cc.

References addCalled(), edm::errors::Configuration, Exception, edm::BranchDescription::processName(), edm::BranchDescription::produced(), productList_, runTheMatrix::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 157 of file ProductRegistry.cc.

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

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

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

    ProductList::const_iterator it = productList().begin();
    ProductList::const_iterator end = productList().end();

    for(; it != end; ++it) result.push_back(&(it->second));
    return result;
  }
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().

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

    ProductList::const_iterator it = productList().begin();
    ProductList::const_iterator end = productList().end();

    for(; it != end; ++it) result.push_back(it->second.branchName());

    return result;
  }
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().

                                                      {
    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 95 of file ProductRegistry.h.

References productList_.

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

                                            {
      //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 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().

                                                                   {
    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 319 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 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().

                                                     {
    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(ProductList::const_iterator i = productList_.begin(), e = productList_.end(); i != e; ++i, ++index) {
      if(i->second.produced()) {
        setProductProduced(i->second.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(i->first, ConstBranchDescription(i->second))).first->second);

      transient_.branchIDToIndex_[i->second.branchID()] = index;

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

      //only do the following if the data is supposed to be available in the event
      if(i->second.present()) {
        Reflex::Type type(Reflex::Type::ByName(i->second.className()));
        Reflex::Type wrappedType(Reflex::Type::ByName(wrappedClassName(i->second.className())));
        if(!bool(type) || !bool(wrappedType)) {
          missingDicts.insert(i->second.className());
          continue;
        }
        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 Reflex::Type for it.
          // Then check to ensure the Reflex 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.
          Reflex::Type 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<Reflex::Type> baseTypes;
            public_base_classes(valueType, baseTypes);

            for(std::vector<Reflex::Type>::iterator iter = baseTypes.begin(),
                iend = baseTypes.end();
                iter != iend;
                ++iter) {
              fillLookup(*iter, index, pBD, tempElementLookupMap);
            }
          }
        }
      }
    }
    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 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().

                                                      {
    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 327 of file ProductRegistry.cc.

References alignCSCRings::e, i, and productList_.

Referenced by edm::operator<<().

                                                  {
    for(ProductList::const_iterator i = productList_.begin(), e = productList_.end(); i != e; ++i) {
      os << i->second << "\n-----\n";
    }
  }
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::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 115 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 104 of file ProductRegistry.h.

References productList_.

Referenced by allBranchDescriptions(), and allBranchNames().

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

Definition at line 124 of file ProductRegistry.cc.

References Exception, and frozen().

Referenced by 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 132 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 177 of file ProductRegistry.cc.

References copyProduct().

                                                                            {
    for(std::vector<BranchDescription>::const_iterator it = other.begin(), itEnd = other.end();
        it != itEnd; ++it) {
      copyProduct(*it);
    }
  }
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().

                                                           {
    for(ProductList::const_iterator it = other.begin(), itEnd = other.end();
        it != itEnd; ++it) {
      copyProduct(it->second);
    }
  }

Member Data Documentation