Jpp
JModuleLocation.hh
Go to the documentation of this file.
1 #ifndef __JDETECTOR__JMODULELOCATION__
2 #define __JDETECTOR__JMODULELOCATION__
3 
4 #include <istream>
5 #include <ostream>
6 #include <iomanip>
7 #include <string>
8 
9 #include "JLang/JComparable.hh"
10 #include "JLang/JString.hh"
11 #include "JIO/JSerialisable.hh"
12 
13 
14 /**
15  * \file
16  *
17  * Logical location of module.
18  * \author mdejong
19  */
20 namespace JDETECTOR {}
21 namespace JPP { using namespace JDETECTOR; }
22 
23 namespace JDETECTOR {
24 
25  using JLANG::JComparable;
26  using JIO::JReader;
27  using JIO::JWriter;
28 
29 
30  /**
31  * Logical location of module.
32  *
33  * The logical location of a module consists of a string and floor number.
34  * This class implements the JLANG::JComparable interface.
35  */
37  public JComparable<JModuleLocation>
38  {
39  public:
40  /**
41  * Default constructor.
42  */
44  string(-1),
45  floor (-1)
46  {}
47 
48 
49  /**
50  * Constructor.
51  *
52  * \param string string
53  * \param floor floor
54  */
55  JModuleLocation(const int string,
56  const int floor)
57  {
58  this->string = string;
59  this->floor = floor;
60  }
61 
62 
63  /**
64  * Get location.
65  *
66  * \return location
67  */
69  {
70  return static_cast<const JModuleLocation&>(*this);
71  }
72 
73 
74  /**
75  * Get location.
76  *
77  * \return location
78  */
80  {
81  return static_cast<JModuleLocation&>(*this);
82  }
83 
84 
85  /**
86  * Set location.
87  *
88  * \param location location
89  */
90  void setLocation(const JModuleLocation& location)
91  {
92  static_cast<JModuleLocation&>(*this) = location;
93  }
94 
95 
96  /**
97  * Convert module location to string.
98  *
99  * \return string
100  */
101  std::string toString() const
102  {
103  return toString("% %");
104  }
105 
106 
107  /**
108  * Convert module loation to string.
109  *
110  * The targets <tt>target</tt> in the format string <tt>fmt</tt> are
111  * consecutively replaced by <tt>floor</tt> and <tt>string</tt>.
112  *
113  * \param fmt format
114  * \param target target
115  * \return string
116  */
117  std::string toString(const std::string& fmt, const std::string target = "%") const
118  {
119  JLANG::JString buffer(fmt);
120 
121  buffer.replace(target, string, 1);
122  buffer.replace(target, floor, 1);
123 
124  return buffer;
125  }
126 
127 
128  /**
129  * Get string number.
130  *
131  * \return string number
132  */
133  int getString() const
134  {
135  return string;
136  }
137 
138 
139  /**
140  * Get floor number.
141  *
142  * \return floor number
143  */
144  int getFloor() const
145  {
146  return floor;
147  }
148 
149 
150  /**
151  * Less than method.
152  *
153  * \param location module location
154  * \result true if first location before second location; else false
155  */
156  bool less(const JModuleLocation& location) const
157  {
158  if (this->getString() == location.getString())
159  return this->getFloor() < location.getFloor();
160  else
161  return this->getString() < location.getString();
162  }
163 
164 
165  /**
166  * Read module location from input.
167  *
168  * \param in input stream
169  * \param location module location
170  * \return input stream
171  */
172  friend inline std::istream& operator>>(std::istream& in, JModuleLocation& location)
173  {
174  in >> location.string;
175  in >> location.floor;
176 
177  return in;
178  }
179 
180 
181  /**
182  * Write module location to output.
183  *
184  * \param out output stream
185  * \param location module location
186  * \return output stream
187  */
188  friend inline std::ostream& operator<<(std::ostream& out, const JModuleLocation& location)
189  {
190  using namespace std;
191 
192  out << setw(3) << location.string;
193  out << ' ';
194  out << setw(2) << location.floor;
195 
196  return out;
197  }
198 
199 
200  /**
201  * Read module location from input.
202  *
203  * \param in reader
204  * \param location module location
205  * \return reader
206  */
207  friend inline JReader& operator>>(JReader& in, JModuleLocation& location)
208  {
209  in >> location.string;
210  in >> location.floor;
211 
212  return in;
213  }
214 
215 
216  /**
217  * Write module location to output.
218  *
219  * \param out writer
220  * \param location module location
221  * \return writer
222  */
223  friend inline JWriter& operator<<(JWriter& out, const JModuleLocation& location)
224  {
225  out << location.string;
226  out << location.floor;
227 
228  return out;
229  }
230 
231 
232  protected:
233  int string;
234  int floor;
235  };
236 }
237 
238 #endif
JDETECTOR::JModuleLocation::operator<<
friend JWriter & operator<<(JWriter &out, const JModuleLocation &location)
Write module location to output.
Definition: JModuleLocation.hh:223
JIO::JReader
Interface for binary input.
Definition: JSerialisable.hh:62
JDETECTOR::JModuleLocation::operator>>
friend std::istream & operator>>(std::istream &in, JModuleLocation &location)
Read module location from input.
Definition: JModuleLocation.hh:172
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::JModuleLocation::less
bool less(const JModuleLocation &location) const
Less than method.
Definition: JModuleLocation.hh:156
JDETECTOR::JModuleLocation::floor
int floor
Definition: JModuleLocation.hh:234
JDETECTOR::JModuleLocation::toString
std::string toString(const std::string &fmt, const std::string target="%") const
Convert module loation to string.
Definition: JModuleLocation.hh:117
JString.hh
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JDETECTOR::JModuleLocation
Logical location of module.
Definition: JModuleLocation.hh:36
JDETECTOR::JModuleLocation::getLocation
JModuleLocation & getLocation()
Get location.
Definition: JModuleLocation.hh:79
JSerialisable.hh
JComparable.hh
JDETECTOR::JModuleLocation::string
int string
Definition: JModuleLocation.hh:233
JLANG::JString
Wrapper class around STL string class.
Definition: JString.hh:28
JIO::JWriter
Interface for binary output.
Definition: JSerialisable.hh:130
JDETECTOR::JModuleLocation::toString
std::string toString() const
Convert module location to string.
Definition: JModuleLocation.hh:101
JDETECTOR::JModuleLocation::getLocation
const JModuleLocation & getLocation() const
Get location.
Definition: JModuleLocation.hh:68
JDETECTOR::JModuleLocation::operator<<
friend std::ostream & operator<<(std::ostream &out, const JModuleLocation &location)
Write module location to output.
Definition: JModuleLocation.hh:188
JDETECTOR::JModuleLocation::setLocation
void setLocation(const JModuleLocation &location)
Set location.
Definition: JModuleLocation.hh:90
JLANG::JComparable
Template definition of auxiliary base class for comparison of data structures.
Definition: JComparable.hh:24
JDETECTOR::JModuleLocation::JModuleLocation
JModuleLocation(const int string, const int floor)
Constructor.
Definition: JModuleLocation.hh:55
JDETECTOR::JModuleLocation::JModuleLocation
JModuleLocation()
Default constructor.
Definition: JModuleLocation.hh:43
std
Definition: jaanetDictionary.h:36
JDETECTOR::JModuleLocation::getFloor
int getFloor() const
Get floor number.
Definition: JModuleLocation.hh:144
JDETECTOR
Auxiliary classes and methods for detector calibration.
Definition: JAnchor.hh:12
JDETECTOR::JModuleLocation::getString
int getString() const
Get string number.
Definition: JModuleLocation.hh:133
JDETECTOR::JModuleLocation::operator>>
friend JReader & operator>>(JReader &in, JModuleLocation &location)
Read module location from input.
Definition: JModuleLocation.hh:207