#include #include #include #include #include #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" /** * \file * * Example program to test policy method for missing module data. * \author mdejong */ int main(int argc, char **argv) { using namespace std; using namespace JPP; string detectorFile; double P; size_t size; UInt_t seed; int debug; try { JParser<> zap("Example program to test policy method for missing module data."); zap['a'] = make_field(detectorFile, "Detector file"); zap['P'] = make_field(P, "Survival probability"); zap['N'] = make_field(size, "Minimal size") = 1; zap['S'] = make_field(seed) = 0; zap['d'] = make_field(debug) = 3; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } gRandom->SetSeed(seed); if (P <= 0.0 || P > 1.0) { FATAL("Invalid probability " << P << endl); } JDetector detector; try { load(detectorFile, detector); } catch(const JException& error) { FATAL(error); } const JModuleRouter router(detector); struct counter_type { counter_type() : count(0) {} int count; }; map strings; for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) { strings[module->getString()].count += 1; } set buffer; for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) { if (gRandom->Rndm() <= P || strings[module->getString()].count == 1) buffer.insert(module->getID()); else strings[module->getString()].count -= 1; } DEBUG("Number of modules " << buffer.size() << "/" << detector.size() << endl); const JPolicy policy(router, buffer.begin(), buffer.end(), size); for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) { const int id = module->getID(); if (debug >= debug_t || buffer.count(id) == 0) { cout << "module: " << setw(10) << id << ' ' << getLabel(module->getLocation()) << ' ' << buffer.count(id) << flush; if (buffer.count(id) == 0) { cout << " ->"; if (module->getFloor() != 0) { const JPolicy::mapped_type result = policy.at(id); for (JPolicy::mapped_type::const_iterator i = result.begin(); i != result.end(); ++i) { cout << ' ' << getLabel(router.getModule(*i).getLocation()); } } else { cout << ' ' << "skip"; } } cout << endl; } if (module->getFloor() != 0) { ASSERT(buffer.count(id) != 0 || !policy.at(id).empty(), "Test policy module at " << module->getLocation()); } } return 0; }