Belle II Software  release-05-02-19
StoreArrayLoader.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2017 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Oliver Frost, Nils Braun *
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 
14 #include <tracking/trackFindingCDC/utilities/StringManipulation.h>
15 
16 #include <framework/core/ModuleParamList.h>
17 #include <framework/datastore/StoreArray.h>
18 
19 #include <vector>
20 
21 namespace Belle2 {
26  namespace TrackFindingCDC {
27 
33  template <class IOType>
34  class StoreArrayLoader : public Findlet<IOType*> {
35 
37  using Super = Findlet<IOType*>;
38 
39  public:
41  StoreArrayLoader(const std::string& storeArrayName = "",
42  const std::string& classMnemomicName = "",
43  const std::string& classMnemomicDescription = "")
44  : m_param_storeArrayName(storeArrayName),
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, taken from StoreArraySwapper
54  }
55  }
56 
57  if (m_classMnemomicName == "") {
58  // Just a little bit of ADL, takem from StoreArraySwapper
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  moduleParamList->addParameter(prefixed(prefix, classMnemomicCapitalName + "sStoreArrayName"),
71  "Name of the StoreArray of the " + m_classMnemomicDescription,
72  std::string(m_param_storeArrayName));
73  }
74 
76  std::string getDescription() override
77  {
78  return "Swaps an interal vector of " + m_classMnemomicDescription + "s to the DataStore";
79  }
80 
82  void initialize() override
83  {
86  storeArray.isRequired();
87  }
88 
90  void apply(std::vector<IOType*>& output) final {
91  // Swap items to the DataStore
93 
94  output.reserve(output.size() + storeArray.getEntries());
95 
96  for (auto& item : storeArray)
97  {
98  // cppcheck-suppress useStlAlgorithm
99  output.push_back(&item);
100  }
101  }
102 
103  private:
105  std::string m_param_storeArrayName;
106 
108  std::string m_classMnemomicName;
109 
111  std::string m_classMnemomicDescription;
112  };
113  }
115 }
Belle2::TrackFindingCDC::StoreArrayLoader::Super
Findlet< IOType * > Super
Type of the base class.
Definition: StoreArrayLoader.h:45
Belle2::TrackFindingCDC::StoreArrayLoader::exposeParameters
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) override
Expose the parameters to a module.
Definition: StoreArrayLoader.h:72
Belle2::TrackFindingCDC::StoreArrayLoader::m_param_storeArrayName
std::string m_param_storeArrayName
Name of the store vector to be used.
Definition: StoreArrayLoader.h:113
Belle2::TrackFindingCDC::StoreArrayLoader::initialize
void initialize() override
Receive signal before the start of the event processing.
Definition: StoreArrayLoader.h:90
Belle2::TrackFindingCDC::StoreArrayLoader::apply
void apply(std::vector< IOType * > &output) final
Loads the items from the DataStore.
Definition: StoreArrayLoader.h:98
Belle2::TrackFindingCDC::CompositeProcessingSignalListener::initialize
void initialize() override
Receive and dispatch signal before the start of the event processing.
Definition: CompositeProcessingSignalListener.cc:17
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
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TrackFindingCDC::StoreArrayLoader::m_classMnemomicDescription
std::string m_classMnemomicDescription
Short description for the type of objects to be written out.
Definition: StoreArrayLoader.h:119
Belle2::StoreArray
Accessor to arrays stored in the data store.
Definition: ECLMatchingPerformanceExpertModule.h:33
Belle2::TrackFindingCDC::StoreArrayLoader::m_classMnemomicName
std::string m_classMnemomicName
Short name for the type of objects to be written out.
Definition: StoreArrayLoader.h:116
Belle2::TrackFindingCDC::StoreArrayLoader::StoreArrayLoader
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.
Definition: StoreArrayLoader.h:49
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::StoreArray::getEntries
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:226
Belle2::TrackFindingCDC::StoreArrayLoader::getDescription
std::string getDescription() override
Short description of the findlet.
Definition: StoreArrayLoader.h:84