Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 09:20:19

0001 //==============================================================================
0002 //  AIDA Detector description implementation for LHCb
0003 //------------------------------------------------------------------------------
0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 // All rights reserved.
0006 //
0007 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 //
0010 //  \author   Markus Frank
0011 //  \date     2018-03-08
0012 //  \version  1.0
0013 //
0014 //==============================================================================
0015 
0016 // Framework include files
0017 #include "Detector/ParameterMap.h"
0018 #include "DD4hep/Handle.h"
0019 
0020 namespace {
0021   static gaudi::ParameterMap::Parameter s_empty;
0022 }
0023 
0024 /// Gaudi namespace declaration
0025 namespace gaudi   {
0026 
0027   /// Type dependent accessor to a named parameter
0028   template <typename T> T ParameterMap::Parameter::get()  const  {
0029     if ( this == &s_empty ) return 0;
0030     return dd4hep::_toType<T>(value);
0031   }
0032 
0033   /// Add/update a parameter value
0034   bool ParameterMap::set(const std::string& nam, const std::string& val, const std::string& type)   {
0035     const auto i = m_params.find(nam);
0036     if ( i == m_params.end() )   {
0037       return m_params.insert(make_pair(nam,Parameter(val,type))).second;
0038     }
0039     (*i).second.value = val;
0040     (*i).second.type  = type;
0041     return false;
0042   }
0043   
0044   /// Access single parameter
0045   const ParameterMap::Parameter& ParameterMap::parameter(const std::string& nam, bool throw_if)   const  {
0046     const auto i = m_params.find(nam);
0047     if ( i != m_params.end() )
0048       return (*i).second;
0049     else if ( throw_if )  {
0050       throw std::runtime_error("ParameterMap: Attempt to access non-existng parameter: "+nam);
0051     }
0052     return s_empty;
0053   }
0054 
0055   /// Type dependent accessor to a named parameter
0056   template <typename T> T ParameterMap::param(const std::string& nam, bool throw_if)   const  {
0057     return parameter(nam, throw_if).template get<T>();
0058   }
0059 
0060 #define INST(x) template x ParameterMap::Parameter::get()  const;       \
0061   template x   ParameterMap::param(const std::string& nam, bool throw_if_not_present)   const
0062 
0063   INST(bool);
0064   INST(int);
0065   INST(short);
0066   INST(long);
0067   INST(double);
0068   INST(float);
0069   INST(std::string);
0070 }
0071 
0072 
0073