Jpp  17.3.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JPolicy.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <iomanip>
4 #include <set>
5 #include <map>
6 
7 #include "TRandom3.h"
8 
9 #include "JCompass/JPolicy.hh"
10 
11 #include "JDetector/JDetector.hh"
14 
15 #include "Jeep/JParser.hh"
16 #include "Jeep/JMessage.hh"
17 
18 /**
19  * \file
20  *
21  * Example program to test policy method for missing module data.
22  * \author mdejong
23  */
24 int main(int argc, char **argv)
25 {
26  using namespace std;
27  using namespace JPP;
28 
29  string detectorFile;
30  double P;
31  size_t size;
32  UInt_t seed;
33  int debug;
34 
35  try {
36 
37  JParser<> zap("Example program to test policy method for missing module data.");
38 
39  zap['a'] = make_field(detectorFile, "Detector file");
40  zap['P'] = make_field(P, "Survival probability");
41  zap['N'] = make_field(size, "Minimal size") = 1;
42  zap['S'] = make_field(seed) = 0;
43  zap['d'] = make_field(debug) = 3;
44 
45  zap(argc, argv);
46  }
47  catch(const exception &error) {
48  FATAL(error.what() << endl);
49  }
50 
51  gRandom->SetSeed(seed);
52 
53  if (P <= 0.0 || P > 1.0) {
54  FATAL("Invalid probability " << P << endl);
55  }
56 
58 
59  try {
60  load(detectorFile, detector);
61  }
62  catch(const JException& error) {
63  FATAL(error);
64  }
65 
66  const JModuleRouter router(detector);
67 
68  struct counter_type {
69  counter_type() :
70  count(0)
71  {}
72 
73  int count;
74  };
75 
77 
78  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
79  strings[module->getString()].count += 1;
80  }
81 
82  set<int> buffer;
83 
84  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
85  if (gRandom->Rndm() <= P || strings[module->getString()].count == 1)
86  buffer.insert(module->getID());
87  else
88  strings[module->getString()].count -= 1;
89  }
90 
91  DEBUG("Number of modules " << buffer.size() << "/" << detector.size() << endl);
92 
93 
94  const JPolicy policy(router, buffer.begin(), buffer.end(), size);
95 
96  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
97 
98  const int id = module->getID();
99 
100  if (debug >= debug_t || buffer.count(id) == 0) {
101 
102  cout << "module: " << setw(10) << id << ' '
103  << getLabel(module->getLocation()) << ' '
104  << buffer.count(id) << flush;
105 
106  if (buffer.count(id) == 0) {
107 
108  cout << " ->";
109 
110  if (module->getFloor() != 0) {
111 
112  const JPolicy::mapped_type result = policy.at(id);
113 
114  for (JPolicy::mapped_type::const_iterator i = result.begin(); i != result.end(); ++i) {
115  cout << ' ' << getLabel(router.getModule(*i).getLocation());
116  }
117 
118  } else {
119 
120  cout << ' ' << "skip";
121  }
122  }
123 
124  cout << endl;
125  }
126 
127  if (module->getFloor() != 0) {
128  ASSERT(buffer.count(id) != 0 || !policy.at(id).empty(), "Test policy module at " << module->getLocation());
129  }
130  }
131 
132  return 0;
133 }
Utility class to parse command line options.
Definition: JParser.hh:1517
General exception.
Definition: JException.hh:23
debug
Definition: JMessage.hh:29
int main(int argc, char *argv[])
Definition: Main.cc:15
const JModule & getModule(const JObjectID &id) const
Get module parameters.
std::string getLabel(const JLocation &location)
Get module label for monitoring and other applications.
Definition: JLocation.hh:246
Detector data structure.
Definition: JDetector.hh:89
Router for direct addressing of module data in detector data structure.
then usage $script< detector specific pre-calibration script >< option > nAuxiliary script to make scan of pre stretching of detector strings(see JEditDetector)." "\nPossible options
Long64_t counter_type
Type definition for counter.
Data structure for detector geometry and calibration.
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
Detector file.
Definition: JHead.hh:226
Auxiliary class to define policy for invalid modules.
Definition: JPolicy.hh:31
const JLocation & getLocation() const
Get location.
Definition: JLocation.hh:69
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1993
return result
Definition: JPolint.hh:764
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Direct access to module in detector data structure.
Policy for invalid modules.
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
Utility class to parse command line options.
do set_variable DETECTOR_TXT $WORKDIR detector
int debug
debug level
then $DIR JPlotNPE PDG P
Definition: JPlotNPE-PDG.sh:62
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62