Jpp  18.6.0-rc.1
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 
8 
9 #include "JTools/JRouter.hh"
10 #include "JLang/JException.hh"
11 
12 
13 /**
14  * \author mdejong
15  */
16 
17 namespace JSUPPORT {}
18 namespace JPP { using namespace JSUPPORT; }
19 
20 namespace JSUPPORT {
21 
26 
27 
28  /**
29  * Router for fast addressing of summary data in KM3NETDAQ::JDAQSummaryslice data structure
30  * as a function of the optical module identifier and PMT address.
31  *
32  * The member method update() should be used to update the internal router for a given event.
33  * The member method getRate(const JDAQPMTIdentifier&) const can subsequently be used to obtain
34  * the measured singles rate for a given PMT.
35  *
36  * Optionally, a default rate can be set.
37  * In that case, a default KM3NETDAQ::JDAQSummaryFrame is setup which is used
38  * when no summary data are available or if the rate is below the specified default rate.\n
39  * Note that the default rate is subject to the limited accuracy of the summary data.
40  */
42  public:
43  /**
44  * Default constructor.
45  */
47  router (-1),
48  summary(NULL),
49  rate_Hz(0.0)
50  {}
51 
52 
53  /**
54  * Constructor with default rate.
55  *
56  * \param rate_Hz singles rate [Hz]
57  */
58  JSummaryRouter(const double rate_Hz) :
59  router (-1),
60  summary(NULL),
61  rate_Hz(rate_Hz)
62  {
63  setDefault(rate_Hz);
64  }
65 
66 
67  /**
68  * Get default summary frame.
69  *
70  * \return summary frame
71  */
73  {
74  return frame;
75  }
76 
77 
78  /**
79  * Get default rate.
80  *
81  * \return rate [Hz]
82  */
83  double getRate() const
84  {
85  return this->rate_Hz;
86  }
87 
88 
89  /**
90  * Has default.
91  *
92  * \return true if default has been set; else false
93  */
94  bool hasDefault() const
95  {
96  return (frame.getModuleID() == MODULE_IDENTIFIER);
97  }
98 
99 
100  /**
101  * Set default.
102  *
103  * \param rate_Hz rate [Hz]
104  */
105  void setDefault(const double rate_Hz)
106  {
107  using namespace KM3NETDAQ;
108 
109  this->rate_Hz = rate_Hz;
110 
111  frame.setModuleIdentifier(MODULE_IDENTIFIER); // allow default
113 
114  for (int i = 0; i != NUMBER_OF_PMTS; ++i) {
115  frame.setRate(i, rate_Hz);
116  }
117  }
118 
119 
120  /**
121  * Unset default.
122  */
124  {
125  using namespace KM3NETDAQ;
126 
127  frame.setModuleIdentifier(JDAQModuleIdentifier()); // disallow default
128  frame.setDAQFrameStatus(JDAQFrameStatus()); // invalid status
129 
130  for (int i = 0; i != NUMBER_OF_PMTS; ++i) {
131  frame[i] = JDAQRate();
132  }
133  }
134 
135 
136  /**
137  * Update router.
138  *
139  * \param ps pointer to new summary slice
140  */
141  void update(const JDAQSummaryslice* ps)
142  {
143  // reset internal router
144 
145  if (summary != NULL) {
146  for (JDAQSummaryslice::const_iterator i = summary->begin(); i != summary->end(); ++i) {
147  router.put(i->getModuleID(), router.getDefaultAddress());
148  }
149  }
150 
151  summary = ps;
152 
153  if (summary != NULL) {
154 
155  // set internal router
156 
157  for (JDAQSummaryslice::const_iterator i = summary->begin(); i != summary->end(); ++i) {
158  router.put(i->getModuleID(), distance(summary->begin(), i));
159  }
160  }
161  }
162 
163 
164  /**
165  * Check validity of summary data.
166  *
167  * \return true if summary data available; else false
168  */
169  bool is_valid() const
170  {
171  return summary != NULL;
172  }
173 
174 
175  /**
176  * Get summary slice.
177  *
178  * pointer to summary slice (may be NULL)
179  */
181  {
182  return summary;
183  }
184 
185 
186  /**
187  * Get address of module.
188  *
189  * \param module module
190  * \return address
191  */
192  const int getAddress(const JDAQModuleIdentifier& module) const
193  {
194  return router.get(module.getModuleID());
195  }
196 
197 
198  /**
199  * Has summary frame.
200  *
201  * \param module module
202  * \return true if module present; else false
203  */
204  bool hasSummaryFrame(const JDAQModuleIdentifier& module) const
205  {
206  return router.has(module.getModuleID()) || this->hasDefault();
207  }
208 
209 
210  /**
211  * Get summary frame.
212  *
213  * \param module module
214  * \return summary frame
215  */
217  {
218  if (router.has(module.getModuleID()))
219  return (*summary)[getAddress(module)];
220  else if (this->hasDefault())
221  return frame;
222  else
223  THROW(JValueOutOfRange, "Invalid module identifier " << module);
224  }
225 
226 
227  /**
228  * Get rate.
229  *
230  * \param id PMT identifier
231  * \return rate [Hz]
232  */
233  double getRate(const JDAQPMTIdentifier& id) const
234  {
235  double R = 0.0;
236 
237  if (this->hasSummaryFrame(id.getModuleIdentifier())) {
238  R = this->getSummaryFrame(id.getModuleIdentifier()).getRate(id.getPMTAddress());
239  }
240 
241  if (R < this->getRate()) {
242  R = this->getRate();
243  }
244 
245  return R;
246  }
247 
248  static const int MODULE_IDENTIFIER = 1; //!< module identifier to allow default
249 
250  private:
254  double rate_Hz;
255  };
256 }
257 
258 #endif
double getRate(const JDAQPMTIdentifier &id) const
Get rate.
Exceptions.
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.
bool hasDefault() const
Has default.
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
static const JDAQFrameStatus & getInstance()
Get reference to unique instance of this class object.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
double getRate() const
Get default rate.
const JDAQSummaryFrame & getSummaryFrame(const JDAQModuleIdentifier &module) const
Get summary frame.
void setDefault(const double rate_Hz)
Set default.
const JDAQSummaryFrame & getSummaryFrame() const
Get default summary frame.
static const int MODULE_IDENTIFIER
module identifier to allow default
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.
void unsetDefault()
Unset default.
Router for fast addressing of summary data in KM3NETDAQ::JDAQSummaryslice data structure as a functio...
then JCookie sh JDataQuality D $DETECTOR_ID R
Definition: JDataQuality.sh:41
JSummaryRouter(const double rate_Hz)
Constructor with default rate.
JSummaryRouter()
Default constructor.
Data storage class for rate measurement of one PMT.
void setModuleIdentifier(const JDAQModuleIdentifier &module)
Set Module identifier.
void setDAQFrameStatus(const JDAQFrameStatus &status)
Set DAQ frame status.
bool hasSummaryFrame(const JDAQModuleIdentifier &module) const
Has summary frame.
const JDAQSummaryslice * summary
Exception for accessing a value in a collection that is outside of its range.
Definition: JException.hh:178
const int getAddress(const JDAQModuleIdentifier &module) const
Get address of module.
void setRate(const int tdc, const double rate_Hz)
Set count rate.
KM3NeT DAQ constants, bit handling, etc.
static const int NUMBER_OF_PMTS
Total number of PMTs in module.
Definition: JDAQ.hh:26