Jpp  17.2.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JAcousticsDisable.cc
Go to the documentation of this file.
1 
2 #include <string>
3 #include <iostream>
4 #include <iomanip>
5 #include <fstream>
6 #include <sstream>
7 #include <set>
8 #include <limits>
9 
10 #include "TROOT.h"
11 #include "TFile.h"
12 #include "TH1D.h"
13 #include "TKey.h"
14 #include "TString.h"
15 #include "TRegexp.h"
16 
18 
19 #include "JSupport/JMeta.hh"
20 
21 #include "Jeep/JContainer.hh"
22 #include "Jeep/JParser.hh"
23 #include "Jeep/JMessage.hh"
24 
25 /**
26  * \author mdejong
27  * Auxiliary program to set disable status of transmission based on time-of-arrival histograms.
28  */
29 int main(int argc, char **argv)
30 {
31  using namespace std;
32  using namespace JPP;
33 
34  typedef JContainer< set<JTransmission_t> > disable_container;
35 
36  vector<string> inputFile;
37  int Nmin;
38  double Tmax_us;
39  string disableFile;
40  int debug;
41 
42  try {
43 
44  JParser<> zap("Auxiliary program to set disable status of transmission based on time-of-arrival histograms.");
45 
46  zap['f'] = make_field(inputFile, "input file (output from JCanberra).");
47  zap['N'] = make_field(Nmin, "minimum number of entries") = 1;
48  zap['T'] = make_field(Tmax_us, "maximal time [us]") = 60.0;
49  zap['!'] = make_field(disableFile, "disable transmission file") = "";
50  zap['d'] = make_field(debug, "debug.") = 1;
51 
52  zap(argc, argv);
53  }
54  catch(const exception &error) {
55  FATAL(error.what() << endl);
56  }
57 
58 
59  disable_container disable;
60 
61  if (disableFile != "") {
62 
63  ifstream in(disableFile.c_str());
64 
65  in >> disable;
66 
67  in.close();
68  }
69 
70  disable.comment.add(JMeta(argc, argv));
71 
72 
73  const vector<double> Q = { 0.333, 0.666 };
74 
75  for (vector<string>::const_iterator i = inputFile.begin(); i != inputFile.end(); ++i) {
76 
77  DEBUG("Processing " << *i << endl) ;
78 
79  TFile in(i->c_str(), "read");
80 
81  TIter iter(in.GetListOfKeys());
82 
83  for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
84 
85  if (TString(key->GetName()).EndsWith(".toa")) {
86 
87  TH1* h1 = dynamic_cast<TH1*>(key->ReadObj());
88 
89  if (h1 != NULL) {
90 
91  TString buffer(h1->GetName());
92 
93  const char* regexp = "[^0-9][0-9]* [0-9]*[^0-9]";
94 
95  buffer = buffer(TRegexp(regexp));
96  buffer = buffer(1, buffer.Length() - 2);
97 
98  if (buffer.Length() > 0 && buffer.IsDigit()) {
99 
100  JTransmission_t id;
101 
102  istringstream(buffer.Data()) >> id;
103 
104  int N = h1->GetEntries();
105  double T_us = numeric_limits<double>::max();
106 
107  if (N > 0) {
108 
109  vector<double> R(Q.size());
110 
111  h1->GetQuantiles(Q.size(), R.data(), Q.data());
112 
113  T_us = (*R.rbegin() - *R.begin()) * 1.0e6;
114  }
115 
116  if (N < Nmin || T_us > Tmax_us) {
117 
118  NOTICE("disable: " << id << ' '
119  << setw(6) << N << (N < Nmin ? "*" : "") << " "
120  << FIXED(5,1) << T_us << (T_us > Tmax_us ? "*" : "") << " [us]" << endl);
121 
122  disable.insert(id);
123  }
124 
125  } else {
126 
127  ERROR("Histogram name " << h1->GetName() << " not compatible with regular expression " << regexp << "." << endl);
128  }
129  }
130  }
131  }
132 
133  in.Close();
134  }
135 
136  if (disableFile != "") {
137 
138  ofstream out(disableFile.c_str());
139 
140  out << disable;
141 
142  out.close();
143  }
144 }
Utility class to parse command line options.
Definition: JParser.hh:1517
Q(UTCMax_s-UTCMin_s)-livetime_s
int main(int argc, char *argv[])
Definition: Main.cc:15
then JShowerPostfit f $INPUT_FILE o $OUTPUT_FILE N
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1993
ROOT I/O of application specific meta data.
#define NOTICE(A)
Definition: JMessage.hh:64
#define ERROR(A)
Definition: JMessage.hh:66
then usage $script[distance] fi case set_variable R
Definition: JDrawLED.sh:43
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Utility class to parse command line options.
Acoustic transmission identifier.
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:46
Container I/O.
int debug
debug level
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62