#include #include #include #include #include "JDetector/JDetector.hh" #include "JDetector/JDetectorCalibration.hh" #include "JDetector/JDetectorToolkit.hh" #include "JDetector/JDetectorAddressMapToolkit.hh" #include "JDetector/JModuleRouter.hh" #include "JDetector/JPMTRouter.hh" #include "JSupport/JMeta.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 compose detector from separate calibrations. * \author mdejong */ int main(int argc, char **argv) { using namespace std; using namespace JPP; string detectorFile; string inputFile; string outputFile; int debug; try { JParser<> zap("Auxiliary program to compose detector from separate calibrations."); zap['a'] = make_field(detectorFile, "detector file"); zap['f'] = make_field(inputFile, "detector calibration files in JSON format "\ "(wild card \'" << FILENAME_WILD_CARD << "\' will be replaced by corresponding calibration set)"); zap['o'] = make_field(outputFile, "detector file") = ""; 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()); const JModuleRouter moduleRouter(detector); const JPMTRouter pmtRouter (detector); json::const_iterator data; { const JSon js(hasWildCard(inputFile) ? setWildCard(inputFile, TCAL) : inputFile); if (is_valid(js) && (data = js.find(Data_t)) != js.end()) { for (size_t i = 0; i != data->size(); ++i) { if (data->at(i).contains(DetID_t)) { ASSERT(data->at(i)[DetID_t].get() == detector.getID(), "Check detector identifier."); } if (data->at(i).contains(PMTT0s_t)) { for (const auto& element : data->at(i)[PMTT0s_t].get()) { if (pmtRouter.hasPMT(element.getID())) { JPMT& pmt = detector.getPMT(pmtRouter.getAddress(element.getID())); pmt.setCalibration(element.getCalibration()); } } } } } } { const JSon js(hasWildCard(inputFile) ? setWildCard(inputFile, PCAL) : inputFile); if (is_valid(js) && (data = js.find(Data_t)) != js.end()) { for (size_t i = 0; i != data->size(); ++i) { if (data->at(i).contains(DetID_t)) { ASSERT(data->at(i)[DetID_t].get() == detector.getID(), "Check detector identifier."); } if (data->at(i).contains(DOMPositions_t)) { for (const auto& element : data->at(i)[DOMPositions_t].get()) { if (moduleRouter.hasModule(element.getID())) { JModule& module = detector.getModule(moduleRouter.getAddress(element.getID())); module.add(element.getPosition()); // position of reference module may not exactly be at origin } } } if (data->at(i).contains(BasePositions_t)) { for (const auto& element : data->at(i)[BasePositions_t].get()) { if (moduleRouter.hasModule(element.getID())) { JModule& module = detector.getModule(moduleRouter.getAddress(element.getID())); module.add(element.getPosition()); } } } } } } { const JSon js(hasWildCard(inputFile) ? setWildCard(inputFile, RCAL) : inputFile); if (is_valid(js) && (data = js.find(Data_t)) != js.end()) { for (size_t i = 0; i != data->size(); ++i) { if (data->at(i).contains(DetID_t)) { ASSERT(data->at(i)[DetID_t].get() == detector.getID(), "Check detector identifier."); } if (data->at(i).contains(DOMRotations_t)) { for (const auto& element : data->at(i)[DOMRotations_t].get()) { if (moduleRouter.hasModule(element.getID())) { JModule& module = detector.getModule(moduleRouter.getAddress(element.getID())); const JModule buffer = getModule(demo.get(module.getID()), module.getID()); if (module.size() != buffer.size()) { FATAL("Module size " << module.size() << " != " << buffer.size() << endl); } const JPosition3D center = module.getCenter(); for (size_t i = 0; i != module.size(); ++i) { module.getPMT(i).setAxis(buffer.getPMT(i).getAxis()); } module.rotate(element.getQuaternion()); module.setPosition(module.getCenter()); module.set(center); } } } if (data->at(i).contains(BaseRotations_t)) { // nothing to be done } } } } { const JSon js(hasWildCard(inputFile) ? setWildCard(inputFile, ACAL) : inputFile); if (is_valid(js) && (data = js.find(Data_t)) != js.end()) { for (size_t i = 0; i != data->size(); ++i) { if (data->at(i).contains(DetID_t)) { ASSERT(data->at(i)[DetID_t].get() == detector.getID(), "Check detector identifier."); } if (data->at(i).contains(DOMAcousticT0_t)) { for (const auto& element : data->at(i)[DOMAcousticT0_t].get()) { if (moduleRouter.hasModule(element.getID())) { JModule& module = detector.getModule(moduleRouter.getAddress(element.getID())); module.setCalibration(element.getCalibration()); } } } } } } { const JSon js(hasWildCard(inputFile) ? setWildCard(inputFile, CCAL) : inputFile); if (is_valid(js) && (data = js.find(Data_t)) != js.end()) { for (size_t i = 0; i != data->size(); ++i) { if (data->at(i).contains(DetID_t)) { ASSERT(data->at(i)[DetID_t].get() == detector.getID(), "Check detector identifier."); } if (data->at(i).contains(DOMCompassRotations_t)) { for (const auto& element : data->at(i)[DOMCompassRotations_t].get()) { if (moduleRouter.hasModule(element.getID())) { JModule& module = detector.getModule(moduleRouter.getAddress(element.getID())); module.setQuaternion(element.getQuaternion()); } } } } } } { const JSon js(hasWildCard(inputFile) ? setWildCard(inputFile, SCAL) : inputFile); if (is_valid(js) && (data = js.find(Data_t)) != js.end()) { for (size_t i = 0; i != data->size(); ++i) { if (data->at(i).contains(DetID_t)) { ASSERT(data->at(i)[DetID_t].get() == detector.getID(), "Check detector identifier."); } if (data->at(i).contains(PMTStatusInfo_t)) { for (const auto& element : data->at(i)[PMTStatusInfo_t].get()) { if (pmtRouter.hasPMT(element.getID())) { JPMT& pmt = detector.getPMT(pmtRouter.getAddress(element.getID())); pmt.setStatus(element.getStatus()); } } } if (data->at(i).contains(DOMStatusInfo_t)) { for (const auto& element : data->at(i)[DOMStatusInfo_t].get()) { if (moduleRouter.hasModule(element.getID())) { JModule& module = detector.getModule(moduleRouter.getAddress(element.getID())); module.setStatus(element.getStatus()); } } } if (data->at(i).contains(BaseStatusInfo_t)) { for (const auto& element : data->at(i)[BaseStatusInfo_t].get()) { if (moduleRouter.hasModule(element.getID())) { JModule& module = detector.getModule(moduleRouter.getAddress(element.getID())); module.setStatus(element.getStatus()); } } } } } } detector.comment.add(JMeta(argc,argv)); try { store(outputFile, detector); } catch(const JException& error) { FATAL(error); } return 0; }