Belle II Software  release-05-02-19
StoreVectorSwapper.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2015 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Oliver Frost *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #pragma once
11 
12 #include <tracking/trackFindingCDC/findlets/base/Findlet.h>
13 #include <tracking/trackFindingCDC/utilities/StringManipulation.h>
14 #include <tracking/trackFindingCDC/rootification/StoreWrappedObjPtr.h>
15 
16 #include <framework/core/ModuleParamList.h>
17 
18 #include <vector>
19 
20 namespace Belle2 {
25  namespace TrackFindingCDC {
26 
28 
31  template<class IOType, bool a_alwaysWrite = false>
32  class StoreVectorSwapper:
33  public Findlet<IOType> {
34 
35  private:
37  using Super = Findlet<IOType>;
38 
39  public:
41  explicit StoreVectorSwapper(const std::string& storeVectorName,
42  const std::string& classMnemomicName = "",
43  const std::string& classMnemomicDescription = "")
44  : m_param_storeVectorName(storeVectorName),
45  m_classMnemomicName(classMnemomicName),
46  m_classMnemomicDescription(classMnemomicDescription)
47  {
48  if (m_classMnemomicDescription == "") {
49  if (m_classMnemomicName != "") {
51  } else {
52  // Just a little bit of ADL
54  }
55  }
56 
57  if (m_classMnemomicName == "") {
58  // Just a little bit of ADL
59  m_classMnemomicName = getClassMnemomicParameterName(static_cast<IOType*>(nullptr));
60  }
61  }
62 
64  void exposeParameters(ModuleParamList* moduleParamList, const std::string& prefix) override
65  {
66  std::string classMnemomicCapitalName = m_classMnemomicName;
67  classMnemomicCapitalName[0] = ::toupper(classMnemomicCapitalName.at(0));
68 
69  if (not a_alwaysWrite) {
70  moduleParamList->addParameter(prefixed(prefix, "Write" + classMnemomicCapitalName + "s"),
72  "Switch if " + m_classMnemomicDescription +
73  "s shall be written to the DataStore",
75  }
76 
77  moduleParamList->addParameter(prefixed(prefix, classMnemomicCapitalName + "sStoreObjName"),
79  "Name of the output StoreObjPtr of the " + m_classMnemomicDescription +
80  "s generated within this module.",
81  std::string(m_param_storeVectorName));
82  //FIXME: Small parameter names
83  }
84 
86  std::string getDescription() override
87  {
88  return "Swaps an interal vector of " + m_classMnemomicDescription + "s to the DataStore";
89  }
90 
91  public:
93  void initialize() override
94  {
99  }
100  }
101 
103  void beginEvent() override
104  {
106 
110  if (not storeVector.isValid()) {
111  storeVector.construct();
112  }
113  }
114  m_backup.clear();
115  }
116 
118  void apply(std::vector<IOType>& input) final {
119  // Swap items to the DataStore
121  {
122  StoreWrappedObjPtr< std::vector<IOType> > storeVector(m_param_storeVectorName);
123  std::vector<IOType>& sink = *storeVector;
124  sink.swap(input);
125  } else {
126  m_backup.swap(input);
127  }
128  }
129 
130  private:
132  std::string m_param_storeVectorName;
133 
135  bool m_param_writeStoreVector = a_alwaysWrite;
136 
138  std::string m_classMnemomicName;
139 
141  std::string m_classMnemomicDescription;
142 
144  std::vector<IOType> m_backup;
145  };
146  }
148 }
Belle2::TrackFindingCDC::StoreVectorSwapper::StoreVectorSwapper
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.
Definition: StoreVectorSwapper.h:49
Belle2::TrackFindingCDC::StoreVectorSwapper::m_classMnemomicDescription
std::string m_classMnemomicDescription
Short description for the type of objects to be written out.
Definition: StoreVectorSwapper.h:149
Belle2::TrackFindingCDC::StoreVectorSwapper::initialize
void initialize() override
Receive signal before the start of the event processing.
Definition: StoreVectorSwapper.h:101
Belle2::TrackFindingCDC::StoreWrappedObjPtr
This class is for convenience access and registration of objects, that are stored inside the StoreWra...
Definition: StoreWrappedObjPtr.h:40
Belle2::DataStore::c_DontWriteOut
@ c_DontWriteOut
Object/array should be NOT saved by output modules.
Definition: DataStore.h:73
Belle2::TrackFindingCDC::StoreVectorSwapper::beginEvent
void beginEvent() override
Receive signal for the start of a new event.
Definition: StoreVectorSwapper.h:111
Belle2::TrackFindingCDC::CompositeProcessingSignalListener::initialize
void initialize() override
Receive and dispatch signal before the start of the event processing.
Definition: CompositeProcessingSignalListener.cc:17
Belle2::TrackFindingCDC::StoreVectorSwapper::m_backup
std::vector< IOType > m_backup
Backup storage if the vector should not be written to the DataStore.
Definition: StoreVectorSwapper.h:152
Belle2::TrackFindingCDC::StoreVectorSwapper::getDescription
std::string getDescription() override
Short description of the findlet.
Definition: StoreVectorSwapper.h:94
Belle2::getClassMnemomicParameterDescription
std::string getClassMnemomicParameterDescription(const RecoTrack *dispatchTag __attribute__((unused)))
Returns a short description for class RecoTrack to be used in descriptions of parameters.
Definition: ClassMnemomics.h:33
Belle2::TrackFindingCDC::StoreVectorSwapper::Super
Findlet< IOType > Super
Type of the base class.
Definition: StoreVectorSwapper.h:45
Belle2::TrackFindingCDC::StoreVectorSwapper::m_param_storeVectorName
std::string m_param_storeVectorName
Name of the store vector to be used.
Definition: StoreVectorSwapper.h:140
Belle2::TrackFindingCDC::StoreVectorSwapper::exposeParameters
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) override
Expose the parameters to a module.
Definition: StoreVectorSwapper.h:72
Belle2::StoreObjPtr< StoreWrapper< T > >::construct
bool construct(Args &&... params)
Construct an object of type T in this StoreObjPtr, using the provided constructor arguments.
Definition: StoreObjPtr.h:128
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TrackFindingCDC::StoreVectorSwapper::m_param_writeStoreVector
bool m_param_writeStoreVector
Switch if the store vector should be filled.
Definition: StoreVectorSwapper.h:143
Belle2::TrackFindingCDC::CompositeProcessingSignalListener::beginEvent
void beginEvent() override
Receive and dispatch signal for the start of a new event.
Definition: CompositeProcessingSignalListener.cc:33
Belle2::TrackFindingCDC::StoreWrappedObjPtr::registerInDataStore
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_DontWriteOut|DataStore::c_ErrorIfAlreadyRegistered)
Register the object/array in the DataStore.
Definition: StoreWrappedObjPtr.h:60
Belle2::DataStore::c_ErrorIfAlreadyRegistered
@ c_ErrorIfAlreadyRegistered
If the object/array was already registered, produce an error (aborting initialisation).
Definition: DataStore.h:74
Belle2::TrackFindingCDC::StoreVectorSwapper::apply
void apply(std::vector< IOType > &input) final
Swaps the items to the DataStore or to the backup storage location.
Definition: StoreVectorSwapper.h:126
Belle2::getClassMnemomicParameterName
std::string getClassMnemomicParameterName(const RecoTrack *dispatchTag __attribute__((unused)))
Returns a short name for class RecoTrack to be used in names of parameters.
Definition: ClassMnemomics.h:27
Belle2::TrackFindingCDC::StoreVectorSwapper::m_classMnemomicName
std::string m_classMnemomicName
Short name for the type of objects to be written out.
Definition: StoreVectorSwapper.h:146
Belle2::StoreObjPtr< StoreWrapper< T > >::isValid
bool isValid() const
Check whether the object was created.
Definition: StoreObjPtr.h:120