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  */
46  JLocation_t(const int string,
47  const int floor,
48  const int position) :
49  string (string),
50  floor (floor),
52  {}
53 
54 
55  /**
56  * Less-than method.
57  *
58  * \param location location
59  * \return true if this location less than given location; else false
60  */
61  bool less(const JLocation_t& location) const
62  {
63  if (this->string == location.string) {
64 
65  if (this->floor == location.floor)
66  return this->position < location.position;
67  else
68  return this->floor < location.floor;
69 
70  } else {
71 
72  return this->string < location.string;
73  }
74  }
75 
76 
77  /**
78  * Write location to output stream.
79  *
80  * \param out output stream
81  * \param object location
82  * \return output stream
83  */
84  friend inline std::ostream& operator<<(std::ostream& out, const JLocation_t& object)
85  {
86  using namespace std;
87 
88  return out << setw(3) << object.string << ' ' << setw(2) << object.floor << ' ' << setw(2) << object.position;
89  }
90 
91 
92  int string; //!< position in detector
93  int floor; //!< position in string
94  int position; //!< position in floor
95  };
96 
97 
98  /**
99  * Auxiliary class to map %UPI to location in detector.
100  */
101  struct JProductRouter :
102  private std::map<JUPI, JLocation_t>
103  {
104  /**
105  * Constructor.
106  *
107  * \param detector detector integration
108  */
110  {
111  using namespace std;
112  using namespace JPP;
113 
114  for (JDetectorIntegration::const_iterator i = detector.begin(); i != detector.end(); ++i) {
115 
116  if (i->has()) {
117 
118  {
119  const JPBS pbs[] = { PBS::DOM, PBS::DETECTION_UNIT, PBS::DETECTOR };
120 
121  const JProductTrace trace(detector, i->content.getUPI(), make_array(pbs));
122 
123  if (trace.size() == getSize(pbs)) {
124 
125  this->insert(make_pair(i->content.getUPI(), JLocation_t(trace[2].position, trace[1].position, trace[0].position)));
126 
127  continue;
128  }
129  }
130 
131  {
132  const JPBS pbs[] = { PBS::BASE, PBS::DETECTION_UNIT, PBS::DETECTOR };
133 
134  const JProductTrace trace(detector, i->content.getUPI(), make_array(pbs));
135 
136  if (trace.size() == getSize(pbs)) {
137 
138  this->insert(make_pair(i->content.getUPI(), JLocation_t(trace[2].position, trace[1].position, trace[0].position)));
139 
140  continue;
141  }
142  }
143 
144  {
146 
147  const JProductTrace trace(detector, i->content.getUPI(), make_array(pbs));
148 
149  if (trace.size() == getSize(pbs)) {
150 
151  this->insert(make_pair(i->content.getUPI(), JLocation_t(trace[2].position, trace[1].position, trace[0].position)));
152 
153  continue;
154  }
155  }
156  }
157  }
158  }
159 
160 
161  /**
162  * Get location of product with given %UPI.
163  *
164  * Note that only for products inside a string, a valid location is returned,
165  * otherwise, the default location is returned.
166  *
167  * \param upi %UPI
168  * \return location
169  */
170  JLocation_t getLocation(const JUPI& upi) const
171  {
173 
174  if (p != this->end())
175  return p->second;
176  else
177  return JLocation_t();
178  }
179  };
180 }
181 
182 #endif
JDATABASE::JLocation_t::JLocation_t
JLocation_t(const int string, const int floor, const int position)
Constructor.
Definition: JProductRouter.hh:46
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:93
JPBS.hh
JDATABASE::JLocation_t::less
bool less(const JLocation_t &location) const
Less-than method.
Definition: JProductRouter.hh:61
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:101
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:94
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:84
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:170
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:109
JDATABASE::JLocation_t::string
int string
position in detector
Definition: JProductRouter.hh:92
JLangToolkit.hh