Belle II Software  release-08-01-10
StoreArrayLoader.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 
12 #include <tracking/trackFindingCDC/utilities/StringManipulation.h>
13 
14 #include <framework/core/ModuleParamList.h>
15 #include <framework/datastore/StoreArray.h>
16 
17 #include <vector>
18 
19 namespace Belle2 {
24  namespace TrackFindingCDC {
25 
31  template <class IOType>
32  class StoreArrayLoader : public Findlet<IOType*> {
33 
36 
37  public:
39  StoreArrayLoader(const std::string& storeArrayName = "",
40  const std::string& classMnemomicName = "",
41  const std::string& classMnemomicDescription = "")
42  : m_param_storeArrayName(storeArrayName),
43  m_classMnemomicName(classMnemomicName),
44  m_classMnemomicDescription(classMnemomicDescription)
45  {
46  if (m_classMnemomicDescription == "") {
47  if (m_classMnemomicName != "") {
49  } else {
50  // Just a little bit of ADL, taken from StoreArraySwapper
52  }
53  }
54 
55  if (m_classMnemomicName == "") {
56  // Just a little bit of ADL, takem from StoreArraySwapper
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  moduleParamList->addParameter(prefixed(prefix, classMnemomicCapitalName + "sStoreArrayName"),
69  "Name of the StoreArray of the " + m_classMnemomicDescription,
70  std::string(m_param_storeArrayName));
71  }
72 
74  std::string getDescription() override
75  {
76  return "Swaps an interal vector of " + m_classMnemomicDescription + "s to the DataStore";
77  }
78 
80  void initialize() override
81  {
84  storeArray.isRequired();
85  }
86 
88  void apply(std::vector<IOType*>& output) final {
89  // Swap items to the DataStore
91 
92  output.reserve(output.size() + storeArray.getEntries());
93 
94  for (auto& item : storeArray)
95  {
96  // cppcheck-suppress useStlAlgorithm
97  output.push_back(&item);
98  }
99  }
100 
101  private:
104 
106  std::string m_classMnemomicName;
107 
110  };
111  }
113 }
The Module parameter list class.
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:216
void initialize() override
Receive and dispatch signal before the start of the event processing.
Interface for a minimal algorithm part that wants to expose some parameters to a module.
Definition: Findlet.h:26
Helper findlet to allow combined findlets to import data from the DataStore.
void initialize() override
Receive signal before the start of the event processing.
StoreArrayLoader(const std::string &storeArrayName="", const std::string &classMnemomicName="", const std::string &classMnemomicDescription="")
Constructor taking the default name of the store vector which is the source for the import.
std::string getDescription() override
Short description of the findlet.
std::string m_param_storeArrayName
Name of the store vector to be used.
std::string m_classMnemomicDescription
Short description for the type of objects to be written out.
std::string m_classMnemomicName
Short name for the type of objects to be written out.
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) override
Expose the parameters to a module.
void apply(std::vector< IOType * > &output) final
Loads the items from 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.