Jpp  18.3.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JDisable.cc File Reference

Auxiliary program to disable acoustic sensors based on acoustic events. More...

#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include "km3net-dataformat/definitions/module_status.hh"
#include "TROOT.h"
#include "TFile.h"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JSupport/JMultipleFileScanner.hh"
#include "JAcoustics/JEvent.hh"
#include "JAcoustics/JSupport.hh"
#include "Jeep/JPrint.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

Auxiliary program to disable acoustic sensors based on acoustic events.

Author
mdejong

Definition in file JDisable.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 30 of file JDisable.cc.

31 {
32  using namespace std;
33  using namespace JPP;
34 
36  JLimit_t& numberOfEvents = inputFile.getLimit();
37  string detectorFile;
38  size_t Nmin;
39  bool overwriteDetector;
40  int debug;
41 
42  try {
43 
44  JParser<> zap("Auxiliary program to disable acoustic sensors based on acoustic events.");
45 
46  zap['f'] = make_field(inputFile, "output of JAcousticEventBuilder[.sh]");
47  zap['n'] = make_field(numberOfEvents) = JLimit::max();
48  zap['a'] = make_field(detectorFile);
49  zap['N'] = make_field(Nmin, "minimum number of transmissions");
50  zap['A'] = make_field(overwriteDetector, "overwrite detector file provided through '-a' with status of acoustic sensor.");
51  zap['d'] = make_field(debug) = 2;
52 
53  zap(argc, argv);
54  }
55  catch(const exception &error) {
56  FATAL(error.what() << endl);
57  }
58 
60 
61  try {
62  load(detectorFile, detector);
63  }
64  catch(const JException& error) {
65  FATAL(error);
66  }
67 
68  map<int, size_t> buffer;
69 
70  while (inputFile.hasNext()) {
71 
72  if (inputFile.getCounter()%1000 == 0) {
73  STATUS("event " << setw(8) << inputFile.getCounter() << '\r'); DEBUG(endl);
74  }
75 
76  const JEvent* evt = inputFile.next();
77 
78  for (JEvent::const_iterator i = evt->begin(); i != evt->end(); ++i) {
79  buffer[i->getID()] += 1;
80  }
81  }
82  STATUS(endl);
83 
84  if (inputFile.getCounter() == 0) {
85  FATAL("No events in input." << endl);
86  }
87 
88  for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
89 
90  if (buffer[module->getID()] < Nmin) {
91 
92  if (module->getFloor() == 0) {
93 
94  if (!module->has(HYDROPHONE_DISABLE)) {
95 
96  NOTICE("Module " << setw(10) << module->getID() << ' ' << getLabel(module->getLocation()) << " disable hydrophone." << endl);
97 
98  module->set(HYDROPHONE_DISABLE);
99  }
100 
101  } else {
102 
103  if (!module->has(PIEZO_DISABLE)) {
104 
105  NOTICE("Module " << setw(10) << module->getID() << ' ' << getLabel(module->getLocation()) << " disable piezo." << endl);
106 
107  module->set(PIEZO_DISABLE);
108  }
109  }
110  }
111  }
112 
113  if (overwriteDetector) {
114 
115  NOTICE("Store calibration data on file " << detectorFile << endl);
116 
117  store(detectorFile, detector);
118  }
119 }
Utility class to parse command line options.
Definition: JParser.hh:1514
General exception.
Definition: JException.hh:24
std::string getLabel(const JLocation &location)
Get module label for monitoring and other applications.
Definition: JLocation.hh:246
#define STATUS(A)
Definition: JMessage.hh:63
Detector data structure.
Definition: JDetector.hh:89
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
Detector file.
Definition: JHead.hh:226
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
void store(const std::string &file_name, const JDetector &detector)
Store detector to output file.
#define NOTICE(A)
Definition: JMessage.hh:64
#define FATAL(A)
Definition: JMessage.hh:67
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
General purpose class for object reading from a list of file names.
static const int PIEZO_DISABLE
Enable (disable) use of piezo if this status bit is 0 (1);.
Acoustic event.
static const int HYDROPHONE_DISABLE
Enable (disable) use of hydrophone if this status bit is 0 (1);.
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:84
do set_variable DETECTOR_TXT $WORKDIR detector
int debug
debug level
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62