Jpp
JProductRouter.hh
Go to the documentation of this file.
1 #ifndef __JDB__JPRODUCTROUTER__
2 #define __JDB__JPRODUCTROUTER__
3 
4 #include <ostream>
5 #include <map>
6 
8 #include "JDB/JPBS.hh"
9 #include "JDB/JUPI.hh"
10 #include "JLang/JComparable.hh"
11 #include "JLang/JVectorize.hh"
12 #include "JLang/JLangToolkit.hh"
13 
14 
15 /**
16  * \author mdejong
17  */
18 namespace JDATABASE {}
19 namespace JPP { using namespace JDATABASE; }
20 
21 namespace JDATABASE {
22 
23  /**
24  * Auxiliary data structure for location of product in detector.
25  */
26  struct JLocation_t :
27  public JLANG::JComparable<JLocation_t>
28  {
29  /**
30  * Default constructor.\n
31  * The default corresponds to an invalid location.
32  */
34  string (-1),
35  floor (-1),
36  position(-1)
37  {}
38 
39 
40  /**
41  * Constructor.
42  *
43  * \param string string
44  * \param floor floor
45  * \param position position
46  */
47  JLocation_t(const int string,
48  const int floor,
49  const int position) :
50  string (string),
51  floor (floor),
53  {}
54 
55 
56  /**
57  * Less-than method.
58  *
59  * \param location location
60  * \return true if this location less than given location; else false
61  */
62  bool less(const JLocation_t& location) const
63  {
64  if (this->string == location.string) {
65 
66  if (this->floor == location.floor)
67  return this->position < location.position;
68  else
69  return this->floor < location.floor;
70 
71  } else {
72 
73  return this->string < location.string;
74  }
75  }
76 
77 
78  /**
79  * Write location to output stream.
80  *
81  * \param out output stream
82  * \param object location
83  * \return output stream
84  */
85  friend inline std::ostream& operator<<(std::ostream& out, const JLocation_t& object)
86  {
87  using namespace std;
88 
89  return out << setw(3) << object.string << ' ' << setw(2) << object.floor << ' ' << setw(2) << object.position;
90  }
91 
92 
93  int string; //!< position in detector
94  int floor; //!< position in string
95  int position; //!< position in floor
96  };
97 
98 
99  /**
100  * Auxiliary class to map %UPI to location in detector.
101  */
102  struct JProductRouter :
103  private std::map<JUPI, JLocation_t>
104  {
105  /**
106  * Constructor.
107  *
108  * \param detector detector integration
109  */
111  {
112  using namespace std;
113  using namespace JPP;
114 
115  for (JDetectorIntegration::const_iterator i = detector.begin(); i != detector.end(); ++i) {
116 
117  if (i->has()) {
118 
119  {
120  const JPBS pbs[] = { PBS::DOM, PBS::DETECTION_UNIT, PBS::DETECTOR };
121 
122  const JProductTrace trace(detector, i->content.getUPI(), make_array(pbs));
123 
124  if (trace.size() == getSize(pbs)) {
125 
126  this->insert(make_pair(i->content.getUPI(), JLocation_t(trace[2].position, trace[1].position, trace[0].position)));
127 
128  continue;
129  }
130  }
131 
132  {
133  const JPBS pbs[] = { PBS::BASE, PBS::DETECTION_UNIT, PBS::DETECTOR };
134 
135  const JProductTrace trace(detector, i->content.getUPI(), make_array(pbs));
136 
137  if (trace.size() == getSize(pbs)) {
138 
139  this->insert(make_pair(i->content.getUPI(), JLocation_t(trace[2].position, trace[1].position, trace[0].position)));
140 
141  continue;
142  }
143  }
144 
145  {
147 
148  const JProductTrace trace(detector, i->content.getUPI(), make_array(pbs));
149 
150  if (trace.size() == getSize(pbs)) {
151 
152  this->insert(make_pair(i->content.getUPI(), JLocation_t(trace[2].position, trace[1].position, trace[0].position)));
153 
154  continue;
155  }
156  }
157  }
158  }
159  }
160 
161 
162  /**
163  * Get location of product with given %UPI.
164  *
165  * Note that only for products inside a string, a valid location is returned,
166  * otherwise, the default location is returned.
167  *
168  * \param upi %UPI
169  * \return location
170  */
171  JLocation_t getLocation(const JUPI& upi) const
172  {
174 
175  if (p != this->end())
176  return p->second;
177  else
178  return JLocation_t();
179  }
180  };
181 }
182 
183 #endif
JDATABASE::JLocation_t::JLocation_t
JLocation_t(const int string, const int floor, const int position)
Constructor.
Definition: JProductRouter.hh:47
JDATABASE::JDetectorIntegration::end
const_iterator end() const
end of integration data
Definition: JDetectorIntegration.hh:320
JDATABASE::PBS::DETECTION_UNIT
static const JPBS DETECTION_UNIT(3)
JDATABASE::JLocation_t::floor
int floor
position in string
Definition: JProductRouter.hh:94
JPBS.hh
JDATABASE::JLocation_t::less
bool less(const JLocation_t &location) const
Less-than method.
Definition: JProductRouter.hh:62
JDATABASE
Auxiliary classes and methods for database I/O.
Definition: JAHRS.hh:12
JDATABASE::JLocation_t::JLocation_t
JLocation_t()
Default constructor.
Definition: JProductRouter.hh:33
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JDATABASE::JProductRouter
Auxiliary class to map UPI to location in detector.
Definition: JProductRouter.hh:102
JDATABASE::JDetectorIntegration::begin
const_iterator begin() const
begin of integration data
Definition: JDetectorIntegration.hh:319
JDATABASE::JLocation_t::position
int position
position in floor
Definition: JProductRouter.hh:95
JComparable.hh
JLANG::getSize
size_t getSize(T(&array)[N])
Get size of c-array.
Definition: JLangToolkit.hh:32
JDATABASE::JDetectorIntegration::const_iterator
data_type::const_iterator const_iterator
Definition: JDetectorIntegration.hh:306
JDATABASE::JLocation_t::operator<<
friend std::ostream & operator<<(std::ostream &out, const JLocation_t &object)
Write location to output stream.
Definition: JProductRouter.hh:85
JDATABASE::PBS::DOM
static const JPBS DOM(3, 4)
JDATABASE::JLocation_t
Auxiliary data structure for location of product in detector.
Definition: JProductRouter.hh:26
std::map
Definition: JSTDTypes.hh:16
JDetectorIntegration.hh
JDATABASE::JProductTrace
Auxiliary class to trace product.
Definition: JDetectorIntegration.hh:617
JVectorize.hh
JDATABASE::JPBS
Product breakdown structure (PBS).
Definition: JPBS.hh:27
JLANG::JComparable
Template definition of auxiliary base class for comparison of data structures.
Definition: JComparable.hh:24
JDATABASE::JProductRouter::getLocation
JLocation_t getLocation(const JUPI &upi) const
Get location of product with given UPI.
Definition: JProductRouter.hh:171
JDATABASE::JDetectorIntegration
Detector integration.
Definition: JDetectorIntegration.hh:294
JDATABASE::PBS::DETECTOR
static const JPBS DETECTOR(0)
Fixed PBS.
std
Definition: jaanetDictionary.h:36
JDATABASE::PBS::BASE_CONTAINER
static const JPBS BASE_CONTAINER(3, 2, 2)
JUPI.hh
JLANG::make_array
const std::vector< JValue_t > make_array(const JValue_t(&array)[N])
Method to create array of values.
Definition: JVectorize.hh:27
JDATABASE::PBS::BASE
static const JPBS BASE(3, 2)
JDATABASE::JUPI
Universal product identifier (UPI).
Definition: JUPI.hh:29
JDATABASE::JProductRouter::JProductRouter
JProductRouter(const JDetectorIntegration &detector)
Constructor.
Definition: JProductRouter.hh:110
JDATABASE::JLocation_t::string
int string
position in detector
Definition: JProductRouter.hh:93
JLangToolkit.hh