LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
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::ProducesCollectorcollector_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 917 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 920 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 1004 of file HitCreator.h.

1010 {
1011  declareProducts(collector, instanceName, doWireAssns, doRawDigitAssns);
1012 } // 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:1016
std::string instanceName() const
Returns the configured product instance name.
Definition: HitCreator.h:972

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 1040 of file HitCreator.h.

References art::errors::LogicError.

1041 {
1042  if (!collector_p) {
1043  // this means you forgot to code a call to declaredProducts()
1044  // or used the wrong constructor:
1046  << "HitAndAssociationsWriter<>::collectionWriter() called"
1047  " before products are declared.";
1048  }
1049  return {event, prodInstance, hasWireAssns, hasRawDigitAssns};
1050 } // recob::HitAndAssociationsWriterManager::collectionWriter()
bool hasWireAssns
Whether we produce hit-wire associations.
Definition: HitCreator.h:986
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
art::ProducesCollector * collector_p
Collector this manager is bound to.
Definition: HitCreator.h:978
bool hasRawDigitAssns
Whether we produce hit-digit associations.
Definition: HitCreator.h:983
std::string prodInstance
Tame of the instance for data products.
Definition: HitCreator.h:980
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 1016 of file HitCreator.h.

References art::errors::LogicError.

1022 {
1023  if (collector_p) {
1024  // this means you already called to declaredProducts()
1025  // or used the wrong constructor (which did that for you):
1027  << "HitAndAssociationsWriter<> has already declared its products.";
1028  }
1029  collector_p = &collector;
1031  hasWireAssns = doWireAssns;
1032  hasRawDigitAssns = doRawDigitAssns;
1035 } // 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:986
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
art::ProducesCollector * collector_p
Collector this manager is bound to.
Definition: HitCreator.h:978
bool hasRawDigitAssns
Whether we produce hit-digit associations.
Definition: HitCreator.h:983
std::string prodInstance
Tame of the instance for data products.
Definition: HitCreator.h:980
std::string instanceName() const
Returns the configured product instance name.
Definition: HitCreator.h:972
template<typename Writer>
std::string recob::HitAndAssociationsWriterManager< Writer >::instanceName ( ) const
inline

Returns the configured product instance name.

Definition at line 972 of file HitCreator.h.

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

Returns whether the class is fully configured.

Definition at line 975 of file HitCreator.h.

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

Member Data Documentation

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

Collector this manager is bound to.

Definition at line 978 of file HitCreator.h.

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

Whether we produce hit-digit associations.

Definition at line 983 of file HitCreator.h.

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

Whether we produce hit-wire associations.

Definition at line 986 of file HitCreator.h.

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

Tame of the instance for data products.

Definition at line 980 of file HitCreator.h.


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