Jpp
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 
8 #include "JLang/JString.hh"
9 #include "JLang/JException.hh"
12 
13 
14 /**
15  * \author mdejong
16  */
17 
18 namespace JDETECTOR {}
19 namespace JPP { using namespace JDETECTOR; }
20 
21 namespace JDETECTOR {
22 
24 
25  /**
26  * Data structure to translate PMT physical to readout address.
27  */
29  public JPMTReadoutAddress,
30  public JPMTPhysicalAddress
31  {
32  /**
33  * Constructor.
34  *
35  * \param readout readout address
36  * \param address physical address
37  */
39  const JPMTPhysicalAddress& address) :
40  JPMTReadoutAddress (readout),
41  JPMTPhysicalAddress(address)
42  {}
43 
44 
45  /**
46  * Convert PMT address translator to string.
47  *
48  * \return string
49  */
50  std::string toString() const
51  {
52  return toString("% % %");
53  }
54 
55 
56  /**
57  * Convert PMT address translator to string.
58  *
59  * The targets <tt>target</tt> in the format string <tt>fmt</tt> are
60  * consecutively replaced by <tt>tdc</tt>, <tt>ring</tt> and <tt>position</tt>.
61  *
62  * \param fmt format
63  * \param target target
64  * \return string
65  */
66  std::string toString(const std::string& fmt, const std::string target = "%") const
67  {
68  JLANG::JString buffer(fmt);
69 
70  buffer.replace(target, tdc, 1);
71  buffer.replace(target, ring, 1);
72  buffer.replace(target, position, 1);
73 
74  return buffer;
75  }
76  };
77 
78 
79  /**
80  * Lookup table for PMT addresses in optical module.
81  */
83  public std::vector<JPMTAddressTranslator>
84  {
85  public:
86  /**
87  * Default constructor.
88  *
89  * The list of valid PMT address translations should be build according to the detector type.
90  * The internal router is used to convert a readout channel (TDC) to a PMT readout address.
91  */
93  std::vector<JPMTAddressTranslator>()
94  {}
95 
96 
97  /**
98  * Test whether index is available.
99  *
100  * \param index index
101  * \return true if index is available; else false
102  */
103  bool has(const int index) const
104  {
105  return (index >= 0 && index < (int) this->size());
106  }
107 
108 
109  /**
110  * Test whether TDC is available.
111  *
112  * \param tdc TDC
113  * \return true if TDC is available; else false
114  */
115  bool hasTDC(const int tdc) const
116  {
117  return (tdc >= 0 && tdc < (int) router.size() && router[tdc] != -1);
118  }
119 
120 
121  /**
122  * Test whether PMT is available.
123  *
124  * \param address PMT address
125  * \return true if PMT is available; else false
126  */
127  bool hasPMT(const JPMTPhysicalAddress& address) const
128  {
129  using namespace std;
130 
131  const_iterator p = lower_bound(this->begin(), this->end(), address, less<JPMTPhysicalAddress>());
132 
133  return (p != this->end() && *p == address);
134  }
135 
136 
137  /**
138  * Configure internal router.
139  */
140  void configure()
141  {
142  using namespace std;
143 
144  sort(this->begin(), this->end(), less<JPMTPhysicalAddress>());
145 
146  for (const_iterator i = this->begin(); i != this->end(); ++i) {
147 
148  if (i->tdc >= (int) router.size()) {
149  router.resize(i->tdc + 1, -1);
150  }
151 
152  router[i->tdc] = std::distance(const_iterator(this->begin()),i);
153  }
154  }
155 
156 
157  /**
158  * Swap readout addresses corresponding to indices.
159  *
160  * \param i1 first index
161  * \param i2 second index
162  */
163  void swap(const int i1, const int i2)
164  {
165  std::swap(router[at(i1).tdc],
166  router[at(i2).tdc]);
167 
168  std::swap(static_cast<JPMTReadoutAddress&>(at(i1)),
169  static_cast<JPMTReadoutAddress&>(at(i2)));
170  }
171 
172 
173  /**
174  * Swap physical addresses corresponding to TDCs.
175  *
176  * \param tdc1 first TDC
177  * \param tdc2 second TDC
178  */
179  void swapTDC(const int tdc1, const int tdc2)
180  {
181  std::swap(static_cast<JPMTReadoutAddress&>(at(router[tdc1])),
182  static_cast<JPMTReadoutAddress&>(at(router[tdc2])));
183 
184  std::swap(router[tdc1],
185  router[tdc2]);
186 
187  }
188 
189 
190  /**
191  * Get PMT logical index for given TDC channel.
192  *
193  * \param tdc TDC
194  * \return PMT logical index
195  */
196  int getIndex(const int tdc) const
197  {
198  return router.at(tdc);
199  }
200 
201 
202  /**
203  * Get PMT address translator.
204  *
205  * \param tdc TDC
206  * \return PMT address translator
207  */
208  const JPMTAddressTranslator& getAddressTranslator(const int tdc) const
209  {
210  return at(getIndex(tdc));
211  }
212 
213 
214  /**
215  * Get PMT address translator.
216  *
217  * \param address PMT address
218  * \return PMT address translator
219  */
221  {
222  using namespace std;
223 
224  const_iterator p = lower_bound(this->begin(), this->end(), address, less<JPMTPhysicalAddress>());
225 
226  if (p != this->end() && *p == address)
227  return *p;
228  else
229  THROW(JIndexOutOfRange, "Invalid PMT address " << address);
230  }
231 
232 
233  //protected:
235  };
236 }
237 
238 #endif
JException.hh
JDETECTOR::JModuleAddressMap::swapTDC
void swapTDC(const int tdc1, const int tdc2)
Swap physical addresses corresponding to TDCs.
Definition: JModuleAddressMap.hh:179
JDETECTOR::JModuleAddressMap::JModuleAddressMap
JModuleAddressMap()
Default constructor.
Definition: JModuleAddressMap.hh:92
JLANG::JIndexOutOfRange
Exception for accessing an index in a collection that is outside of its range.
Definition: JException.hh:90
JLANG::JString::replace
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:189
JDETECTOR::JModuleAddressMap::swap
void swap(const int i1, const int i2)
Swap readout addresses corresponding to indices.
Definition: JModuleAddressMap.hh:163
JDETECTOR::JModuleAddressMap::has
bool has(const int index) const
Test whether index is available.
Definition: JModuleAddressMap.hh:103
JDETECTOR::JModuleAddressMap::getAddressTranslator
const JPMTAddressTranslator & getAddressTranslator(const JPMTPhysicalAddress &address) const
Get PMT address translator.
Definition: JModuleAddressMap.hh:220
JDETECTOR::JPMTPhysicalAddress
Data structure for PMT physical address.
Definition: JPMTPhysicalAddress.hh:26
std::vector
Definition: JSTDTypes.hh:12
distance
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
Definition: PhysicsEvent.hh:434
JDETECTOR::JModuleAddressMap
Lookup table for PMT addresses in optical module.
Definition: JModuleAddressMap.hh:82
JString.hh
JDETECTOR::JModuleAddressMap::getAddressTranslator
const JPMTAddressTranslator & getAddressTranslator(const int tdc) const
Get PMT address translator.
Definition: JModuleAddressMap.hh:208
JDETECTOR::JPMTAddressTranslator::toString
std::string toString() const
Convert PMT address translator to string.
Definition: JModuleAddressMap.hh:50
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JDETECTOR::JPMTPhysicalAddress::ring
char ring
ring number ['A','F']
Definition: JPMTPhysicalAddress.hh:144
JDETECTOR::JPMTPhysicalAddress::position
int position
position within ring [1,6]
Definition: JPMTPhysicalAddress.hh:145
JPMTPhysicalAddress.hh
JLANG::JString
Wrapper class around STL string class.
Definition: JString.hh:28
JDETECTOR::JModuleAddressMap::hasTDC
bool hasTDC(const int tdc) const
Test whether TDC is available.
Definition: JModuleAddressMap.hh:115
THROW
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:670
JDETECTOR::JPMTReadoutAddress::tdc
int tdc
TDC channel.
Definition: JPMTReadoutAddress.hh:113
JDETECTOR::JModuleAddressMap::hasPMT
bool hasPMT(const JPMTPhysicalAddress &address) const
Test whether PMT is available.
Definition: JModuleAddressMap.hh:127
JPMTReadoutAddress.hh
JDETECTOR::JModuleAddressMap::configure
void configure()
Configure internal router.
Definition: JModuleAddressMap.hh:140
JDETECTOR::JModuleAddressMap::router
std::vector< int > router
Definition: JModuleAddressMap.hh:234
std
Definition: jaanetDictionary.h:36
JDETECTOR::JPMTAddressTranslator::JPMTAddressTranslator
JPMTAddressTranslator(const JPMTReadoutAddress &readout, const JPMTPhysicalAddress &address)
Constructor.
Definition: JModuleAddressMap.hh:38
JDETECTOR::JPMTAddressTranslator::toString
std::string toString(const std::string &fmt, const std::string target="%") const
Convert PMT address translator to string.
Definition: JModuleAddressMap.hh:66
JDETECTOR::JPMTAddressTranslator
Data structure to translate PMT physical to readout address.
Definition: JModuleAddressMap.hh:28
JDETECTOR::JPMTReadoutAddress
Data structure for PMT readout address.
Definition: JPMTReadoutAddress.hh:27
JDETECTOR
Auxiliary classes and methods for detector calibration.
Definition: JAnchor.hh:12
JDETECTOR::JModuleAddressMap::getIndex
int getIndex(const int tdc) const
Get PMT logical index for given TDC channel.
Definition: JModuleAddressMap.hh:196