File indexing completed on 2025-10-29 07:58:05
0001
0002
0003
0004 #include "RichGeo_service.h"
0005
0006 #include <JANA/JException.h>
0007 #include <JANA/Services/JServiceLocator.h>
0008 #include <fmt/core.h>
0009 #include <exception>
0010 #include <gsl/pointers>
0011
0012 #include "services/geometry/dd4hep/DD4hep_service.h"
0013 #include "services/geometry/richgeo/ActsGeo.h"
0014 #include "services/geometry/richgeo/IrtGeo.h"
0015 #include "services/geometry/richgeo/IrtGeoDRICH.h"
0016 #include "services/geometry/richgeo/IrtGeoPFRICH.h"
0017 #include "services/geometry/richgeo/ReadoutGeo.h"
0018 #include "services/log/Log_service.h"
0019
0020
0021 void RichGeo_service::acquire_services(JServiceLocator* srv_locator) {
0022
0023
0024 auto log_service = srv_locator->get<Log_service>();
0025 m_log = log_service->logger("richgeo");
0026
0027
0028 auto dd4hep_service = srv_locator->get<DD4hep_service>();
0029 m_dd4hepGeo = dd4hep_service->detector();
0030 m_converter = dd4hep_service->converter();
0031 }
0032
0033
0034 richgeo::IrtGeo* RichGeo_service::GetIrtGeo(std::string detector_name) {
0035
0036
0037 try {
0038 m_log->debug("Call RichGeo_service::GetIrtGeo initializer");
0039 auto initialize = [this, &detector_name]() {
0040 if (m_dd4hepGeo == nullptr) {
0041 throw JException("RichGeo_service m_dd4hepGeo==null which should never be!");
0042 }
0043
0044 auto which_rich = detector_name;
0045 if (which_rich == "DRICH") {
0046 m_irtGeo = new richgeo::IrtGeoDRICH(m_dd4hepGeo, m_converter, m_log);
0047 } else if (which_rich == "RICHEndcapN") {
0048 m_irtGeo = new richgeo::IrtGeoPFRICH(m_dd4hepGeo, m_converter, m_log);
0049 } else {
0050 throw JException(fmt::format("IrtGeo is not defined for detector '{}'", detector_name));
0051 }
0052 };
0053 std::lock_guard<std::mutex> lock(m_init_lock);
0054 std::call_once(m_init_irt[detector_name], initialize);
0055 } catch (std::exception& ex) {
0056 throw JException(ex.what());
0057 }
0058
0059 return m_irtGeo;
0060 }
0061
0062
0063 const richgeo::ActsGeo* RichGeo_service::GetActsGeo(std::string detector_name) {
0064
0065 try {
0066 m_log->debug("Call RichGeo_service::GetActsGeo initializer");
0067 auto initialize = [this, &detector_name]() {
0068 if (m_dd4hepGeo == nullptr) {
0069 throw JException("RichGeo_service m_dd4hepGeo==null which should never be!");
0070 }
0071 m_actsGeo = new richgeo::ActsGeo(detector_name, m_dd4hepGeo, m_log);
0072 };
0073 std::lock_guard<std::mutex> lock(m_init_lock);
0074 std::call_once(m_init_acts[detector_name], initialize);
0075 } catch (std::exception& ex) {
0076 throw JException(ex.what());
0077 }
0078 return m_actsGeo;
0079 }
0080
0081
0082 std::shared_ptr<richgeo::ReadoutGeo> RichGeo_service::GetReadoutGeo(std::string detector_name,
0083 std::string readout_class) {
0084
0085 try {
0086 m_log->debug("Call RichGeo_service::GetReadoutGeo initializer");
0087 auto initialize = [this, &detector_name, &readout_class]() {
0088 if (m_dd4hepGeo == nullptr) {
0089 throw JException("RichGeo_service m_dd4hepGeo==null which should never be!");
0090 }
0091 m_readoutGeo = std::make_shared<richgeo::ReadoutGeo>(detector_name, readout_class,
0092 m_dd4hepGeo, m_converter, m_log);
0093 };
0094 std::lock_guard<std::mutex> lock(m_init_lock);
0095 std::call_once(m_init_readout[detector_name], initialize);
0096 } catch (std::exception& ex) {
0097 throw JException(ex.what());
0098 }
0099 return m_readoutGeo;
0100 }
0101
0102
0103 RichGeo_service::~RichGeo_service() {
0104 try {
0105 delete m_irtGeo;
0106 delete m_actsGeo;
0107 } catch (...) {
0108 }
0109 }