Jpp  15.0.1-rc.1-highQE
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
9 #include "JDetector/JLocation.hh"
10 
11 /**
12  * \file
13  *
14  * Policy for invalid modules.
15  * \author mdejong
16  */
17 
18 namespace JCOMPASS {}
19 namespace JPP { using namespace JCOMPASS; }
20 
21 namespace 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 modules 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; step < zmap[string].size() && (*this)[id].size() < size; ++step) {
83  for (int sign : { -1, +1 }) {
84 
85  const int floor = module->getFloor() + sign * step;
86 
87  if (zmap[string].count(floor) != 0) {
88  (*this)[id].push_back(detector[JLocation(string,floor)]);
89  }
90  }
91  }
92  }
93  }
94  }
95  }
96  }
97  };
98 }
99 
100 #endif
const JModule & getModule(const JObjectID &id) const
Get module parameters.
Router for direct addressing of module data in detector data structure.
JDetector::const_iterator const_iterator
JPolicy(const JModuleRouter &router, T __begin, T __end, const size_t size=1)
Constructor.
Definition: JPolicy.hh:44
Auxiliary class to define policy for invalid modules.
Definition: JPolicy.hh:31
do set_variable OUTPUT_DIRECTORY $WORKDIR T
Logical location of module.
Direct access to module in detector data structure.
std::vector< int > count
Definition: JAlgorithm.hh:180
bool hasModule(const JObjectID &id) const
Has module.
int sign(const T &value)
Get sign of value.
Definition: JLib.hh:20
do set_variable DETECTOR_TXT $WORKDIR detector