Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-21 09:58:00

0001 //==========================================================================
0002 //  AIDA Detector description implementation 
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     : M.Frank
0011 //
0012 //==========================================================================
0013 #ifndef DD4HEP_CONDITIONSDATA_H
0014 #define DD4HEP_CONDITIONSDATA_H
0015 
0016 // Framework include files
0017 #include <DD4hep/Objects.h>
0018 #include <DD4hep/Conditions.h>
0019 
0020 // C/C++ include files
0021 #include <vector>
0022 #include <stdexcept>
0023 
0024 /// Namespace for the AIDA detector description toolkit
0025 namespace dd4hep {
0026 
0027   /// Namespace for the conditions part of the AIDA detector description toolkit
0028   namespace cond   {
0029 
0030     /// Client data addition
0031     /**
0032      *
0033      *  \author  M.Frank
0034      *  \version 1.0
0035      *  \ingroup DD4HEP_CONDITIONS
0036      */
0037     struct ClientData {
0038       virtual ~ClientData();
0039       virtual void release() = 0;
0040     };
0041 
0042     /// Conditions data block. Internaly maps other objects to abstract data blocks
0043     /**
0044      *   \author  M.Frank
0045      *   \version 1.0
0046      *   \date    31/03/2016
0047      *   \ingroup DD4HEP_DDDB
0048      */
0049     class AbstractMap   {
0050     private:
0051     public:
0052       enum {
0053         REGULAR = 0,
0054         ALIGNMENT = 6
0055       };
0056       typedef std::map<std::string, OpaqueDataBlock> Params;
0057       ClientData*   clientData;
0058       Params        params;
0059       int           classID;
0060       /// Default constructor
0061       AbstractMap();
0062       /// Copy constructor
0063       AbstractMap(const AbstractMap& c);
0064       /// Default destructor
0065       virtual ~AbstractMap();
0066       /// Assignment operator
0067       AbstractMap& operator=(const AbstractMap& c);
0068       /// Simplify access to client data
0069       template <typename T> T* option()  const   {
0070         return static_cast<T*>(clientData);
0071       }
0072       /// Access the number of contained blocks
0073       size_t size()  const   {
0074         return params.size();
0075       }
0076       /// Simplify access to first item of the parameter list (const access)
0077       const Params::value_type& firstParam()  const   {
0078         Params::const_iterator i=std::begin(params);
0079         if ( i != std::end(params) ) return (*i);
0080         throw std::runtime_error("AbstractMap: Failed to access non-existing first parameter");
0081       }
0082       /// Simplify access to first item of the parameter list
0083       Params::value_type& firstParam()   {
0084         Params::iterator i=std::begin(params);
0085         if ( i != std::end(params) ) return (*i);
0086         throw std::runtime_error("AbstractMap: Failed to access non-existing first parameter");
0087       }
0088       /// Simplify access to first item of the parameter list (const access)
0089       template <typename T> const T& first()  const   {
0090         Params::const_iterator i=std::begin(params);
0091         if ( i != std::end(params) ) return (*i).second.get<T>();
0092         throw std::runtime_error("AbstractMap: Failed to access non-existing first item");
0093       }
0094       /// Simplify access to first item of the parameter list
0095       template <typename T> T& first()   {
0096         Params::iterator i=std::begin(params);
0097         if ( i != std::end(params) ) return (*i).second.get<T>();
0098         throw std::runtime_error("AbstractMap: Failed to access non-existing first item");
0099       }
0100       /// Simplify access to mapped item of the parameter list (const access)
0101       template <typename T> const T& operator[](const std::string& item)  const   {
0102         Params::const_iterator i=params.find(item);
0103         if ( i != std::end(params) ) return (*i).second.get<T>();
0104         throw std::runtime_error("AbstractMap: Failed to access non-existing item:"+item);
0105       }
0106       /// Simplify access to mapped item of the parameter list
0107       template <typename T> T& operator[](const std::string& item)   {
0108         Params::iterator i=params.find(item);
0109         if ( i != std::end(params) ) return (*i).second.get<T>();
0110         throw std::runtime_error("AbstractMap: Failed to access non-existing item:"+item);
0111       }
0112       /// Simplify access to mapped item of the parameter list (const access)
0113       template <typename T> const T& get(const std::string& item)  const   {
0114         Params::const_iterator i=params.find(item);
0115         if ( i != std::end(params) ) return (*i).second.get<T>();
0116         throw std::runtime_error("AbstractMap: Failed to access non-existing item:"+item);
0117       }
0118       /// Simplify access to mapped item of the parameter list
0119       template <typename T> T& get(const std::string& item)   {
0120         Params::iterator i=params.find(item);
0121         if ( i != std::end(params) ) return (*i).second.get<T>();
0122         throw std::runtime_error("AbstractMap: Failed to access non-existing item:"+item);
0123       }
0124     };
0125 
0126   } /* End namespace cond             */
0127 } /* End namespace dd4hep                   */
0128 #endif // DD4HEP_CONDITIONSDATA_H