#include #include #include #include #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" /** * \file * * Auxiliary program to disable acoustic sensors based on acoustic events. * \author mdejong */ int main(int argc, char **argv) { using namespace std; using namespace JPP; JMultipleFileScanner inputFile; JLimit_t& numberOfEvents = inputFile.getLimit(); string detectorFile; size_t Nmin; bool overwriteDetector; int debug; try { JParser<> zap("Auxiliary program to disable acoustic sensors based on acoustic events."); zap['f'] = make_field(inputFile, "output of JAcousticEventBuilder[.sh]"); zap['n'] = make_field(numberOfEvents) = JLimit::max(); zap['a'] = make_field(detectorFile); zap['N'] = make_field(Nmin, "minimum number of transmissions"); zap['A'] = make_field(overwriteDetector, "overwrite detector file provided through '-a' with status of acoustic sensor."); zap['d'] = make_field(debug) = 2; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } JDetector detector; try { load(detectorFile, detector); } catch(const JException& error) { FATAL(error); } map buffer; while (inputFile.hasNext()) { if (inputFile.getCounter()%1000 == 0) { STATUS("event " << setw(8) << inputFile.getCounter() << '\r'); DEBUG(endl); } const JEvent* evt = inputFile.next(); for (JEvent::const_iterator i = evt->begin(); i != evt->end(); ++i) { buffer[i->getID()] += 1; } } STATUS(endl); if (inputFile.getCounter() == 0) { FATAL("No events in input." << endl); } for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) { if (buffer[module->getID()] < Nmin) { if (module->getFloor() == 0) { if (!module->has(HYDROPHONE_DISABLE)) { NOTICE("Module " << setw(10) << module->getID() << ' ' << getLabel(module->getLocation()) << " disable hydrophone." << endl); module->set(HYDROPHONE_DISABLE); } } else { if (!module->has(PIEZO_DISABLE)) { NOTICE("Module " << setw(10) << module->getID() << ' ' << getLabel(module->getLocation()) << " disable piezo." << endl); module->set(PIEZO_DISABLE); } } } } if (overwriteDetector) { NOTICE("Store calibration data on file " << detectorFile << endl); store(detectorFile, detector); } }