OPAL (Object Oriented Parallel Accelerator Library)  2024.1
OPAL
OpalFilter.h
Go to the documentation of this file.
1 //
2 // Class OpalFilter
3 // The class for the Filter Object.
4 // A FILTER definition is used to define a filter which can be applied
5 // to a 1D histogram in order to get rid of noise.
6 //
7 // Copyright (c) 2008 - 2022, Christof Metzger-Kraus
8 // All rights reserved
9 //
10 // This file is part of OPAL.
11 //
12 // OPAL is free software: you can redistribute it and/or modify
13 // it under the terms of the GNU General Public License as published by
14 // the Free Software Foundation, either version 3 of the License, or
15 // (at your option) any later version.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with OPAL. If not, see <https://www.gnu.org/licenses/>.
19 //
20 #ifndef OPAL_FILTER_HH
21 #define OPAL_FILTER_HH
22 
24 #include "Filters/Filter.h"
25 
26 #include <memory>
27 #include <vector>
28 
29 
30 class OpalFilter: public Definition {
31 
32 public:
34  OpalFilter();
35 
36  virtual ~OpalFilter();
37 
39  // Can replace only by another OpalFilter
40  virtual bool canReplaceBy(Object* object);
41 
43  virtual OpalFilter* clone(const std::string& name);
44 
46  virtual void execute();
47 
49  static OpalFilter* find(const std::string& name);
50 
52  virtual void update();
53 
54  void print(std::ostream& os) const;
55 
56  void initOpalFilter();
57 
58  inline void apply(std::vector<double>& histogram);
59  inline void calc_derivative(std::vector<double>& histogram, const double& hz);
60 
62 
63 private:
64  enum class FilterType: unsigned short {
68  STENCIL
69  };
70 
71  // Not implemented.
72  OpalFilter(const OpalFilter&);
73  void operator=(const OpalFilter&);
74 
75  // Clone constructor.
76  OpalFilter(const std::string &name, OpalFilter* parent);
77 };
78 
79 void OpalFilter::apply(std::vector<double>& histogram) {
80  if (filter_m)
81  filter_m->apply(histogram);
82 }
83 
84 void OpalFilter::calc_derivative(std::vector<double>& histogram, const double& hz) {
85  if (filter_m)
86  filter_m->calc_derivative(histogram, hz);
87 }
88 
89 inline std::ostream& operator<<(std::ostream& os, const OpalFilter& b) {
90  b.print(os);
91  return os;
92 }
93 
94 #endif // OPAL_FILTER_HH
void print(std::ostream &os) const
Print the object.
Definition: OpalFilter.cpp:204
virtual ~OpalFilter()
Definition: OpalFilter.cpp:102
The base class for all OPAL objects.
Definition: Object.h:48
static OpalFilter * find(const std::string &name)
Find named FILTER.
Definition: OpalFilter.cpp:124
virtual void execute()
Check the OpalFilter data.
Definition: OpalFilter.cpp:119
std::ostream & operator<<(std::ostream &os, const Attribute &attr)
Definition: Attribute.cpp:169
virtual OpalFilter * clone(const std::string &name)
Make clone.
Definition: OpalFilter.cpp:114
Filter * filter_m
Definition: OpalFilter.h:61
void apply(std::vector< double > &histogram)
Definition: OpalFilter.h:79
virtual void apply(std::vector< double > &histogram)=0
OpalFilter()
Exemplar constructor.
Definition: OpalFilter.cpp:55
virtual void update()
Update the OpalFilter data.
Definition: OpalFilter.cpp:135
void initOpalFilter()
Definition: OpalFilter.cpp:141
const std::string name
virtual void calc_derivative(std::vector< double > &histogram, const double &h)=0
virtual bool canReplaceBy(Object *object)
Test if replacement is allowed.
Definition: OpalFilter.cpp:108
The base class for all OPAL definitions.
Definition: Definition.h:30
void operator=(const OpalFilter &)
Definition: Filter.h:8
void calc_derivative(std::vector< double > &histogram, const double &hz)
Definition: OpalFilter.h:84