All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Protected Attributes | List of all members
recob::HitAndAssociationsWriterManager< Writer > Class Template Reference

A helper to centralise creation of a hit collection data product. More...

#include <HitCreator.h>

Public Types

using Writer_t = Writer
 Type of managed hit collection writer. More...
 

Public Member Functions

 HitAndAssociationsWriterManager ()=default
 Constructor: does not declare anything. More...
 
 HitAndAssociationsWriterManager (art::ProducesCollector &collector, std::string instanceName="", bool doWireAssns=true, bool doRawDigitAssns=true)
 Declares the hit products we are going to fill. More...
 
void declareProducts (art::ProducesCollector &collector, std::string instanceName="", bool doWireAssns=true, bool doRawDigitAssns=true)
 Declares the hit products we are going to fill. More...
 
Writer_t collectionWriter (art::Event &event) const
 Returns a new writer already configured. More...
 
std::string instanceName () const
 Returns the configured product instance name. More...
 
bool ready () const noexcept
 Returns whether the class is fully configured. More...
 

Protected Attributes

art::ProducesCollector * collector_p = nullptr
 Collector this manager is bound to. More...
 
std::string prodInstance
 Tame of the instance for data products. More...
 
bool hasRawDigitAssns = true
 Whether we produce hit-digit associations. More...
 
bool hasWireAssns = true
 Whether we produce hit-wire associations. More...
 

Detailed Description

template<typename Writer>
class recob::HitAndAssociationsWriterManager< Writer >

A helper to centralise creation of a hit collection data product.

Template Parameters
Writerwriter class to manage
ModuleTypeowning module: art::EDProducer or art::EDFilter

This class adds an indirection layer to the model relying on HitAndAssociationsWriter. In that one, two different steps are required, one in the constructor of the module, where data products are declared, and one in the place where hits are actually assembled. These two steps need consistent setup, but they are separate and formally independent. The "manager" approach consists of an object performing the first step directly, and delivering an already configured object for the second step.

An example of usage in a module:

class MyHitProducer: public art::EDProducer {
hitCollCreator;
public:
MyHitProducer(fhicl::ParameterSet const& pset)
: EDProducer{pset}
, hitCollCreator(*this, pset.get<std::string>("instanceName", ""))
{}
void produce(art::Event& event)
{
auto hitCollWriter = hitCollCreator.collectionWriter(event);
for (recob::Wire const& wire: Wires) {
// create hits...
hitCollWriter.emplace_back(hit, wire, digit);
}
hitCollWriter.put_into();
}
}; // class MyHitProducer

Definition at line 977 of file HitCreator.h.

Member Typedef Documentation

template<typename Writer>
using recob::HitAndAssociationsWriterManager< Writer >::Writer_t = Writer

Type of managed hit collection writer.

Definition at line 980 of file HitCreator.h.

Constructor & Destructor Documentation

template<typename Writer>
recob::HitAndAssociationsWriterManager< Writer >::HitAndAssociationsWriterManager ( )
default

Constructor: does not declare anything.

This constructor does not declare products. Calling declare_products() explicitly is then required in the module constructor.

template<typename Writer >
recob::HitAndAssociationsWriterManager< Writer >::HitAndAssociationsWriterManager ( art::ProducesCollector &  collector,
std::string  instanceName = "",
bool  doWireAssns = true,
bool  doRawDigitAssns = true 
)

Declares the hit products we are going to fill.

Parameters
collectorthe module this manager is bound to
instanceNamename of the instance for all data products
doWireAssnswhether to enable associations to wires
doRawDigitAssnswhether to enable associations to raw digits

This constructor calls declareProducts().

Definition at line 1069 of file HitCreator.h.

1073 {
1075  (collector, instanceName, doWireAssns, doRawDigitAssns);
1076 } // recob::HitAndAssociationsWriterManager::HitAndAssociationsWriterManager()
void declareProducts(art::ProducesCollector &collector, std::string instanceName="", bool doWireAssns=true, bool doRawDigitAssns=true)
Declares the hit products we are going to fill.
Definition: HitCreator.h:1082
std::string instanceName() const
Returns the configured product instance name.
Definition: HitCreator.h:1033

Member Function Documentation

template<typename Writer >
recob::HitAndAssociationsWriterManager< Writer >::Writer_t recob::HitAndAssociationsWriterManager< Writer >::collectionWriter ( art::Event &  event) const

Returns a new writer already configured.

Definition at line 1106 of file HitCreator.h.

1107 {
1108  if (!collector_p) {
1109  // this means you forgot to code a call to declaredProducts()
1110  // or used the wrong constructor:
1111  throw art::Exception(art::errors::LogicError)
1112  << "HitAndAssociationsWriter<>::collectionWriter() called"
1113  " before products are declared.";
1114  }
1115  return
1117 } // recob::HitAndAssociationsWriterManager::collectionWriter()
bool hasWireAssns
Whether we produce hit-wire associations.
Definition: HitCreator.h:1047
art::ProducesCollector * collector_p
Collector this manager is bound to.
Definition: HitCreator.h:1039
bool hasRawDigitAssns
Whether we produce hit-digit associations.
Definition: HitCreator.h:1044
std::string prodInstance
Tame of the instance for data products.
Definition: HitCreator.h:1041
template<typename Writer >
void recob::HitAndAssociationsWriterManager< Writer >::declareProducts ( art::ProducesCollector &  collector,
std::string  instanceName = "",
bool  doWireAssns = true,
bool  doRawDigitAssns = true 
)

Declares the hit products we are going to fill.

Parameters
collectorthe module this manager is bound to
instanceNamename of the instance for all data products
doWireAssnswhether to enable associations to wires
doRawDigitAssnswhether to enable associations to raw digits

This declaration must be made in the constructor of producer. It is equivalent to manually declare the relevant among these products:

produces<std::vector<recob::Hit>>(prod_instance);
produces<art::Assns<recob::Wire, recob::Hit>>(prod_instance);
produces<art::Assns<raw::RawDigit, recob::Hit>>(prod_instance);

in the producer constructor. All the data products (hit collection and associations) will have the specified product instance name.

Definition at line 1082 of file HitCreator.h.

1086 {
1087  if (collector_p) {
1088  // this means you already called to declaredProducts()
1089  // or used the wrong constructor (which did that for you):
1090  throw art::Exception(art::errors::LogicError)
1091  << "HitAndAssociationsWriter<> has already declared its products.";
1092  }
1093  collector_p = &collector;
1095  hasWireAssns = doWireAssns;
1096  hasRawDigitAssns = doRawDigitAssns;
1099 } // recob::HitAndAssociationsWriterManager::declareProducts()
static void declare_products(art::ProducesCollector &collector, std::string instance_name="", bool doWireAssns=true, bool doRawDigitAssns=true)
Declares the hit products we are going to fill.
Definition: HitCreator.cxx:248
bool hasWireAssns
Whether we produce hit-wire associations.
Definition: HitCreator.h:1047
art::ProducesCollector * collector_p
Collector this manager is bound to.
Definition: HitCreator.h:1039
bool hasRawDigitAssns
Whether we produce hit-digit associations.
Definition: HitCreator.h:1044
std::string prodInstance
Tame of the instance for data products.
Definition: HitCreator.h:1041
std::string instanceName() const
Returns the configured product instance name.
Definition: HitCreator.h:1033
template<typename Writer>
std::string recob::HitAndAssociationsWriterManager< Writer >::instanceName ( ) const
inline

Returns the configured product instance name.

Definition at line 1033 of file HitCreator.h.

1033 { return prodInstance; }
std::string prodInstance
Tame of the instance for data products.
Definition: HitCreator.h:1041
template<typename Writer>
bool recob::HitAndAssociationsWriterManager< Writer >::ready ( ) const
inlinenoexcept

Returns whether the class is fully configured.

Definition at line 1036 of file HitCreator.h.

1036 { return collector_p != nullptr; }
art::ProducesCollector * collector_p
Collector this manager is bound to.
Definition: HitCreator.h:1039

Member Data Documentation

template<typename Writer>
art::ProducesCollector* recob::HitAndAssociationsWriterManager< Writer >::collector_p = nullptr
protected

Collector this manager is bound to.

Definition at line 1039 of file HitCreator.h.

template<typename Writer>
bool recob::HitAndAssociationsWriterManager< Writer >::hasRawDigitAssns = true
protected

Whether we produce hit-digit associations.

Definition at line 1044 of file HitCreator.h.

template<typename Writer>
bool recob::HitAndAssociationsWriterManager< Writer >::hasWireAssns = true
protected

Whether we produce hit-wire associations.

Definition at line 1047 of file HitCreator.h.

template<typename Writer>
std::string recob::HitAndAssociationsWriterManager< Writer >::prodInstance
protected

Tame of the instance for data products.

Definition at line 1041 of file HitCreator.h.


The documentation for this class was generated from the following file: