15#include <tracking/trackFindingVXD/filterMap/filterFramework/VoidObserver.h>
33 template<
typename ... typePack>
45 template<
typename ... types>
70 template<
typename T,
typename ... types>
75 class BypassableFilter;
77 class ActivatableFilter;
145 template<
typename ... argsType>
148 typename std::enable_if<
all_same<argumentType, argsType ... >::value,
bool>::type
151 typename Variable::variableType value = Variable::value(args ...);
153 return m_range.contains(value);
161 void persist(TTree* t,
const std::string& branchName)
163 m_range.persist(t, branchName, Variable().name());
173 m_range.setBranchAddress(t, branchName, Variable().name());
208 bypass(
const bool& bypassVariable =
false)
220 enable(
const bool& enableVariable =
true)
230 template<
class otherObserver >
242 template<
class otherObserver >
244 m_range(
filter.getRange()) {};
254 return m_range.getNameAndReference(pointers, Variable::name());
306 public Filter<Variable, RangeType, Observer> {
324 Filter(
const RangeType& range,
const bool& bypass):
326 { m_bypass = &bypass; };
339 template<
typename ... argsType>
345 typename Variable::variableType value = Variable::value(args ...);
358 return "(" + std::to_string(*m_bypass) +
" OR " +
413 public Filter<Variable, RangeType, Observer> {
431 Filter(
const RangeType& range,
const bool& enable):
434 m_enable = & enable ;
447 template<
typename ... argsType>
451 typename Variable::variableType value = Variable::value(args ...);
465 return "(!(" + std::to_string(*m_enable) +
") OR "
486 class templateObserverType
490 const char* c_notSuffix =
"_not";
515 template<
typename ... argsType>
516 typename std::enable_if<
all_same<argumentType, argsType ...>::value,
bool>::type
519 return ! m_filter.accept(args ...);
530 return "!" + m_filter.getNameAndReference(pointers);
538 template<
class otherObserver>
539 Filter<Belle2::OperatorNot,
decltype(someFilter().observeLeaf(otherObserver())), otherObserver>
542 return Filter<Belle2::OperatorNot,
decltype(someFilter().observeLeaf(otherObserver())),
543 otherObserver>(m_filter.observeLeaf(otherObserver()));
551 void persist(TTree* t,
const std::string& branchName)
553 std::string nameOfFilter(branchName);
554 nameOfFilter += c_notSuffix;
555 m_filter.persist(t, nameOfFilter);
565 std::string nameOfFilter(branchName);
566 nameOfFilter += c_notSuffix;
567 m_filter.setBranchAddress(t, nameOfFilter);
581 template<
typename ... types>
602 class templateObserverType
604 class Filter <
Belle2::OperatorAnd, FilterA, FilterB, templateObserverType> {
606 const char* c_andSuffixA =
"_and_A";
608 const char* c_andSuffixB =
"_and_B";
626 Filter(
const FilterA& filterA,
const FilterB& filterB):
627 m_filterA(filterA), m_filterB(filterB) { };
641 template<
typename ... argsType>
642 typename std::enable_if<
all_same<argumentType, argumentTypeB, argsType ...>::value,
bool>::type
645 templateObserverType::prepare(args ...);
646 bool returnValue = m_filterA.accept(args ...) && m_filterB.accept(args ...);
647 templateObserverType::collect(args ...);
658 template<
class otherObserver>
659 Filter<Belle2::OperatorAnd,
decltype(FilterA().observeLeaf(otherObserver())),
660 decltype(FilterB().observeLeaf(otherObserver())), otherObserver>
664 return Filter<Belle2::OperatorAnd,
665 decltype(FilterA().observeLeaf(otherObserver())),
666 decltype(FilterB().observeLeaf(otherObserver())),
667 otherObserver>(m_filterA.observeLeaf(otherObserver()), m_filterB.observeLeaf(otherObserver()));
677 template<
class otherObserver>
678 Filter<Belle2::OperatorAnd,
decltype(FilterA().observeLeaf(otherObserver())),
679 decltype(FilterB().observeLeaf(otherObserver())),
VoidObserver>
684 return Filter<Belle2::OperatorAnd,
685 decltype(FilterA().observeLeaf(otherObserver())),
686 decltype(FilterB().observeLeaf(otherObserver())),
687 VoidObserver>(m_filterA.observeLeaf(otherObserver()), m_filterB.observeLeaf(otherObserver()));
695 void persist(TTree* t,
const std::string& branchName)
697 std::string nameOfFilterA(branchName);
698 nameOfFilterA += c_andSuffixA;
699 m_filterA.persist(t, nameOfFilterA);
701 std::string nameOfFilterB(branchName);
702 nameOfFilterB += c_andSuffixB;
703 m_filterB.persist(t, nameOfFilterB);
713 std::string nameOfFilterA(branchName);
714 nameOfFilterA += c_andSuffixA;
715 m_filterA.setBranchAddress(t, nameOfFilterA);
717 std::string nameOfFilterB(branchName);
718 nameOfFilterB += c_andSuffixB;
719 m_filterB.setBranchAddress(t, nameOfFilterB);
730 return "(" + m_filterA.getNameAndReference(pointers) +
" AND " + m_filterB.getNameAndReference(pointers) +
")";
772 class templateObserverType
775 class Filter <
Belle2::OperatorOr, FilterA, FilterB, templateObserverType > {
777 const char* c_orSuffixA =
"_or_A";
779 const char* c_orSuffixB =
"_or_B";
798 Filter(
const FilterA& filterA,
const FilterB& filterB):
799 m_filterA(filterA), m_filterB(filterB) { };
813 template<
typename ... argsType>
814 typename std::enable_if <
all_same<argumentType, argumentTypeB, argsType ...>::value,
bool>::type
817 templateObserverType::prepare(args ...);
818 bool returnValue = m_filterA.accept(args ...) || m_filterB.accept(args ...);
819 templateObserverType::collect(args ...);
829 template<
class otherObserver>
830 Filter<Belle2::OperatorOr,
decltype(FilterA().observeLeaf(otherObserver())),
831 decltype(FilterB().observeLeaf(otherObserver())), otherObserver>
835 return Filter<Belle2::OperatorOr,
836 decltype(FilterA().observeLeaf(otherObserver())),
837 decltype(FilterB().observeLeaf(otherObserver())),
838 otherObserver>(m_filterA.observeLeaf(otherObserver()), m_filterB.observeLeaf(otherObserver()));
849 template<
class otherObserver>
850 Filter<Belle2::OperatorOr,
decltype(FilterA().observeLeaf(otherObserver())),
851 decltype(FilterB().observeLeaf(otherObserver())),
VoidObserver>
856 return Filter<Belle2::OperatorOr,
857 decltype(FilterA().observeLeaf(otherObserver())),
858 decltype(FilterB().observeLeaf(otherObserver())),
859 VoidObserver>(m_filterA.observeLeaf(otherObserver()), m_filterB.observeLeaf(otherObserver()));
867 void persist(TTree* t,
const std::string& branchName)
869 std::string nameOfFilterA(branchName);
870 nameOfFilterA += c_orSuffixA;
871 m_filterA.persist(t, nameOfFilterA);
873 std::string nameOfFilterB(branchName);
874 nameOfFilterB += c_orSuffixB;
875 m_filterB.persist(t, nameOfFilterB);
885 std::string nameOfFilterA(branchName);
886 nameOfFilterA += c_orSuffixA;
887 m_filterA.setBranchAddress(t, nameOfFilterA);
889 std::string nameOfFilterB(branchName);
890 nameOfFilterB += c_orSuffixB;
891 m_filterB.setBranchAddress(t, nameOfFilterB);
902 return "(" + m_filterA.getNameAndReference(pointers) +
" OR " + m_filterB.getNameAndReference(pointers) +
")";
942 template<
class booleanBinaryOperator,
946 typename ... argsTypes>
951 return observer::initialize(args ...)
965 template<
class booleanUnaryOperator,
968 typename ... argsTypes>
984 template<
class Variable,
class RangeType,
class observer,
typename ... argsTypes>
987 return observer::initialize(Variable(),
filter.getRange(), args ...);
void setBranchAddress(TTree *t, const std::string &branchName)
Set the Branches addresses to this filter.
FilterA::argumentType argumentType
Handy typedef for arguments type A.
FilterB::argumentType argumentTypeB
Handy typedef for arguments type B.
FilterB m_filterB
Member containing the filter B of the combination A AND B.
Filter< Belle2::OperatorAnd, decltype(FilterA().observeLeaf(otherObserver())), decltype(FilterB().observeLeaf(otherObserver())), VoidObserver > observeLeaf(const otherObserver &) const
will set the observer for the Leaves of this filter, this AND filter will not be observed.
std::enable_if< all_same< functionTypeA, functionTypeB >::value, functionTypeA >::type functionType
Handy typedef for combined function type.
void persist(TTree *t, const std::string &branchName)
Persist the filter on a TTree.
std::string getNameAndReference(std::vector< std::pair< char, void * > > *pointers=nullptr)
Getter for name of and reference to the range of the filters.
Filter< Belle2::OperatorAnd, decltype(FilterA().observeLeaf(otherObserver())), decltype(FilterB().observeLeaf(otherObserver())), otherObserver > observe(const otherObserver &) const
Will set the observer for this and both of the via the AND operation combined filters it contains.
Filter(const FilterA &filterA, const FilterB &filterB)
Constructor creating a filter representing the boolean AND combination of two filters.
FilterB::functionType functionTypeB
Handy typedef for function type B.
FilterA m_filterA
Member containing the filter A of the combination A AND B.
Filter()
Empty constructor.
std::enable_if< all_same< argumentType, argumentTypeB, argsType... >::value, bool >::type accept(const argsType &... args) const
The accept method for the combination of two filters with the AND Operator: This will return the comb...
FilterA::functionType functionTypeA
Handy typedef for function type A.
void setBranchAddress(TTree *t, const std::string &branchName)
Set the Branches addresses to this filter.
someFilter m_filter
Member variable containing the filter.
void persist(TTree *t, const std::string &branchName)
Persist the filter on a TTree.
std::string getNameAndReference(std::vector< std::pair< char, void * > > *pointers=nullptr)
Getter for name of and reference to the range of the filters.
std::enable_if< all_same< argumentType, argsType... >::value, bool >::type accept(const argsType &... args) const
The accept method of the filter with NOT Operator: This will return the inverse of the result of the ...
Filter< Belle2::OperatorNot, decltype(someFilter().observeLeaf(otherObserver())), otherObserver > observeLeaf(const otherObserver &) const
Will set the observer for the combination of NOT operator + filter.
someFilter::argumentType argumentType
Handy typedef for arguments.
Filter()
Empty constructor.
Filter(const someFilter &filter)
Constructor creating a NOT filter from a filter.
someFilter::functionType functionType
Handy typedef for function.
void setBranchAddress(TTree *t, const std::string &branchName)
Set the Branches addresses to this filter.
FilterA::argumentType argumentType
Handy typedef for arguments type A.
FilterB::argumentType argumentTypeB
Handy typedef for arguments type B.
FilterB m_filterB
Member containing the filter B of the combination A OR B.
std::enable_if< all_same< functionTypeA, functionTypeB >::value, functionTypeA >::type functionType
Handy typedef for the combined function type.
void persist(TTree *t, const std::string &branchName)
Persist the filter on a TTree.
Filter< Belle2::OperatorOr, decltype(FilterA().observeLeaf(otherObserver())), decltype(FilterB().observeLeaf(otherObserver())), otherObserver > observe(const otherObserver &) const
Will set the observer for this and both via the OR operator combined filters it contains,...
Filter< Belle2::OperatorOr, decltype(FilterA().observeLeaf(otherObserver())), decltype(FilterB().observeLeaf(otherObserver())), VoidObserver > observeLeaf(const otherObserver &) const
Will set the observer for both via the OR operation combined filters it contains, this filter itself ...
std::string getNameAndReference(std::vector< std::pair< char, void * > > *pointers=nullptr)
Getter for name of and reference to the range of the filters.
Filter(const FilterA &filterA, const FilterB &filterB)
Constructor creating a filter representing the boolean OR combination of two filters.
FilterB::functionType functionTypeB
Handy typedef for function type B.
FilterA m_filterA
Member containing the filter A of the combination A OR B.
Filter()
Empty constructor.
std::enable_if< all_same< argumentType, argumentTypeB, argsType... >::value, bool >::type accept(const argsType &... args) const
The accept method for the combination of two filters with the OR Operator: This will return the combi...
FilterA::functionType functionTypeA
Handy typedef for function type A.
Variable::argumentType argumentType
Handy typedef for arguments.
Filter()=default
Empty constructor.
Variable::functionType functionType
Handy typedef for function.
std::string getNameAndReference(std::vector< std::pair< char, void * > > *pointers=nullptr)
Getter for name of and reference to the range of the filters.
Filter(const RangeType &range, const bool &enable)
Constructor.
std::enable_if< all_same< argumentType, argsType... >::value, bool >::type accept(const argsType &... args) const
The accept method of the activatable filter: All the real computations are occurring in this method.
const bool * m_enable
Member pointer to boolean indicating if filters are active (true) or inactive (false).
Variable::argumentType argumentType
Handy typedef for arguments.
Filter()=default
Empty constructor.
Variable::functionType functionType
Handy typedef for function.
std::string getNameAndReference(std::vector< std::pair< char, void * > > *pointers=nullptr)
Getter for name of and reference to the range of the filters.
const bool * m_bypass
Member pointer to boolean indicating if filters are bypassed (true) or their actual result is returne...
std::enable_if< all_same< argumentType, argsType... >::value, bool >::type accept(const argsType &... args) const
The accept method of the bypassable filter: All the real computations are occurring in this method.
Filter(const RangeType &range, const bool &bypass)
Constructor.
void setBranchAddress(TTree *t, const std::string &branchName)
Set the Branches addresses to this filter.
Filter< Variable, RangeType, BypassableFilter, Observer > bypass(const bool &bypassVariable=false)
This method creates a new bypassable Filter with the same range of *this E.g.:
Variable::argumentType argumentType
Handy typedef for arguments.
void persist(TTree *t, const std::string &branchName)
Persist the range on a TTree.
Filter(const Filter< Variable, RangeType, otherObserver > &filter)
Copy constructor for filter.
Filter()=default
Empty constructor.
Variable::functionType functionType
Handy typedef for function.
std::string getNameAndReference(std::vector< std::pair< char, void * > > *pointers=nullptr)
Getter for name of and reference to the range of the filters.
Filter< Variable, RangeType, otherObserver > observeLeaf(const otherObserver &) const
Function to observer of a filter.
std::enable_if< all_same< argumentType, argsType... >::value, bool >::type accept(const argsType &... args) const
The accept method of the filter: All the real computations are occurring in this method.
RangeType m_range
Member range of the filter.
RangeType getRange(void) const
Getter of the range.
Filter(const RangeType &range)
Constructor.
Filter< Variable, RangeType, ActivatableFilter, Observer > enable(const bool &enableVariable=true)
Create a new activatable filter.
This class is used to select pairs, triplets... of objects.
Observer base class which can be used to evaluate the VXDTF2's Filters.
static void notify(T, double, someRangeType, const someHitType &, const someHitType &)
exemplary draft for a notify-function of an observer
The most CPU efficient Observer for the VXDTF filter tools (even if useless).
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
Filter< Belle2::OperatorOr, Belle2::Filter< types1... >, Belle2::Filter< types2... >, Belle2::VoidObserver > operator||(const Filter< types1... > &filter1, const Filter< types2... > &filter2)
Definition of the boolean OR operator || of the Filter class.
Filter< Belle2::OperatorAnd, Belle2::Filter< types1... >, Belle2::Filter< types2... >, Belle2::VoidObserver > operator&&(const Filter< types1... > &filter1, const Filter< types2... > &filter2)
Definition of the boolean AND operator && of the Filter class.
Filter< OperatorNot, Filter< types... >, VoidObserver > operator!(const Filter< types... > &filter)
Definition of the NOT operator ! for the Filter class.
bool initializeObservers(const Filter< booleanBinaryOperator, Belle2::Filter< types1... >, Belle2::Filter< types2... >, observer > &, argsTypes ... args)
Observer Stuff ///.
Abstract base class for different kinds of events.
The all_same struct is meant to check that all the types in a template pack are of the same type.