Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JPolicy.cc File Reference

Example program to test policy method for missing module data. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <set>
#include "TRandom3.h"
#include "JCompass/JPolicy.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JModuleRouter.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Example program to test policy method for missing module data.

Author
mdejong

Definition in file JPolicy.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 23 of file JPolicy.cc.

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
std::string getLabel(const JLocation &location)
Get module label for monitoring and other applications.
Definition: JLocation.hh:246
Detector data structure.
Definition: JDetector.hh:80
Router for direct addressing of module data in detector data structure.
Detector file.
Definition: JHead.hh:196
Auxiliary class to define policy for invalid modules.
Definition: JPolicy.hh:31
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
return result
Definition: JPolint.hh:727
int debug
debug level
Definition: JSirene.cc:63
#define FATAL(A)
Definition: JMessage.hh:67
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
do set_variable DETECTOR_TXT $WORKDIR detector
then $DIR JPlotNPE PDG P
Definition: JPlotNPE-PDG.sh:60
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62