Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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/JEquals.hh"
11 #include "JLang/JComparable.hh"
12 #include "JLang/JVectorize.hh"
13 #include "JLang/JLangToolkit.hh"
14 #include "Jeep/JPrint.hh"
15 
16 
17 /**
18  * \author mdejong
19  */
20 namespace JDATABASE {}
21 namespace JPP { using namespace JDATABASE; }
22 
23 namespace JDATABASE {
24 
25  /**
26  * Auxiliary data structure for location of product in detector.
27  */
28  struct JLocation_t :
29  public JLANG::JComparable<JLocation_t>
30  {
31  /**
32  * Default constructor.\n
33  * The default corresponds to an invalid location.
34  */
36  string (-1),
37  floor (-1),
38  position(-1)
39  {}
40 
41 
42  /**
43  * Constructor.
44  *
45  * \param string string
46  * \param floor floor
47  * \param position position
48  */
49  JLocation_t(const int string,
50  const int floor,
51  const int position) :
52  string (string),
53  floor (floor),
54  position(position)
55  {}
56 
57 
58  /**
59  * Less-than method.
60  *
61  * \param location location
62  * \return true if this location less than given location; else false
63  */
64  bool less(const JLocation_t& location) const
65  {
66  if (this->string == location.string) {
67 
68  if (this->floor == location.floor)
69  return this->position < location.position;
70  else
71  return this->floor < location.floor;
72 
73  } else {
74 
75  return this->string < location.string;
76  }
77  }
78 
79 
80  /**
81  * Write location to output stream.
82  *
83  * \param out output stream
84  * \param object location
85  * \return output stream
86  */
87  friend inline std::ostream& operator<<(std::ostream& out, const JLocation_t& object)
88  {
89  using namespace std;
90  using namespace JPP;
91 
92  return out << FILL(3,'0') << object.string << '.'
93  << FILL(2,'0') << object.floor << '.'
94  << FILL(2,'0') << object.position << FILL();
95  }
96 
97 
98  int string; //!< position in detector
99  int floor; //!< position in string
100  int position; //!< position in floor
101  };
102 
103 
104  /**
105  * Auxiliary class to map %UPI to location in detector.
106  */
108  {
109 
110  public:
111 
112  /**
113  * Constructor.
114  *
115  * \param detector detector integration
116  */
118  {
119  using namespace std;
120  using namespace JPP;
121 
122  for (JDetectorIntegration_t::const_iterator i = detector.begin(); i != detector.end(); ++i) {
123 
124  if (i->has()) {
125 
126  if (insert(detector, *i, vector<JPBS>{ PBS::DOM, PBS::DETECTION_UNIT, PBS::DETECTOR })) { continue; }
127  if (insert(detector, *i, vector<JPBS>{ PBS::BASE, PBS::DETECTION_UNIT, PBS::DETECTOR })) { continue; }
128  if (insert(detector, *i, vector<JPBS>{ PBS::BASE_CONTAINER, PBS::DETECTION_UNIT, PBS::DETECTOR })) { continue; }
129 
130  if (insert(detector, *i, vector<JPBS>{ PBS::CLB, PBS::DOM, PBS::DETECTION_UNIT, PBS::DETECTOR })) { continue; }
131  if (insert(detector, *i, vector<JPBS>{ PBS::CLB, PBS::BASE, PBS::DETECTION_UNIT, PBS::DETECTOR })) { continue; }
132  if (insert(detector, *i, vector<JPBS>{ PBS::CLB, PBS::BASE_CONTAINER, PBS::DETECTION_UNIT, PBS::DETECTOR })) { continue; }
133  }
134  }
135  }
136 
137 
138  /**
139  * Get location of product with given %UPI.
140  *
141  * Note that only for products inside a string, a valid location is returned,
142  * otherwise, the default location is returned.
143  *
144  * \param upi %UPI
145  * \return location
146  */
147  JLocation_t getLocation(const JUPI& upi) const
148  {
150 
151  if (p != map.end())
152  return p->second;
153  else
154  return JLocation_t();
155  }
156 
157 
158  /**
159  * Get %UPI of product with given location.
160  *
161  * Note that only for products inside a string, a valid location is returned,
162  * otherwise, the default location is returned.
163  *
164  * \param location location
165  * \return %UPI
166  */
167  JUPI getUPI(const JLocation_t& location) const
168  {
169  std::map<JLocation_t, JUPI>::const_iterator p = inverse_map.find(location);
170 
171  if (p != inverse_map.end())
172  return p->second;
173  else
174  return JUPI();
175  }
176 
177 
178  private:
179  /**
180  * Insert product.
181  *
182  * Note that given PBS hierarchy should contain at least three levels and
183  * normally terminate with detection unit and detector.
184  *
185  * \param detector detector integration
186  * \param product product
187  * \param pbs %PBS hierarchy
188  * \return true if inserted; else false
189  */
191  const JProductIntegration_t& product,
192  const std::vector<JPBS>& pbs)
193  {
194  if (pbs.size() >= 3) {
195 
196  const JProductTrace trace(detector, product.content.getUPI(), pbs);
197 
198  if (trace.size() == pbs.size()) {
199 
200  const JUPI upi = product.content.getUPI();
201  const JLocation_t loc = JLocation_t(trace[2].position, trace[1].position, trace[0].position);
202 
203  map.insert (make_pair(upi, loc));
204  inverse_map.insert(make_pair(loc, upi));
205 
206  return true;
207  }
208  }
209 
210  return false;
211  }
212 
215  };
216 }
217 
218 #endif
std::map< JUPI, JLocation_t > map
JLocation_t(const int string, const int floor, const int position)
Constructor.
const_iterator end() const
end of integration data
set_variable DETECTOR
Definition: JLegolas.sh:31
bool less(const JLocation_t &location) const
Less-than method.
static const JPBS BASE_CONTAINER(3, 2, 2)
Auxiliary class to trace product.
static const JPBS DETECTION_UNIT(3)
data_type::const_iterator const_iterator
int floor
position in string
JLocation_t getLocation(const JUPI &upi) const
Get location of product with given UPI.
I/O formatting auxiliaries.
JProductRouter(const JDetectorIntegration_t &detector)
Constructor.
Auxiliary class to map UPI to location in detector.
JUPI getUPI(const JLocation_t &location) const
Get UPI of product with given location.
Auxiliary data structure for location of product in detector.
JLocation_t()
Default constructor.
std::map< JLocation_t, JUPI > inverse_map
Auxiliary methods to convert data members or return values of member methods of a set of objects to a...
static const JPBS DOM(3, 4)
Template definition of auxiliary base class for comparison of data structures.
Definition: JComparable.hh:24
Auxiliary data structure for sequence of same character.
Definition: JPrint.hh:361
static const JPBS BASE(3, 2)
friend std::ostream & operator<<(std::ostream &out, const JLocation_t &object)
Write location to output stream.
Universal product identifier (UPI).
Definition: JUPI.hh:30
int position
position in floor
bool insert(const JDetectorIntegration_t &detector, const JProductIntegration_t &product, const std::vector< JPBS > &pbs)
Insert product.
const JUPI & getUPI() const
Get UPI.
Definition: JUPI.hh:68
char * loc(char *orig)
int string
position in detector
static const JPBS CLB(3, 4, 3, 2)
const_iterator begin() const
begin of integration data
Auxiliary class for product integration data.