Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-12 07:55:49

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