FRIBParallelanalysis  1.0
FrameworkforMPIParalleldataanalysisatFRIB
TreeParameter.h
Go to the documentation of this file.
1 /*
2  This software is Copyright by the Board of Trustees of Michigan
3  State University (c) Copyright 2017.
4 
5  You may use this software under the terms of the GNU public license
6  (GPL). The terms of this license are described at:
7 
8  http://www.gnu.org/licenses/gpl.txt
9 
10  Authors:
11  Ron Fox
12  Giordano Cerriza
13  FRIB
14  Michigan State University
15  East Lansing, MI 48824-1321
16 */
17 
21 #ifndef TREEPARAMETER_H
22 #define TREEPARAMETER_H
23 #include <cstdint>
24 #include <string>
25 #include <map>
26 #include <vector>
27 namespace frib {
28  namespace analysis {
29  class CEvent;
43  public:
44  // internal data structs.
45 
46  typedef struct _SharedData {
47  unsigned s_parameterNumber; // Offset into paramter vector.
48  double s_low;
49  double s_high; // Spectrum recommendations.
50  unsigned s_chans;
51  std::string s_units;
52  std::uint64_t s_generation; // Last generation it was set at.
53  bool s_changed; // Definition has changed.
54  _SharedData(double low, double hi, unsigned chans, const char* units);
55  _SharedData(const _SharedData& rhs);
56  _SharedData();
58  private:
59  static std::uint64_t m_generation; // For O(1) reset.
60  static std::map<std::string, SharedData> m_parameterDictionary; // Registered parameters.
61  static unsigned m_nextId;
62  static std::vector<double> m_event; // Event data
63  static std::vector<unsigned> m_scoreboard; // Parameters set this event.
64  public:
65  static SharedData m_defaultSpecification;
66 
67  // object data:
68  private:
69  std::string m_name;
70  pSharedData m_pDefinition;
71 
72  // Static methods:
73  public:
74  static void nextEvent(); // Called to start a new event.
75  static std::vector<std::pair<unsigned, double>> collectEvent();
76  static void setDefaultLimits(double low, double high);
77  static void setDefaultBins(unsigned bins);
78  static void setDefaultUnits(const char* units);
79 
80  // These are for compatibility with ancient code and don't actually
81  // do anything:
82 
83  static void BindParameters();
84  static void setEvent(...);
85 
86  static const std::vector<double>& getEvent();
87  static const std::vector<unsigned> getScoreboard();
88  static std::vector<std::pair<std::string, SharedData>> getDefinitions();
89  private:
90  static pSharedData lookupParameter(const std::string& name);
91  static pSharedData makeSharedData(
92  const std::string& name,
93  double low, double high, unsigned chans, const char* units
94  );
95 
96  // Object methods:
97  // - construction/destruction and initialization:
98  public:
100  CTreeParameter(std::string name);
101  CTreeParameter(std::string name, std::string units);
102  CTreeParameter(std::string name, double lowLimit, double highLimit,
103  std::string units);
104  CTreeParameter(std::string name, unsigned channels,
105  double lowLimit, double highLimit, std::string units);
106  CTreeParameter(std::string name, unsigned resolution);
107  CTreeParameter(std::string name, unsigned resolution,
108  double lowLimit, double widthOrHigh,
109  std::string units, bool widthOrHighGiven);
110  CTreeParameter(std::string name, const CTreeParameter& Template);
111  CTreeParameter(const CTreeParameter& rhs);
112  ~CTreeParameter();
113 
114 
115  void Initialize(std::string name, unsigned resolution);
116  void Initialize(std::string name, unsigned resolution,
117  double lowLimit, double highOrWidth, std::string units,
118  bool highOrWidthGiven);
119  void Initialize(std::string name);
120  void Initialize(std::string name, std::string units);
121  void Initialize(std::string name, unsigned channels,
122  double lowLimit, double highLimit, std::string units);
123 
124 
125 
126  bool isBound() const;
127 
128  // Support for various arithmetic operations:
129 
130  operator double() const;
131  CTreeParameter& operator= (double newValue);
133  CTreeParameter& operator+=(double rhs);
134  CTreeParameter& operator-=(double rhs);
135  CTreeParameter& operator*=(double rhs);
136  CTreeParameter& operator/=(double rhs);
137  double operator++(int dummy);
139  double operator--(int dummy);
141 
142  // Getters and setters:
143 
144  std::string getName() const;
145  unsigned getId() const;
146  double getValue() const;
147  void setValue(double newValue);
148  unsigned getBins() const;
149  void setBins(unsigned channels);
150  double getStart() const;
151  void setStart(double low);
152  double getStop() const;
153  void setStop(double high);
154  double getInc() const;
155  void setInc(double channelWidth);
156  std::string getUnit() const;
157  void setUnit(std::string units);
158  bool isValid() const;
159  void setInvalid();
160  void Reset();
161  void clear();
162  bool hasChanged() const;
163  void setChanged() ;
164  void resetChanged() ;
165  static void ResetAll();
166 
167  void Bind();
168  // It's either this or expose all the internals via public methods
169  // I think this is preferable....much as I hate the friend feature
170  // of C++.
171 
172  friend ::frib::analysis::CEvent;
173  };
174 
175 
176  }
177 }
178 
179 #endif
void setChanged()
Definition: TreeParameter.cpp:917
CTreeParameter & operator++()
Definition: TreeParameter.cpp:584
void Initialize(std::string name, unsigned resolution)
Definition: TreeParameter.cpp:411
static void nextEvent()
Definition: TreeParameter.cpp:128
void setStop(double high)
Definition: TreeParameter.cpp:770
static void setDefaultLimits(double low, double high)
Definition: TreeParameter.cpp:160
double getValue() const
Definition: TreeParameter.cpp:647
std::string getName() const
Definition: TreeParameter.cpp:616
CTreeParameter & operator=(double newValue)
Definition: TreeParameter.cpp:517
double getStart() const
Definition: TreeParameter.cpp:726
Definition: TreeParameter.h:46
Definition: TreeParameter.h:42
CTreeParameter & operator--()
Definition: TreeParameter.cpp:603
static std::vector< std::pair< unsigned, double > > collectEvent()
Definition: TreeParameter.cpp:144
~CTreeParameter()
Definition: TreeParameter.cpp:396
std::string getUnit() const
Definition: TreeParameter.cpp:830
void Reset()
Definition: TreeParameter.cpp:891
CTreeParameter & operator+=(double rhs)
Definition: TreeParameter.cpp:537
CTreeParameter()
Definition: TreeParameter.cpp:295
static void setDefaultBins(unsigned bins)
Definition: TreeParameter.cpp:172
void resetChanged()
Definition: TreeParameter.cpp:930
void setUnit(std::string units)
Definition: TreeParameter.cpp:845
static void ResetAll()
Definition: TreeParameter.cpp:944
void setInc(double channelWidth)
Definition: TreeParameter.cpp:807
double getInc() const
Definition: TreeParameter.cpp:788
CTreeParameter & operator/=(double rhs)
Definition: TreeParameter.cpp:565
static void setEvent(...)
Definition: TreeParameter.cpp:199
bool isBound() const
Definition: TreeParameter.cpp:493
static void setDefaultUnits(const char *units)
Definition: TreeParameter.cpp:182
CTreeParameter & operator-=(double rhs)
Definition: TreeParameter.cpp:547
bool isValid() const
Definition: TreeParameter.cpp:860
unsigned getId() const
Definition: TreeParameter.cpp:627
static void BindParameters()
Definition: TreeParameter.cpp:192
static std::vector< std::pair< std::string, SharedData > > getDefinitions()
Definition: TreeParameter.cpp:224
void setBins(unsigned channels)
Definition: TreeParameter.cpp:708
double getStop() const
Definition: TreeParameter.cpp:756
bool hasChanged() const
Definition: TreeParameter.cpp:904
static const std::vector< double > & getEvent()
Definition: TreeParameter.cpp:206
CTreeParameter & operator*=(double rhs)
Definition: TreeParameter.cpp:556
void setStart(double low)
Definition: TreeParameter.cpp:741
void setInvalid()
Definition: TreeParameter.cpp:876
static const std::vector< unsigned > getScoreboard()
Definition: TreeParameter.cpp:214
void Bind()
Definition: TreeParameter.cpp:954
unsigned getBins() const
Definition: TreeParameter.cpp:691
Definition: AbstractApplication.cpp:30
void setValue(double newValue)
Definition: TreeParameter.cpp:670