Jpp  17.3.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  {}
50 
51 
52  /**
53  * Constructor with default rate.
54  *
55  * \param rate_Hz singles rate [Hz]
56  */
57  JSummaryRouter(const double rate_Hz) :
58  router (-1),
59  summary(NULL)
60  {
61  setDefault(rate_Hz);
62  }
63 
64 
65  /**
66  * Get default summary frame.
67  *
68  * \return summary frame
69  */
71  {
72  return frame;
73  }
74 
75 
76  /**
77  * Get default rate.
78  *
79  * \return rate [Hz]
80  */
81  double getRate() const
82  {
83  return frame.getRate(0);
84  }
85 
86 
87  /**
88  * Has default.
89  *
90  * \return true if default has been set; else false
91  */
92  bool hasDefault() const
93  {
94  return (frame.getModuleID() == MODULE_IDENTIFIER);
95  }
96 
97 
98  /**
99  * Set default.
100  *
101  * \param rate_Hz rate [Hz]
102  */
103  void setDefault(const double rate_Hz)
104  {
105  using namespace KM3NETDAQ;
106 
107  frame.setModuleIdentifier(MODULE_IDENTIFIER); // allow default
109 
110  for (int i = 0; i != NUMBER_OF_PMTS; ++i) {
111  frame.setRate(i, rate_Hz);
112  }
113  }
114 
115 
116  /**
117  * Unset default.
118  */
120  {
121  using namespace KM3NETDAQ;
122 
123  frame.setModuleIdentifier(JDAQModuleIdentifier()); // disallow default
124  frame.setDAQFrameStatus(JDAQFrameStatus()); // invalid status
125 
126  for (int i = 0; i != NUMBER_OF_PMTS; ++i) {
127  frame[i] = JDAQRate();
128  }
129  }
130 
131 
132  /**
133  * Update router.
134  *
135  * \param ps pointer to new summary slice
136  */
137  void update(const JDAQSummaryslice* ps)
138  {
139  // reset internal router
140 
141  if (summary != NULL) {
142  for (JDAQSummaryslice::const_iterator i = summary->begin(); i != summary->end(); ++i) {
143  router.put(i->getModuleID(), router.getDefaultAddress());
144  }
145  }
146 
147  summary = ps;
148 
149  if (summary != NULL) {
150 
151  // set internal router
152 
153  for (JDAQSummaryslice::const_iterator i = summary->begin(); i != summary->end(); ++i) {
154  router.put(i->getModuleID(), distance(summary->begin(), i));
155  }
156  }
157  }
158 
159 
160  /**
161  * Check validity of summary data.
162  *
163  * \return true if summary data available; else false
164  */
165  bool is_valid() const
166  {
167  return summary != NULL;
168  }
169 
170 
171  /**
172  * Get summary slice.
173  *
174  * pointer to summary slice (may be NULL)
175  */
177  {
178  return summary;
179  }
180 
181 
182  /**
183  * Get address of module.
184  *
185  * \param module module
186  * \return address
187  */
188  const int getAddress(const JDAQModuleIdentifier& module) const
189  {
190  return router.get(module.getModuleID());
191  }
192 
193 
194  /**
195  * Has summary frame.
196  *
197  * \param module module
198  * \return true if module present; else false
199  */
200  bool hasSummaryFrame(const JDAQModuleIdentifier& module) const
201  {
202  return router.has(module.getModuleID()) || this->hasDefault();
203  }
204 
205 
206  /**
207  * Get summary frame.
208  *
209  * \param module module
210  * \return summary frame
211  */
213  {
214  if (router.has(module.getModuleID()))
215  return (*summary)[getAddress(module)];
216  else if (this->hasDefault())
217  return frame;
218  else
219  THROW(JValueOutOfRange, "Invalid module identifier " << module);
220  }
221 
222 
223  /**
224  * Get rate.
225  *
226  * \param id PMT identifier
227  * \return rate [Hz]
228  */
229  double getRate(const JDAQPMTIdentifier& id) const
230  {
231  double R = 0.0;
232 
233  if (this->hasSummaryFrame(id.getModuleIdentifier())) {
234  R = this->getSummaryFrame(id.getModuleIdentifier()).getRate(id.getPMTAddress());
235  }
236 
237  if (R < this->getRate()) {
238  R = this->getRate();
239  }
240 
241  return R;
242  }
243 
244  static const int MODULE_IDENTIFIER = 1; //!< module identifier to allow default
245 
246  private:
250  };
251 }
252 
253 #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:696
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:162
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