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_t.hh"
9 #include "JDB/JUPI_t.hh"
10 #include "JDB/JPBSSequence.hh"
11 #include "JLang/JComparable.hh"
12 #include "Jeep/JPrint.hh"
13 
14 
15 /**
16  * \author mdejong
17  */
18 namespace JDATABASE {}
19 namespace JPP { using namespace JDATABASE; }
20 
21 namespace JDATABASE {
22 
23  using JLANG::JComparable;
24 
25 
26  /**
27  * Auxiliary data structure for location of product in detector.
28  */
29  struct JLocation_t :
30  public JComparable<JLocation_t>
31  {
32  /**
33  * Default constructor.\n
34  * The default corresponds to an invalid location.
35  */
37  string (-1),
38  floor (-1),
39  position(-1)
40  {}
41 
42 
43  /**
44  * Constructor.
45  *
46  * \param string string
47  * \param floor floor
48  * \param position position
49  */
50  JLocation_t(const int string,
51  const int floor,
52  const int position) :
53  string (string),
54  floor (floor),
55  position(position)
56  {}
57 
58 
59  /**
60  * Check validity of location.
61  *
62  * \return true if valid; else false
63  */
64  bool is_valid() const
65  {
66  return *this != JLocation_t();
67  }
68 
69 
70  /**
71  * Less-than method.
72  *
73  * \param location location
74  * \return true if this location less than given location; else false
75  */
76  bool less(const JLocation_t& location) const
77  {
78  if (this->string == location.string) {
79 
80  if (this->floor == location.floor)
81  return this->position < location.position;
82  else
83  return this->floor < location.floor;
84 
85  } else {
86 
87  return this->string < location.string;
88  }
89  }
90 
91 
92  /**
93  * Write location to output stream.
94  *
95  * \param out output stream
96  * \param object location
97  * \return output stream
98  */
99  friend inline std::ostream& operator<<(std::ostream& out, const JLocation_t& object)
100  {
101  using namespace std;
102  using namespace JPP;
103 
104  return out << FILL(4,'0') << object.string << '.'
105  << FILL(2,'0') << object.floor << '.'
106  << FILL(2,'0') << object.position << FILL();
107  }
108 
109 
110  int string; //!< position in detector
111  int floor; //!< position in string
112  int position; //!< position in floor
113  };
114 
115 
116  /**
117  * Auxiliary class to map %UPI to location in detector.
118  */
119  struct JProductRouter :
120  public std::map<JUPI_t, JLocation_t>
121  {
122  /**
123  * Constructor.
124  *
125  * \param detector detector integration
126  * \param pbs %PBS sequences
127  */
129  {
130  for (JDetectorIntegration_t::const_iterator product = detector.begin(); product != detector.end(); ++product) {
131  if (product->has()) {
132  for (JPBSSequences::const_iterator i = pbs.begin(); i != pbs.end(); ++i) {
133  if (insert(detector, *product, *i)) {
134  break;
135  }
136  }
137  }
138  }
139  }
140 
141 
142  /**
143  * Get location of product with given %UPI.
144  *
145  * \param upi %UPI
146  * \return location
147  */
148  JLocation_t getLocation(const JUPI_t& upi) const
149  {
150  const_iterator p = this->find(upi);
151 
152  if (p != this->end())
153  return p->second;
154  else
155  return JLocation_t();
156  }
157 
158  private:
159  /**
160  * Insert product.
161  *
162  * \param detector detector integration
163  * \param product product
164  * \param pbs %PBS sequence
165  * \return true if inserted; else false
166  */
168  const JProductIntegration_t& product,
169  const JPBSSequence& pbs)
170  {
171  using namespace std;
172 
173  if (!pbs.empty()) {
174 
175  JPBSSequence::const_iterator i = pbs.begin();
176 
177  if (product.content.getPBS() == i->getPBS()) {
178 
179  JLocation_t location;
180 
181  for (JUPI_t upi = product.content.getUPI(); ++i != pbs.end(); ) {
182 
183  const JDetectorIntegration_t::range_type range = detector.find(upi);
184 
185  if (distance(range.first, range.second) == 1) {
186 
187  const JProductIntegration_t& ps = detector[range.first->second];
188 
189  if (is_optical_module(ps.container.getPBS()) ||
190  is_base_module (ps.container.getPBS())) { location.position = ps.position; }
191  else if (is_string (ps.container.getPBS())) { location.floor = ps.position; }
192  else if (is_detector (ps.container.getPBS())) { location.string = ps.position; }
193 
194  upi = ps.container.getUPI();
195 
196  } else {
197 
198  break;
199  }
200  }
201 
202  if (i == pbs.end()) {
203 
204  std::map<JUPI_t, JLocation_t>::insert(make_pair(product.content.getUPI(), location));
205 
206  return true;
207  }
208  }
209  }
210 
211  return false;
212  }
213  };
214 }
215 
216 #endif
JLocation_t(const int string, const int floor, const int position)
Constructor.
bool less(const JLocation_t &location) const
Less-than method.
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
Universal product identifier (UPI).
Definition: JUPI_t.hh:29
const JPBS_t & getPBS() const
Get PBS.
Definition: JPBS_t.hh:99
const JUPI_t & getUPI() const
Get UPI.
Definition: JUPI_t.hh:97
int floor
position in string
bool is_valid() const
Check validity of location.
I/O formatting auxiliaries.
Auxiliary data structure for a sequence of PBS values.
Definition: JPBSSequence.hh:30
Auxiliary data structure for location of product in detector.
JLocation_t getLocation(const JUPI_t &upi) const
Get location of product with given UPI.
JLocation_t()
Default constructor.
Auxiliary data structure for set of PBS sequences.
Definition: JPBSSequence.hh:83
range_type find(const JUPI_t &upi) const
Find range of products with given UPI.
Auxiliary class to map UPI to location in detector.
Template definition of auxiliary base class for comparison of data structures.
Definition: JComparable.hh:24
Auxiliary data structure for sequence of same character.
Definition: JManip.hh:327
z range($ZMAX-$ZMIN)< $MINIMAL_DZ." fi fi mv $WORKDIR/fit.root $MODULE_ROOT typeset -Z 4 STRING typeset -Z 2 FLOOR JPlot1D -f $
Definition: module-Z:fit.sh:84
friend std::ostream & operator<<(std::ostream &out, const JLocation_t &object)
Write location to output stream.
int position
position in floor
bool insert(const JDetectorIntegration_t &detector, const JProductIntegration_t &product, const JPBSSequence &pbs)
Insert product.
bool is_string(const JPBS_t &pbs)
Test if given PBS corresponds to a string.
Definition: JPBS_t.hh:265
JProductRouter(const JDetectorIntegration_t &detector, const JPBSSequences &pbs)
Constructor.
bool is_base_module(const JPBS_t &pbs)
Test if given PBS corresponds to a base module.
Definition: JPBS_t.hh:289
do set_variable DETECTOR_TXT $WORKDIR detector
int string
position in detector
bool is_detector(const JPBS_t &pbs)
Test if given PBS corresponds to a detector.
Definition: JPBS_t.hh:253
bool is_optical_module(const JPBS_t &pbs)
Test if given PBS corresponds to a optical module.
Definition: JPBS_t.hh:277
Auxiliary class for product integration data.