Jpp 19.3.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
JPolicy.hh
Go to the documentation of this file.
1#ifndef __JCOMPASS__JPOLICY__
2#define __JCOMPASS__JPOLICY__
3
4#include <map>
5#include <vector>
6#include <set>
7
10
11/**
12 * \file
13 *
14 * Policy for invalid modules.
15 * \author mdejong
16 */
17
18namespace JCOMPASS {}
19namespace JPP { using namespace JCOMPASS; }
20
21namespace JCOMPASS {
22
24
25 /**
26 * Auxiliary class to define policy for invalid modules.
27 *
28 * The policy is defined as a map of the identifier of a module to a list of identifiers of valid modules.\n
29 * For invalid modules, the valid modules in the nearest floors in the same string are selected.
30 */
31 struct JPolicy :
32 public std::map<int, // identifier of module
33 std::vector<int> > // identifiers of valid module(s)
34 {
35 /**
36 * Constructor.
37 *
38 * \param router module router
39 * \param __begin begin of list with identifiers of valid modules
40 * \param __end end of list with identifiers of valid modules
41 * \param size minimum number of valid modules in case of an invalid module
42 */
43 template<class T>
44 JPolicy(const JModuleRouter& router, T __begin, T __end, const size_t size = 1)
45 {
46 using namespace std;
47 using namespace JPP;
48
49 map<int, set<int> > zmap; // valid floors per string
50
51 for (T i = __begin; i != __end; ++i) {
52
53 if (router.hasModule(*i)) {
54
55 const JLocation& location = router.getModule(*i);
56
57 zmap[location.getString()].insert(location.getFloor());
58 }
59 }
60
61 map<JLocation, int> detector; // inverse router
62
63 for (JModuleRouter::const_iterator module = router->begin(); module != router->end(); ++module) {
64 detector[module->getLocation()] = module->getID();
65 }
66
67 for (JModuleRouter::const_iterator module = router->begin(); module != router->end(); ++module) {
68
69 if (module->getFloor() != 0) {
70
71 const int id = module->getID();
72 const int string = module->getString();
73
74 if (!zmap[string].empty()) {
75
76 if (zmap[string].count(module->getFloor()) != 0) {
77
78 (*this)[id].push_back(id);
79
80 } else {
81
82 for (size_t step = 1; (*this)[id].size() < size && (module->getFloor() + (int) step <= *zmap[string].rbegin() ||
83 module->getFloor() - (int) step >= *zmap[string]. begin()); ++step) {
84 for (int sign : { -1, +1 }) {
85
86 const int floor = module->getFloor() + sign * step;
87
88 if (zmap[string].count(floor) != 0) {
89 (*this)[id].push_back(detector[JLocation(string,floor)]);
90 }
91 }
92 }
93 }
94 }
95 }
96 }
97 }
98 };
99}
100
101#endif
Logical location of module.
Direct access to module in detector data structure.
Logical location of module.
Definition JLocation.hh:40
int getFloor() const
Get floor number.
Definition JLocation.hh:146
int getString() const
Get string number.
Definition JLocation.hh:135
Router for direct addressing of module data in detector data structure.
JDetector::const_iterator const_iterator
bool hasModule(const JObjectID &id) const
Has module.
const JModule & getModule(const JObjectID &id) const
Get module parameters.
Auxiliary classes and methods for orientation calibration based on compasses.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Detector file.
Definition JHead.hh:227
Auxiliary class to define policy for invalid modules.
Definition JPolicy.hh:34
JPolicy(const JModuleRouter &router, T __begin, T __end, const size_t size=1)
Constructor.
Definition JPolicy.hh:44