#include #include #include #include #include "JDetector/JDetector.hh" #include "JDetector/JDetectorCalibration.hh" #include "JDetector/JDetectorToolkit.hh" #include "JDetector/JDetectorAddressMapToolkit.hh" #include "JSon/JSon.hh" #include "Jeep/JeepToolkit.hh" #include "Jeep/JPrint.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" /** * \file * * Auxiliary program to decompose detector to separate calibrations. * \author mdejong */ int main(int argc, char **argv) { using namespace std; using namespace JPP; string detectorFile; string outputFile; double precision; int debug; try { JParser<> zap("Auxiliary program to decompose detector to separate calibrations."); zap['a'] = make_field(detectorFile, "detector file"); zap['o'] = make_field(outputFile, "detector calibrations file in JSON format "\ "(optionally contains wild card \'" << FILENAME_WILD_CARD << "\')"); zap['p'] = make_field(precision, "precision for match with reference module") = 1.0e-5; zap['d'] = make_field(debug) = 1; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } JDetector detector; try { load(detectorFile, detector); } catch(const JException& error) { FATAL(error); } if (!hasDetectorAddressMap(detector.getID())) { FATAL("No detector address map for detector identier " << detector.getID() << endl); } const JDetectorAddressMap& demo = getDetectorAddressMap(detector.getID()); // Test compatibility of modules with reference(s). for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) { if (module->getFloor() != 0) { JModule buffer = getModule(demo.get(module->getID()), module->getID(), module->getLocation()); const JRotation3D R = getRotation(buffer, *module); buffer.rotate(R); if (!JModule::compare(buffer, *module, precision)) { FATAL("Module " << setw(10) << module->getID() << ' ' << module->getLocation() << " incompatible with reference." << endl); } } } const json error = { {Message_t, "" }, {Code_t, OK_t }, {Arguments_t, json::array() } }; json js; size_t N = 0; // data js[Comment_t] = json(detector.comment); js[Error_t] = json(error); { JPMTCalibration data; for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) { for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) { data.push_back(JPMTCalibration_t(pmt->getID(), getCalibration(JCalibration(), *pmt))); } } js[Data_t][N][DetID_t] = json(detector.getID()); js[Data_t][N][PMTT0s_t] = json(data); if (hasWildCard(outputFile)) { store(setWildCard(outputFile.c_str(), TCAL), js); js[Data_t].clear(); } else { N += 1; } } { JModulePosition data[2]; for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) { const JModule& buffer = getModule(demo.get(module->getID()), module->getID(), module->getLocation()); if (buffer.getFloor() == 0) data[0].push_back(JModulePosition_t(module->getID(), getPosition(buffer, *module))); else data[1].push_back(JModulePosition_t(module->getID(), getPosition(buffer, *module))); } js[Data_t][N][DetID_t] = json(detector.getID()); js[Data_t][N][BasePositions_t] = json(data[0]); js[Data_t][N][DOMPositions_t] = json(data[1]); if (hasWildCard(outputFile)) { store(setWildCard(outputFile.c_str(), PCAL), js); js[Data_t].clear(); } else { N += 1; } } { JModuleRotation data; for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) { const JModule& buffer = getModule(demo.get(module->getID()), module->getID(), module->getLocation()); if (module->getFloor() != 0) { data.push_back(JModuleRotation_t(module->getID(), getRotation(buffer, *module))); } } js[Data_t][N][DetID_t] = json(detector.getID()); js[Data_t][N][DOMRotations_t] = json(data); if (hasWildCard(outputFile)) { store(setWildCard(outputFile.c_str(), RCAL), js); js[Data_t].clear(); } else { N += 1; } } { JModuleCalibration data[2]; for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) { if (module->getFloor() == 0) data[0].push_back(JModuleCalibration_t(module->getID(), module->getT0())); else data[1].push_back(JModuleCalibration_t(module->getID(), module->getT0())); } js[Data_t][N][DetID_t] = json(detector.getID()); js[Data_t][N][BaseAcousticT0_t] = json(data[0]); js[Data_t][N][DOMAcousticT0_t] = json(data[1]); if (hasWildCard(outputFile)) { store(setWildCard(outputFile.c_str(), ACAL), js); js[Data_t].clear(); } else { N += 1; } } { JCompassRotation data[2]; for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) { if (module->getFloor() == 0) data[0].push_back(JCompassRotation_t(module->getID(), module->getQuaternion())); else data[1].push_back(JCompassRotation_t(module->getID(), module->getQuaternion())); } js[Data_t][N][DetID_t] = json(detector.getID()); js[Data_t][N][BaseCompassRotations_t] = json(data[0]); js[Data_t][N][DOMCompassRotations_t] = json(data[1]); if (hasWildCard(outputFile)) { store(setWildCard(outputFile.c_str(), CCAL), js); js[Data_t].clear(); } else { N += 1; } } { js[Data_t][N][DetID_t] = json(detector.getID()); { JPMTStatus data; for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) { for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) { data.push_back(JPMTStatus_t(pmt->getID(), pmt->getStatus())); } } js[Data_t][N][PMTStatusInfo_t ] = json(data); } { JModuleStatus data[2]; for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) { if (module->getFloor() == 0) data[0].push_back(JModuleStatus_t(module->getID(), module->getStatus())); else data[1].push_back(JModuleStatus_t(module->getID(), module->getStatus())); } js[Data_t][N][BaseStatusInfo_t] = json(data[0]); js[Data_t][N][DOMStatusInfo_t] = json(data[1]); } if (hasWildCard(outputFile)) { store(setWildCard(outputFile.c_str(), SCAL), js); js[Data_t].clear(); } else { N += 1; } } if (!hasWildCard(outputFile)) { store(outputFile.c_str(), js); } return 0; }