10#include <tracking/trackFindingCDC/filters/base/UnionRecordingFilter.dcl.h>
12#include <tracking/trackFindingCDC/filters/base/RecordingFilter.icc.h>
14#include <tracking/trackFindingCDC/filters/base/FilterVarSet.icc.h>
15#include <tracking/trackFindingCDC/filters/base/FilterVarSet.dcl.h>
17#include <tracking/trackFindingCDC/varsets/UnionVarSet.h>
19#include <framework/core/ModuleParamList.templateDetails.h>
20#include <tracking/trackFindingCDC/utilities/StringManipulation.h>
31 namespace TrackFindingCDC {
34 template <
class AFilter>
36 const std::string& defaultRootFileName,
37 const std::string& defaultTreeName)
39 , m_filterFactory(
std::move(filterFactory))
43 template <
class AFilter>
46 template <
class AFilter>
49 Super::exposeParameters(moduleParamList, prefix);
51 moduleParamList->
addParameter(prefixed(prefix,
"varSets"),
53 "List of names refering to concrete variable sets."
55 join(
", ", this->getValidVarSetNames()),
60 "Filter name which object must pass to be recorded."
62 join(
", ", this->getValidFilterNames()),
66 template <
class AFilter>
70 if (m_param_skim !=
"") {
71 std::unique_ptr<AFilter> skimFilter = m_filterFactory->create(m_param_skim);
72 this->setSkimFilter(std::move(skimFilter));
75 auto multiVarSet = std::make_unique<UnionVarSet<Object>>();
78 for (std::string name : getVarSetNames()) {
79 std::unique_ptr<AVarSet> varSet = createVarSet(name);
81 multiVarSet->push_back(std::move(varSet));
83 B2WARNING(
"Could not create a variable set from name " << name);
86 this->setVarSet(std::move(multiVarSet));
90 template <
class AFilter>
94 std::vector<std::string> varSetNames;
95 std::vector<std::string> filterNames = getValidFilterNames();
96 for (
const std::string& filterName : filterNames) {
97 std::string varSetName =
"filter(" + filterName +
")";
98 varSetNames.push_back(varSetName);
103 template <
class AFilter>
107 std::map<std::string, std::string> filterNamesAndDescriptions =
108 m_filterFactory->getValidFilterNamesAndDescriptions();
110 std::vector<std::string> filterNames;
111 filterNames.reserve(filterNamesAndDescriptions.size());
112 for (
const auto& filterNameAndDescription :
113 filterNamesAndDescriptions) {
114 const std::string& filterName = filterNameAndDescription.first;
115 filterNames.push_back(filterName);
120 template <
class AFilter>
122 -> std::unique_ptr<AVarSet> {
123 if (name.find(
"filter(") == 0 and name.rfind(
")") == name.size() - 1)
125 B2INFO(
"Detected filter name");
126 std::string filterName = name.substr(7, name.size() - 8);
127 B2INFO(
"filterName = " << filterName);
128 std::unique_ptr<AFilter>
filter = m_filterFactory->create(filterName);
130 B2WARNING(
"Could not construct filter for name " << filterName);
131 return std::unique_ptr<AVarSet>(
nullptr);
134 return std::unique_ptr<AVarSet>(filterVarSet);
137 return std::unique_ptr<AVarSet>(
nullptr);
141 template <
class AFilter>
144 return m_param_varSetNames;
148 template <
class AFilterFactory>
150 const std::string& defaultRootFileName,
151 const std::string& defaultTreeName)
156 template <
class AFilterFactory>
The Module parameter list class.
Class to compute floating point variables from a filter response which can be recorded as a flat TNtu...
Filter adapter to make a filter work on a set of variables and record the observed instances on invok...
UnionRecordingFilter(const std::string &defaultRootFileName="records.root", const std::string &defaultTreeName="records")
Constructor of the filter.
~UnionRecordingFilter()
Default destructor.
A filter that records variables form given objects.
virtual std::vector< std::string > getValidFilterNames() const
Getter for the names of valid filters.
void initialize() override
Initialize the recorder before event processing.
~UnionRecording()
Default destructor.
UnionRecording(std::unique_ptr< AFilterFactory > filterFactory, const std::string &defaultRootFileName="records.root", const std::string &defaultTreeName="records")
Constructor of the filter.
const std::vector< std::string > & getVarSetNames() const
Splits the comma separated variable names list into a vector of names.
typename AFilter::Object Object
Type of the object to be analysed.
virtual std::unique_ptr< AVarSet > createVarSet(const std::string &name) const
Create a variable set for the given name.
virtual std::vector< std::string > getValidVarSetNames() const
Getter for the list of valid names of concret variable sets.
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) override
Expose the set of parameters of the filter to the module parameter list.
Class that accomodates many variable sets and presents them as on set of variables.
void addParameter(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module list.
std::map< ExpRun, std::pair< double, double > > filter(const std::map< ExpRun, std::pair< double, double > > &runs, double cut, std::map< ExpRun, std::pair< double, double > > &runsRemoved)
filter events to remove runs shorter than cut, it stores removed runs in runsRemoved
Abstract base class for different kinds of events.