Jpp 21.0.0
the software that should make you happy
Loading...
Searching...
No Matches
JTDC_t.hh
Go to the documentation of this file.
1#ifndef __JCALIBRATE_JTDC_t__
2#define __JCALIBRATE_JTDC_t__
3
4#include <istream>
5#include <ostream>
6#include <iomanip>
7#include <map>
8
10
12#include "JLang/JException.hh"
13#include "Jeep/JComment.hh"
14
15
16/**
17 * \author mdejong
18 */
19
20namespace JCALIBRATE {}
21namespace JPP { using namespace JCALIBRATE; }
22
23/**
24 * Auxiliary classes and methods for PMT calibration.
25 */
26namespace JCALIBRATE {
27
29 using KM3NETDAQ::NUMBER_OF_PMTS;
30 using JEEP::JComment;
31
32
33 /**
34 * Auxiliary class for TDC constraints.
35 */
36 struct JTDC_t :
37 public std::multimap<int, int> // module identifier -> TDC
38 {
40
41 /**
42 * Type definition for range of TDC constraints of a given module identfier.
43 */
45
46
47 /**
48 * Wild card for module identifier and TDC.
49 */
50 enum { WILDCARD = -1 };
51
52
53 /**
54 * Insert constraint.
55 *
56 * Note that if TDC equals JTDC_t::WILDCARD,
57 * all possible TDCs in the given module are inserted.
58 *
59 * \param value module identifier and TDC
60 */
61 void insert(const value_type& value)
62 {
63 if (value.second == WILDCARD) {
64
65 for (int pmt = 0; pmt != NUMBER_OF_PMTS; ++pmt) {
66 multimap_type::insert(value_type(value.first, pmt));
67 }
68
69 } else {
70
71 multimap_type::insert(value);
72 }
73 }
74
75
76 /**
77 * Insert constraint.
78 *
79 * Note that if TDC equals JTDC_t::WILDCARD,
80 * all possible TDCs in the given module are inserted.
81 *
82 * \param id module identifier
83 * \param tdc TDC
84 */
85 void insert(const int id, const int tdc)
86 {
87 this->insert(value_type(id, tdc));
88 }
89
90
91 /**
92 * Get range of constraints for given module.
93 *
94 * Note that if no data are available for given module identifier,
95 * the data corresponding to JTDC_t::WILDCARD are returned.
96 *
97 * \param id module identifier
98 * \return range of constraints
99 */
101 {
102 range_type range = multimap_type::equal_range(id);
103
104 if (range.first == range.second) {
105 range = multimap_type::equal_range(WILDCARD);
106 }
107
108 return range;
109 }
110
111
112 /**
113 * Check if TDC is constraint.
114 *
115 * \param id module identifier
116 * \param tdc TDC channel
117 * \return true if given TDC is constraint; else false
118 */
119 bool has(const int id, const int tdc)
120 {
121 const range_type range = equal_range(id);
122
123 for (JTDC_t::const_iterator i = range.first; i != range.second; ++i) {
124 if (tdc == i->second) {
125 return true;
126 }
127 }
128
129 return false;
130 }
131
132
133 /**
134 * Reverse constraints.
135 */
136 void reverse()
137 {
138 JTDC_t buffer;
139
140 for (JTDC_t::const_iterator p = this->begin(); p != this->end(); ) {
141
142 JTDC_t::const_iterator q = p;
143
144 for ( ; q != this->end() && q->first == p->first; ++q) {}
145
146 for (int pmt = 0; pmt != NUMBER_OF_PMTS; ++pmt) {
147
148 JTDC_t::const_iterator i = p;
149
150 for ( ; i != q && i->second != pmt; ++i) {}
151
152 if (i == q) {
153 buffer.insert(value_type(p->first, pmt));
154 }
155 }
156
157 p = q;
158 }
159
160 this->swap(buffer);
161 }
162
163
164 /**
165 * Check validity of TDC constrants.
166 *
167 * \param option option (if true, throw exception if not valid)
168 * \return true if valid; else false
169 */
170 bool is_valid(const bool option = false) const
171 {
172 for (const_iterator i = this->begin(); i != this->end(); ++i) {
173
174 if (i->first < WILDCARD) {
175
176 if (option) {
177 THROW(JValueOutOfRange, "Invalid module identifier: " << i->first << " < " << WILDCARD);
178 }
179
180 return false;
181 }
182
183 if (i->second < 0 || i->second >= NUMBER_OF_PMTS) {
184
185 if (option) {
186 THROW(JValueOutOfRange, "Invalid TDC: " << i->second << " {0, .., " << NUMBER_OF_PMTS - 1 << "}");
187 }
188
189 return false;
190 }
191 }
192
193 return true;
194 }
195
196
197 /**
198 * Read TDC constraints from input.
199 *
200 * \param in input stream
201 * \param tdc TDC constraints
202 * \return input stream
203 */
204 friend inline std::istream& operator>>(std::istream& in, JTDC_t& tdc)
205 {
206 using namespace std;
207 using namespace JPP;
208
209 JStringStream is(in);
210
211 is >> tdc.comment;
212
213 for (int id, pmt; is >> id >> pmt; ) {
214 tdc.insert(JTDC_t::value_type(id, pmt));
215 }
216
217 return in;
218 }
219
220
221 /**
222 * Write TDC constraints to output.
223 *
224 * \param out output stream
225 * \param tdc TDC constraints
226 * \return output stream
227 */
228 friend inline std::ostream& operator<<(std::ostream& out, const JTDC_t& tdc)
229 {
230 using namespace std;
231
232 out << tdc.comment;
233
234 for (JTDC_t::const_iterator i = tdc.begin(); i != tdc.end(); ++i) {
235 out << setw(10) << i->first << ' ' << setw(2) << i->second << endl;
236 }
237
238 return out;
239 }
240
242 };
243}
244
245#endif
KM3NeT DAQ constants, bit handling, etc.
Exceptions.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Wrapper class around STL stringstream class to facilitate optional loading of data from file.
Exception for accessing a value in a collection that is outside of its range.
Auxiliary classes and methods for PMT calibration.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary class for TDC constraints.
Definition JTDC_t.hh:38
std::multimap< int, int > multimap_type
Definition JTDC_t.hh:39
range_type equal_range(const int id)
Get range of constraints for given module.
Definition JTDC_t.hh:100
void reverse()
Reverse constraints.
Definition JTDC_t.hh:136
void insert(const value_type &value)
Insert constraint.
Definition JTDC_t.hh:61
JComment comment
Definition JTDC_t.hh:241
std::pair< const_iterator, const_iterator > range_type
Type definition for range of TDC constraints of a given module identfier.
Definition JTDC_t.hh:44
friend std::ostream & operator<<(std::ostream &out, const JTDC_t &tdc)
Write TDC constraints to output.
Definition JTDC_t.hh:228
friend std::istream & operator>>(std::istream &in, JTDC_t &tdc)
Read TDC constraints from input.
Definition JTDC_t.hh:204
bool has(const int id, const int tdc)
Check if TDC is constraint.
Definition JTDC_t.hh:119
bool is_valid(const bool option=false) const
Check validity of TDC constrants.
Definition JTDC_t.hh:170
void insert(const int id, const int tdc)
Insert constraint.
Definition JTDC_t.hh:85
Auxiliary class for comment.
Definition JComment.hh:43