Jpp 19.3.0-rc.3
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 */
37 public:
38 /**
39 * Default constructor.
40 */
42 router (-1),
43 summary(NULL)
44 {}
45
46
47 /**
48 * Update router.
49 *
50 * \param ps pointer to new summary slice
51 */
52 void update(const JDAQSummaryslice* ps)
53 {
54 // reset internal router
55
56 if (summary != NULL) {
57 for (JDAQSummaryslice::const_iterator i = summary->begin(); i != summary->end(); ++i) {
58 router.put(i->getModuleID(), router.getDefaultAddress());
59 }
60 }
61
62 summary = ps;
63
64 if (summary != NULL) {
65
66 // set internal router
67
68 for (JDAQSummaryslice::const_iterator i = summary->begin(); i != summary->end(); ++i) {
69 router.put(i->getModuleID(), distance(summary->begin(), i));
70 }
71 }
72 }
73
74
75 /**
76 * Check validity of summary data.
77 *
78 * \return true if summary data available; else false
79 */
80 bool is_valid() const
81 {
82 return summary != NULL;
83 }
84
85
86 /**
87 * Get summary slice.
88 *
89 * \return pointer to summary slice (may be NULL)
90 */
92 {
93 return summary;
94 }
95
96
97 /**
98 * Get address of module.
99 *
100 * \param module module
101 * \return address
102 */
103 const int getAddress(const JDAQModuleIdentifier& module) const
104 {
105 return router.get(module.getModuleID());
106 }
107
108
109 /**
110 * Has summary frame.
111 *
112 * \param module module
113 * \return true if module present; else false
114 */
115 bool hasSummaryFrame(const JDAQModuleIdentifier& module) const
116 {
117 return router.has(module.getModuleID());
118 }
119
120
121 /**
122 * Get summary frame.
123 *
124 * \param module module
125 * \return summary frame
126 */
128 {
129 if (router.has(module.getModuleID()))
130 return (*summary)[getAddress(module)];
131 else
132 THROW(JValueOutOfRange, "Module identifier " << module);
133 }
134
135
136 /**
137 * Get summary frame.
138 *
139 * \param module module
140 * \param rate_Hz default rate [Hz]
141 * \return summary frame
142 */
143 const JDAQSummaryFrame& getSummaryFrame(const JDAQModuleIdentifier& module, const double rate_Hz) const
144 {
145 if (router.has(module.getModuleID())) {
146
147 return (*summary)[getAddress(module)];
148
149 } else {
150
153
154 for (int i = 0; i != NUMBER_OF_PMTS; ++i) {
155 frame.setRate(i, rate_Hz);
156 }
157
158 return frame;
159 }
160 }
161
162
163 /**
164 * Get rate.
165 *
166 * \param id PMT identifier
167 * \param rate_Hz default rate [Hz]
168 * \return rate [Hz]
169 */
170 double getRate(const JDAQPMTIdentifier& id, const double rate_Hz) const
171 {
172 double R = 0.0;
173
174 if (this->hasSummaryFrame(id.getModuleIdentifier())) {
175 R = this->getSummaryFrame(id.getModuleIdentifier()).getRate(id.getPMTAddress());
176 }
177
178 if (R < rate_Hz) {
179 R = rate_Hz;
180 }
181
182 return R;
183 }
184
185 private:
189 };
190}
191
192#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...
double getRate(const JDAQPMTIdentifier &id, const double rate_Hz) const
Get rate.
bool hasSummaryFrame(const JDAQModuleIdentifier &module) const
Has summary frame.
bool is_valid() const
Check validity of summary data.
JSummaryRouter()
Default constructor.
const JDAQSummaryslice * summary
const JDAQSummaryFrame & getSummaryFrame(const JDAQModuleIdentifier &module, const double rate_Hz) const
Get summary frame.
const int getAddress(const JDAQModuleIdentifier &module) const
Get address of module.
const JDAQSummaryslice * getSummaryslice() const
Get summary slice.
const JDAQSummaryFrame & getSummaryFrame(const JDAQModuleIdentifier &module) const
Get summary frame.
void update(const JDAQSummaryslice *ps)
Update router.
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 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.
static const int NUMBER_OF_PMTS
Total number of PMTs in module.
Definition JDAQ.hh:26