Jpp 19.3.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
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 "JDB/JLocation_t.hh"
12
13
14/**
15 * \author mdejong
16 */
17namespace JDATABASE {}
18namespace JPP { using namespace JDATABASE; }
19
20namespace JDATABASE {
21
22 /**
23 * Auxiliary class to map %UPI to location in detector.
24 */
26 public std::map<JUPI_t, JLocation_t>
27 {
28 /**
29 * Constructor.
30 *
31 * \param detector detector integration
32 * \param pbs %PBS sequences
33 */
35 {
36 for (JDetectorIntegration_t::const_iterator product = detector.begin(); product != detector.end(); ++product) {
37 if (product->is_set()) {
38 for (JPBSSequences::const_iterator i = pbs.begin(); i != pbs.end(); ++i) {
39 if (insert(detector, *product, *i)) {
40 break;
41 }
42 }
43 }
44 }
45 }
46
47
48 /**
49 * Get location of product with given %UPI.
50 *
51 * \param upi %UPI
52 * \return location
53 */
54 JLocation_t getLocation(const JUPI_t& upi) const
55 {
56 const_iterator p = this->find(upi);
57
58 if (p != this->end())
59 return p->second;
60 else
61 return JLocation_t();
62 }
63
64 private:
65 /**
66 * Insert product.
67 *
68 * \param detector detector integration
69 * \param product product
70 * \param pbs %PBS sequence
71 * \return true if inserted; else false
72 */
73 bool insert(const JDetectorIntegration_t& detector,
74 const JProductIntegration_t& product,
75 const JPBSSequence& pbs)
76 {
77 using namespace std;
78
79 if (!pbs.empty()) {
80
81 JPBSSequence::const_iterator i = pbs.begin();
82
83 if (product.content.getPBS() == i->getPBS()) {
84
85 JLocation_t location;
86
87 for (JUPI_t upi = product.content.getUPI(); ++i != pbs.end(); ) {
88
89 const JDetectorIntegration_t::range_type range = detector.find(upi);
90
91 if (distance(range.first, range.second) == 1) {
92
93 const JProductIntegration_t& ps = detector[range.first->second];
94
96 is_base_module (ps.container.getPBS())) { location.position = ps.position; }
97 else if (is_string (ps.container.getPBS())) { location.floor = ps.position; }
98 else if (is_detector (ps.container.getPBS())) { location.string = ps.position; }
99
100 upi = ps.container.getUPI();
101
102 } else {
103
104 break;
105 }
106 }
107
108 if (i == pbs.end()) {
109
110 std::map<JUPI_t, JLocation_t>::insert(make_pair(product.content.getUPI(), location));
111
112 return true;
113 }
114 }
115 }
116
117 return false;
118 }
119 };
120}
121
122#endif
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
Auxiliary classes and methods for database I/O.
Definition JAHRS.hh:14
bool is_base_module(const JPBS_t &pbs)
Test if given PBS corresponds to a base module.
Definition JPBS_t.hh:291
bool is_string(const JPBS_t &pbs)
Test if given PBS corresponds to a string.
Definition JPBS_t.hh:267
bool is_detector(const JPBS_t &pbs)
Test if given PBS corresponds to a detector.
Definition JPBS_t.hh:255
bool is_optical_module(const JPBS_t &pbs)
Test if given PBS corresponds to a optical module.
Definition JPBS_t.hh:279
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
range_type find(const JUPI_t &upi) const
Find range of products with given UPI.
Auxiliary data structure for location of product in detector.
int string
position in detector
int floor
position in string
int position
position in floor
Auxiliary data structure for a sequence of PBS values.
Auxiliary data structure for set of PBS sequences.
const JPBS_t & getPBS() const
Get PBS.
Definition JPBS_t.hh:101
Auxiliary class for product integration data.
Auxiliary class to map UPI to location in detector.
JProductRouter(const JDetectorIntegration_t &detector, const JPBSSequences &pbs)
Constructor.
bool insert(const JDetectorIntegration_t &detector, const JProductIntegration_t &product, const JPBSSequence &pbs)
Insert product.
JLocation_t getLocation(const JUPI_t &upi) const
Get location of product with given UPI.
Universal product identifier (UPI).
Definition JUPI_t.hh:32
const JUPI_t & getUPI() const
Get UPI.
Definition JUPI_t.hh:100