CMS 3D CMS Logo

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

//fill the collection
...
event.put(std::make_unique<AppleCollection>());
//fill the collection
...
event.put(std::make_unique<FruitCollection>());

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)

auto pApples = std::make_unique<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
....
}