Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-07-03 07:05:28

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 <ctype.h>
0008 #include <fmt/core.h>
0009 #include <algorithm>
0010 #include <exception>
0011 #include <gsl/pointers>
0012 
0013 #include "services/geometry/dd4hep/DD4hep_service.h"
0014 #include "services/geometry/richgeo/ActsGeo.h"
0015 #include "services/geometry/richgeo/IrtGeo.h"
0016 #include "services/geometry/richgeo/IrtGeoDRICH.h"
0017 #include "services/geometry/richgeo/IrtGeoPFRICH.h"
0018 #include "services/geometry/richgeo/ReadoutGeo.h"
0019 #include "services/log/Log_service.h"
0020 
0021 // Services ----------------------------------------------------------
0022 void RichGeo_service::acquire_services(JServiceLocator *srv_locator) {
0023 
0024   // logging service
0025   auto log_service = srv_locator->get<Log_service>();
0026   m_log = log_service->logger("richgeo");
0027 
0028   // DD4Hep geometry service
0029   auto dd4hep_service = srv_locator->get<DD4hep_service>();
0030   m_dd4hepGeo = dd4hep_service->detector();
0031   m_converter = dd4hep_service->converter();
0032 }
0033 
0034 // IrtGeo -----------------------------------------------------------
0035 richgeo::IrtGeo *RichGeo_service::GetIrtGeo(std::string detector_name) {
0036 
0037   // initialize, if not yet initialized
0038   try {
0039     m_log->debug("Call RichGeo_service::GetIrtGeo initializer");
0040     auto initialize = [this,&detector_name] () {
0041       if(!m_dd4hepGeo) throw JException("RichGeo_service m_dd4hepGeo==null which should never be!");
0042       // instantiate IrtGeo-derived object, depending on detector
0043       auto which_rich = detector_name;
0044       std::transform(which_rich.begin(), which_rich.end(), which_rich.begin(), ::toupper);
0045       if     ( which_rich=="DRICH"  ) m_irtGeo = new richgeo::IrtGeoDRICH(m_dd4hepGeo,  m_converter, m_log);
0046       else if( which_rich=="PFRICH" ) m_irtGeo = new richgeo::IrtGeoPFRICH(m_dd4hepGeo, m_converter, m_log);
0047       else throw JException(fmt::format("IrtGeo is not defined for detector '{}'",detector_name));
0048     };
0049     std::call_once(m_init_irt, initialize);
0050   }
0051   catch (std::exception &ex) {
0052     throw JException(ex.what());
0053   }
0054 
0055   return m_irtGeo;
0056 }
0057 
0058 // ActsGeo -----------------------------------------------------------
0059 richgeo::ActsGeo *RichGeo_service::GetActsGeo(std::string detector_name) {
0060   // initialize, if not yet initialized
0061   try {
0062     m_log->debug("Call RichGeo_service::GetActsGeo initializer");
0063     auto initialize = [this,&detector_name] () {
0064       if(!m_dd4hepGeo) throw JException("RichGeo_service m_dd4hepGeo==null which should never be!");
0065       m_actsGeo = new richgeo::ActsGeo(detector_name, m_dd4hepGeo, m_log);
0066     };
0067     std::call_once(m_init_acts, initialize);
0068   }
0069   catch (std::exception &ex) {
0070     throw JException(ex.what());
0071   }
0072   return m_actsGeo;
0073 }
0074 
0075 // ReadoutGeo -----------------------------------------------------------
0076 std::shared_ptr<richgeo::ReadoutGeo> RichGeo_service::GetReadoutGeo(std::string detector_name) {
0077   // initialize, if not yet initialized
0078   try {
0079     m_log->debug("Call RichGeo_service::GetReadoutGeo initializer");
0080     auto initialize = [this,&detector_name] () {
0081       if(!m_dd4hepGeo) throw JException("RichGeo_service m_dd4hepGeo==null which should never be!");
0082       m_readoutGeo = std::make_shared<richgeo::ReadoutGeo>(detector_name, m_dd4hepGeo, m_converter, m_log);
0083     };
0084     std::call_once(m_init_readout, initialize);
0085   }
0086   catch (std::exception &ex) {
0087     throw JException(ex.what());
0088   }
0089   return m_readoutGeo;
0090 }
0091 
0092 // Destructor --------------------------------------------------------
0093 RichGeo_service::~RichGeo_service() {
0094   try {
0095     delete m_irtGeo;
0096     delete m_actsGeo;
0097   } catch (...) {}
0098 }