Belle II Software development
StoreVectorSwapper.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8#pragma once
9
10#include <tracking/trackFindingCDC/findlets/base/Findlet.h>
11#include <tracking/trackFindingCDC/utilities/StringManipulation.h>
12#include <tracking/trackFindingCDC/rootification/StoreWrappedObjPtr.h>
13
14#include <framework/core/ModuleParamList.h>
15
16#include <vector>
17
18namespace Belle2 {
23 namespace TrackFindingCDC {
24
26
29 template<class IOType, bool a_alwaysWrite = false>
31 public Findlet<IOType> {
32
33 private:
36
37 public:
39 explicit StoreVectorSwapper(const std::string& storeVectorName,
40 const std::string& classMnemomicName = "",
41 const std::string& classMnemomicDescription = "")
42 : m_param_storeVectorName(storeVectorName),
43 m_classMnemomicName(classMnemomicName),
44 m_classMnemomicDescription(classMnemomicDescription)
45 {
47 if (m_classMnemomicName != "") {
49 } else {
50 // Just a little bit of ADL
52 }
53 }
54
55 if (m_classMnemomicName == "") {
56 // Just a little bit of ADL
57 m_classMnemomicName = getClassMnemomicParameterName(static_cast<IOType*>(nullptr));
58 }
59 }
60
62 void exposeParameters(ModuleParamList* moduleParamList, const std::string& prefix) override
63 {
64 std::string classMnemomicCapitalName = m_classMnemomicName;
65 classMnemomicCapitalName[0] = ::toupper(classMnemomicCapitalName.at(0));
66
67 if (not a_alwaysWrite) {
68 moduleParamList->addParameter(prefixed(prefix, "Write" + classMnemomicCapitalName + "s"),
70 "Switch if " + m_classMnemomicDescription +
71 "s shall be written to the DataStore",
73 }
74
75 moduleParamList->addParameter(prefixed(prefix, classMnemomicCapitalName + "sStoreObjName"),
77 "Name of the output StoreObjPtr of the " + m_classMnemomicDescription +
78 "s generated within this module.",
79 std::string(m_param_storeVectorName));
80 //FIXME: Small parameter names
81 }
82
84 std::string getDescription() override
85 {
86 return "Swaps an interal vector of " + m_classMnemomicDescription + "s to the DataStore";
87 }
88
89 public:
91 void initialize() override
92 {
97 }
98 }
99
101 void beginEvent() override
102 {
104
108 if (not storeVector.isValid()) {
109 storeVector.construct();
110 }
111 }
112 m_backup.clear();
113 }
114
116 void apply(std::vector<IOType>& input) final {
117 // Swap items to the DataStore
119 {
121 std::vector<IOType>& sink = *storeVector;
122 sink.swap(input);
123 } else {
124 m_backup.swap(input);
125 }
126 }
127
128 private:
131
133 bool m_param_writeStoreVector = a_alwaysWrite;
134
137
140
142 std::vector<IOType> m_backup;
143 };
144 }
146}
@ c_DontWriteOut
Object/array should be NOT saved by output modules.
Definition: DataStore.h:71
@ c_ErrorIfAlreadyRegistered
If the object/array was already registered, produce an error (aborting initialisation).
Definition: DataStore.h:72
The Module parameter list class.
bool isValid() const
Check whether the object was created.
Definition: StoreObjPtr.h:111
bool construct(Args &&... params)
Construct an object of type T in this StoreObjPtr, using the provided constructor arguments.
Definition: StoreObjPtr.h:119
void initialize() override
Receive and dispatch signal before the start of the event processing.
void beginEvent() override
Receive and dispatch signal for the start of a new event.
Interface for a minimal algorithm part that wants to expose some parameters to a module.
Definition: Findlet.h:26
Refines the clustering of wire hits from clusters to clusters.
void apply(std::vector< IOType > &input) final
Swaps the items to the DataStore or to the backup storage location.
std::vector< IOType > m_backup
Backup storage if the vector should not be written to the DataStore.
void initialize() override
Receive signal before the start of the event processing.
std::string getDescription() override
Short description of the findlet.
bool m_param_writeStoreVector
Switch if the store vector should be filled.
std::string m_classMnemomicDescription
Short description for the type of objects to be written out.
void beginEvent() override
Receive signal for the start of a new event.
std::string m_classMnemomicName
Short name for the type of objects to be written out.
StoreVectorSwapper(const std::string &storeVectorName, const std::string &classMnemomicName="", const std::string &classMnemomicDescription="")
Constructor taking the default name of the store vector which is the target of the swap.
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) override
Expose the parameters to a module.
std::string m_param_storeVectorName
Name of the store vector to be used.
This class is for convenience access and registration of objects, that are stored inside the StoreWra...
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_DontWriteOut|DataStore::c_ErrorIfAlreadyRegistered)
Register the object/array in the DataStore.
void addParameter(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module list.
std::string getClassMnemomicParameterDescription(const RecoTrack *dispatchTag)
Returns a short description for class RecoTrack to be used in descriptions of parameters.
std::string getClassMnemomicParameterName(const RecoTrack *dispatchTag)
Returns a short name for class RecoTrack to be used in names of parameters.
Abstract base class for different kinds of events.