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