Jpp 19.3.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
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
17namespace JSUPPORT {}
18namespace JPP { using namespace JSUPPORT; }
19
20namespace 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),
62 {
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 {
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
113
114 for (int i = 0; i != NUMBER_OF_PMTS; ++i) {
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
KM3NeT DAQ constants, bit handling, etc.
Exceptions.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
Exception for accessing a value in a collection that is outside of its range.
Router for fast addressing of summary data in KM3NETDAQ::JDAQSummaryslice data structure as a functio...
bool hasSummaryFrame(const JDAQModuleIdentifier &module) const
Has summary frame.
static const int MODULE_IDENTIFIER
module identifier to allow default
bool is_valid() const
Check validity of summary data.
JSummaryRouter(const double rate_Hz)
Constructor with default rate.
double getRate(const JDAQPMTIdentifier &id) const
Get rate.
JSummaryRouter()
Default constructor.
bool hasDefault() const
Has default.
const JDAQSummaryslice * summary
const int getAddress(const JDAQModuleIdentifier &module) const
Get address of module.
const JDAQSummaryslice * getSummaryslice() const
Get summary slice.
double getRate() const
Get default rate.
const JDAQSummaryFrame & getSummaryFrame(const JDAQModuleIdentifier &module) const
Get summary frame.
const JDAQSummaryFrame & getSummaryFrame() const
Get default summary frame.
void update(const JDAQSummaryslice *ps)
Update router.
void setDefault(const double rate_Hz)
Set default.
Direct addressing of elements with unique identifiers.
Definition JRouter.hh:27
static const JDAQFrameStatus & getInstance()
Get reference to unique instance of this class object.
void setDAQFrameStatus(const JDAQFrameStatus &status)
Set DAQ frame status.
int getModuleID() const
Get module identifier.
void setModuleIdentifier(const JDAQModuleIdentifier &module)
Set Module identifier.
Data storage class for rate measurement of one PMT.
Data storage class for rate measurements of all PMTs in one module.
double getRate(const int tdc, const double factor=1.0) const
Get count rate.
void setRate(const int tdc, const double rate_Hz)
Set count rate.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Support classes and methods for experiment specific I/O.
KM3NeT DAQ data structures and auxiliaries.
Definition DataQueue.cc:39
static const int NUMBER_OF_PMTS
Total number of PMTs in module.
Definition JDAQ.hh:26