Jpp  15.0.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JSupport/JSummaryRouter.hh
Go to the documentation of this file.
1 #ifndef __JSUPPORT__JSUMMARYROUTER__
2 #define __JSUPPORT__JSUMMARYROUTER__
3 
7 
8 #include "JTools/JRouter.hh"
9 
10 
11 /**
12  * \author mdejong
13  */
14 
15 namespace JSUPPORT {}
16 namespace JPP { using namespace JSUPPORT; }
17 
18 namespace JSUPPORT {
19 
24 
25 
26  /**
27  * Router for fast addressing of summary data in JDAQSummaryslice data structure
28  * as a function of the optical module identifier and PMT address.
29  *
30  * The member method JSummaryRouter::update should be used to update the internal router for a given event.\n
31  * The member method JSummaryRouter::getRate can then be used to obtain the measured singles rate for a given PMT.\n
32  * Note that if there is no measured rate or if it is below the specified default rate, the default rate is taken.
33  */
35  public:
36  /**
37  * Constructor.
38  *
39  * \param rate_Hz default singles rate [Hz]
40  */
41  JSummaryRouter(const double rate_Hz = 0.0) :
43  router (-1),
44  summary(NULL)
45  {}
46 
47 
48  /**
49  * Get default rate.
50  *
51  * \return rate [Hz]
52  */
53  double getRate() const
54  {
55  return rate_Hz;
56  }
57 
58 
59  /**
60  * Set default rate.
61  *
62  * \param rate_Hz rate [Hz]
63  */
64  void setRate(const double rate_Hz)
65  {
66  this->rate_Hz = rate_Hz;
67  }
68 
69 
70  /**
71  * Update router.
72  *
73  * \param ps pointer to new summary slice
74  */
75  void update(const JDAQSummaryslice* ps)
76  {
77  // reset internal router
78 
79  if (summary != NULL) {
80  for (JDAQSummaryslice::const_iterator i = summary->begin(); i != summary->end(); ++i) {
81  router.put(i->getModuleID(), router.getDefaultAddress());
82  }
83  }
84 
85  summary = ps;
86 
87  if (summary != NULL) {
88 
89  // set internal router
90 
91  for (JDAQSummaryslice::const_iterator i = summary->begin(); i != summary->end(); ++i) {
92  router.put(i->getModuleID(), distance(summary->begin(), i));
93  }
94  }
95  }
96 
97 
98  /**
99  * Check validity of summary data.
100  *
101  * \return true if summary data available; else false
102  */
103  bool is_valid() const
104  {
105  return summary != NULL;
106  }
107 
108 
109  /**
110  * Get summary slice.
111  *
112  * pointer to summary slice (may be NULL)
113  */
115  {
116  return summary;
117  }
118 
119 
120  /**
121  * Get address of module.
122  *
123  * \param module module
124  * \return address
125  */
126  const int getAddress(const JDAQModuleIdentifier& module) const
127  {
128  return router.get(module.getModuleID());
129  }
130 
131 
132  /**
133  * Get summary frame.
134  *
135  * \param module module
136  * \return summary frame
137  */
139  {
140  return (*summary)[getAddress(module)];
141  }
142 
143 
144  /**
145  * Has summary frame.
146  *
147  * \param module module
148  * \return true if module present; else false
149  */
150  bool hasSummaryFrame(const JDAQModuleIdentifier& module) const
151  {
152  return router.has(module.getModuleID());
153  }
154 
155 
156  /**
157  * Get rate.
158  *
159  * \param id PMT identifier
160  * \return rate [Hz]
161  */
162  double getRate(const JDAQPMTIdentifier& id) const
163  {
164  if (this->hasSummaryFrame(id.getModuleIdentifier())) {
165 
166  const double R = this->getSummaryFrame(id.getModuleIdentifier()).getRate(id.getPMTAddress());
167 
168  if (R > rate_Hz) {
169  return R;
170  }
171  }
172 
173  return rate_Hz;
174  }
175 
176  private:
177  double rate_Hz;
180  };
181 }
182 
183 #endif
double getRate(const JDAQPMTIdentifier &id) const
Get rate.
void update(const JDAQSummaryslice *ps)
Update router.
int getModuleID() const
Get module identifier.
double getRate(const int tdc, const double factor=1.0) const
Get count rate.
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
double getRate() const
Get default rate.
const JDAQSummaryFrame & getSummaryFrame(const JDAQModuleIdentifier &module) const
Get summary frame.
const JDAQSummaryslice * getSummaryslice() const
Get summary slice.
bool is_valid() const
Check validity of summary data.
Data storage class for rate measurements of all PMTs in one module.
JSummaryRouter(const double rate_Hz=0.0)
Constructor.
Router for fast addressing of summary data in JDAQSummaryslice data structure as a function of the op...
then usage $script[distance] fi case set_variable R
Definition: JDrawLED.sh:43
bool hasSummaryFrame(const JDAQModuleIdentifier &module) const
Has summary frame.
const JDAQSummaryslice * summary
const int getAddress(const JDAQModuleIdentifier &module) const
Get address of module.
void setRate(const double rate_Hz)
Set default rate.