Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
JModuleAddressMap.hh
Go to the documentation of this file.
1#ifndef __JDETECTOR__JMODULEADDRESSMAP__
2#define __JDETECTOR__JMODULEADDRESSMAP__
3
4#include <string>
5#include <vector>
6#include <algorithm>
7
9#include "JLang/JString.hh"
10#include "JLang/JException.hh"
13
14
15/**
16 * \author mdejong
17 */
18
19namespace JDETECTOR {}
20namespace JPP { using namespace JDETECTOR; }
21
22namespace JDETECTOR {
23
25 using JLANG::JTYPELIST;
27
28 /**
29 * Data structure to translate PMT physical to readout address.
30 */
32 public JPMTReadoutAddress,
34 public JMultiComparable<JPMTAddressTranslator, JTYPELIST<JPMTReadoutAddress, JPMTPhysicalAddress>::typelist>
35 {
36 /**
37 * Constructor.
38 *
39 * \param readout readout address
40 * \param address physical address
41 */
43 const JPMTPhysicalAddress& address) :
44 JPMTReadoutAddress (readout),
45 JPMTPhysicalAddress(address)
46 {}
47
48
49 /**
50 * Convert PMT address translator to string.
51 *
52 * \return string
53 */
54 std::string toString() const
55 {
56 return toString("% % %");
57 }
58
59
60 /**
61 * Convert PMT address translator to string.
62 *
63 * The targets <tt>target</tt> in the format string <tt>fmt</tt> are
64 * consecutively replaced by <tt>tdc</tt>, <tt>ring</tt> and <tt>position</tt>.
65 *
66 * \param fmt format
67 * \param target target
68 * \return string
69 */
70 std::string toString(const std::string& fmt, const std::string target = "%") const
71 {
72 JLANG::JString buffer(fmt);
73
74 buffer.replace(target, tdc, 1);
75 buffer.replace(target, ring, 1);
76 buffer.replace(target, position, 1);
77
78 return buffer;
79 }
80 };
81
82
83 /**
84 * Lookup table for PMT addresses in optical module.
85 */
87 public std::vector<JPMTAddressTranslator>
88 {
89 public:
90 /**
91 * Default constructor.
92 *
93 * The list of valid PMT address translations should be build according to the detector type.
94 * The internal router is used to convert a readout channel (TDC) to a PMT readout address.
95 */
99
100
101 /**
102 * Test whether index is available.
103 *
104 * \param index index
105 * \return true if index is available; else false
106 */
107 bool has(const int index) const
108 {
109 return (index >= 0 && index < (int) this->size());
110 }
111
112
113 /**
114 * Test whether TDC is available.
115 *
116 * \param tdc TDC
117 * \return true if TDC is available; else false
118 */
119 bool hasTDC(const int tdc) const
120 {
121 return (tdc >= 0 && tdc < (int) router.size() && router[tdc] != -1);
122 }
123
124
125 /**
126 * Test whether PMT is available.
127 *
128 * \param address PMT address
129 * \return true if PMT is available; else false
130 */
131 bool hasPMT(const JPMTPhysicalAddress& address) const
132 {
133 using namespace std;
134
135 const_iterator p = lower_bound(this->begin(), this->end(), address, less<JPMTPhysicalAddress>());
136
137 return (p != this->end() && *p == address);
138 }
139
140
141 /**
142 * Configure internal router.
143 */
145 {
146 using namespace std;
147
148 sort(this->begin(), this->end(), less<JPMTPhysicalAddress>());
149
150 for (const_iterator i = this->begin(); i != this->end(); ++i) {
151
152 if (i->tdc >= (int) router.size()) {
153 router.resize(i->tdc + 1, -1);
154 }
155
156 router[i->tdc] = std::distance(const_iterator(this->begin()),i);
157 }
158 }
159
160
161 /**
162 * Swap readout addresses corresponding to indices.
163 *
164 * \param i1 first index
165 * \param i2 second index
166 */
167 void swap(const int i1, const int i2)
168 {
169 std::swap(router[at(i1).tdc],
170 router[at(i2).tdc]);
171
172 std::swap(static_cast<JPMTReadoutAddress&>(at(i1)),
173 static_cast<JPMTReadoutAddress&>(at(i2)));
174 }
175
176
177 /**
178 * Swap physical addresses corresponding to TDCs.
179 *
180 * \param tdc1 first TDC
181 * \param tdc2 second TDC
182 */
183 void swapTDC(const int tdc1, const int tdc2)
184 {
185 std::swap(static_cast<JPMTReadoutAddress&>(at(router[tdc1])),
186 static_cast<JPMTReadoutAddress&>(at(router[tdc2])));
187
188 std::swap(router[tdc1],
189 router[tdc2]);
190 }
191
192
193 /**
194 * Swap readout addresses corresponding to PMTs.
195 *
196 * \param pmt1 first PMT
197 * \param pmt2 second PMT
198 */
199 void swapPMT(const JPMTPhysicalAddress& pmt1,const JPMTPhysicalAddress& pmt2)
200 {
202 }
203
204
205 /**
206 * Swap readout addresses by right rotation of physical addresses of PMTs in a given ring.
207 *
208 * \param ring ring
209 */
210 void rotateR(const char ring)
211 {
212 if (ring != 'A') {
218 }
219 }
220
221
222 /**
223 * Swap readout addresses by left rotation of physical addresses of PMTs in a given ring.
224 *
225 * \param ring ring
226 */
227 void rotateL(const char ring)
228 {
229 if (ring != 'A') {
235 }
236 }
237
238
239 /**
240 * Get PMT logical index for given TDC channel.
241 *
242 * \param tdc TDC
243 * \return PMT logical index
244 */
245 int getIndex(const int tdc) const
246 {
247 return router.at(tdc);
248 }
249
250
251 /**
252 * Get PMT address translator.
253 *
254 * \param tdc TDC
255 * \return PMT address translator
256 */
257 const JPMTAddressTranslator& getAddressTranslator(const int tdc) const
258 {
259 return at(getIndex(tdc));
260 }
261
262
263 /**
264 * Get PMT physical address.
265 *
266 * \param tdc TDC
267 * \return PMT physical address
268 */
269 const JPMTPhysicalAddress& getPMTPhysicalAddress(const int tdc) const
270 {
271 return getAddressTranslator(tdc);
272 }
273
274
275 /**
276 * Get PMT address translator.
277 *
278 * \param address PMT physical address
279 * \return PMT address translator
280 */
282 {
283 using namespace std;
284
285 const_iterator p = lower_bound(this->begin(), this->end(), address, less<JPMTPhysicalAddress>());
286
287 if (p != this->end() && *p == address)
288 return *p;
289 else
290 THROW(JIndexOutOfRange, "Invalid PMT address " << address);
291 }
292
293
294 /**
295 * Get PMT readout address.
296 *
297 * \param address PMT physical address
298 * \return PMT readout address
299 */
301 {
302 return getAddressTranslator(address);
303 }
304
305
306 protected:
308 };
309}
310
311#endif
Exceptions.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Lookup table for PMT addresses in optical module.
void rotateL(const char ring)
Swap readout addresses by left rotation of physical addresses of PMTs in a given ring.
void swapPMT(const JPMTPhysicalAddress &pmt1, const JPMTPhysicalAddress &pmt2)
Swap readout addresses corresponding to PMTs.
void swap(const int i1, const int i2)
Swap readout addresses corresponding to indices.
void swapTDC(const int tdc1, const int tdc2)
Swap physical addresses corresponding to TDCs.
const JPMTAddressTranslator & getAddressTranslator(const int tdc) const
Get PMT address translator.
JModuleAddressMap()
Default constructor.
bool hasPMT(const JPMTPhysicalAddress &address) const
Test whether PMT is available.
const JPMTPhysicalAddress & getPMTPhysicalAddress(const int tdc) const
Get PMT physical address.
void configure()
Configure internal router.
const JPMTReadoutAddress & getPMTReadoutAddress(const JPMTPhysicalAddress &address) const
Get PMT readout address.
const JPMTAddressTranslator & getAddressTranslator(const JPMTPhysicalAddress &address) const
Get PMT address translator.
int getIndex(const int tdc) const
Get PMT logical index for given TDC channel.
bool hasTDC(const int tdc) const
Test whether TDC is available.
void rotateR(const char ring)
Swap readout addresses by right rotation of physical addresses of PMTs in a given ring.
bool has(const int index) const
Test whether index is available.
Data structure for PMT physical address.
int position
position within ring [1,6]
Data structure for PMT readout address.
Exception for accessing an index in a collection that is outside of its range.
Wrapper class around STL string class.
Definition JString.hh:29
JString & replace(const char target, const char replacement, const std::size_t max=std::numeric_limits< std::size_t >::max())
Replace characters.
Definition JString.hh:170
file Auxiliary data structures and methods for detector calibration.
Definition JAnchor.hh:12
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Data structure to translate PMT physical to readout address.
std::string toString(const std::string &fmt, const std::string target="%") const
Convert PMT address translator to string.
std::string toString() const
Convert PMT address translator to string.
JPMTAddressTranslator(const JPMTReadoutAddress &readout, const JPMTPhysicalAddress &address)
Constructor.
Template definition of auxiliary base class for composite data structures composed of base classes wi...
Auxiliary class for recursive type list generation.
Definition JTypeList.hh:351