Jpp  16.0.3
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 
6 #include "TRandom3.h"
7 
8 #include "JCompass/JPolicy.hh"
9 
10 #include "JDetector/JDetector.hh"
13 
14 #include "Jeep/JParser.hh"
15 #include "Jeep/JMessage.hh"
16 
17 /**
18  * \file
19  *
20  * Example program to test policy method for missing module data.
21  * \author mdejong
22  */
23 int main(int argc, char **argv)
24 {
25  using namespace std;
26  using namespace JPP;
27 
28  string detectorFile;
29  double P;
30  size_t size;
31  UInt_t seed;
32  int debug;
33 
34  try {
35 
36  JParser<> zap("Example program to test policy method for missing module data.");
37 
38  zap['a'] = make_field(detectorFile, "Detector file");
39  zap['P'] = make_field(P, "Survival probability");
40  zap['N'] = make_field(size, "Minimal size") = 1;
41  zap['S'] = make_field(seed) = 0;
42  zap['d'] = make_field(debug) = 3;
43 
44  zap(argc, argv);
45  }
46  catch(const exception &error) {
47  FATAL(error.what() << endl);
48  }
49 
50  gRandom->SetSeed(seed);
51 
52  if (P <= 0.0 || P > 1.0) {
53  FATAL("Invalid probability " << P << endl);
54  }
55 
57 
58  try {
59  load(detectorFile, detector);
60  }
61  catch(const JException& error) {
62  FATAL(error);
63  }
64 
65  const JModuleRouter router(detector);
66 
67  set<int> buffer;
68 
69  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
70  if (gRandom->Rndm() <= P) {
71  buffer.insert(module->getID());
72  }
73  }
74 
75  DEBUG("Number of modules " << buffer.size() << "/" << detector.size() << endl);
76 
77 
78  const JPolicy policy(router, buffer.begin(), buffer.end(), size);
79 
80  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
81 
82  const int id = module->getID();
83 
84  if (debug >= debug_t || buffer.count(id) == 0) {
85 
86  cout << "module: " << setw(10) << id << ' '
87  << getLabel(module->getLocation()) << ' '
88  << buffer.count(id);
89 
90  if (buffer.count(id) == 0) {
91 
92  cout << " ->";
93 
94  const JPolicy::mapped_type result = policy.at(id);
95 
96  for (JPolicy::mapped_type::const_iterator i = result.begin(); i != result.end(); ++i) {
97  cout << ' ' << getLabel(router.getModule(*i).getLocation());
98  }
99  }
100 
101  cout << endl;
102  }
103  }
104 }
Utility class to parse command line options.
Definition: JParser.hh:1500
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.
Data structure for detector geometry and calibration.
Detector file.
Definition: JHead.hh:224
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:1961
return result
Definition: JPolint.hh:743
int debug
debug level
Definition: JSirene.cc:63
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.
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
do set_variable DETECTOR_TXT $WORKDIR detector
then $DIR JPlotNPE PDG P
Definition: JPlotNPE-PDG.sh:62