CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PrincipalGetAdapter Class Reference

#include <FWCore/Framework/interface/PrincipalGetAdapter.h>

Detailed Description

Description: This is the implementation for accessing EDProducts and inserting new EDProducts.

Usage:

Getting Data

The edm::PrincipalGetAdapter class provides many 'get*" methods for getting data it contains.

The primary method for getting data is to use getByLabel(). The labels are the label of the module assigned in the configuration file and the 'product instance label' (which can be omitted in the case the 'product instance label' is the default value). The C++ type of the product plus the two labels uniquely identify a product in the PrincipalGetAdapter.

We use an event in the examples, but a run or a luminosity block can also hold products.

event.getByLabel("tree",apples);
event.getByLabel("market", "apple", fruits);

Putting Data

std::unique_ptr<AppleCollection> pApples(new AppleCollection);
//fill the collection
...
event.put(std::move(pApples));
std::unique_ptr<FruitCollection> pFruits(new FruitCollection);
//fill the collection
...
event.put("apple", std::move(pFruits));

Getting a reference to a product before that product is put into the event/lumiBlock/run. NOTE: The edm::RefProd returned will not work until after the edm::PrincipalGetAdapter has been committed (which happens after the EDProducer::produce method has ended)

std::unique_ptr<AppleCollection> pApples(new AppleCollection);
edm::RefProd<AppleCollection> refApples = event.getRefBeforePut<AppleCollection>();
//do loop and fill collection
for(unsigned int index = 0; .....) {
....
apples->push_back(Apple(...));
//create an edm::Ref to the new object
....
}