Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:16:28

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  Markus Frank
0011 //  \date    2016-02-02
0012 //  \version 1.0
0013 //
0014 //==========================================================================
0015 #ifndef DD4HEP_CONDITIONS_MULTICONDITONSLOADER_H
0016 #define DD4HEP_CONDITIONS_MULTICONDITONSLOADER_H
0017 
0018 // Framework include files
0019 #include <DDCond/ConditionsDataLoader.h>
0020 #include <DD4hep/Printout.h>
0021 
0022 /// Namespace for the AIDA detector description toolkit
0023 namespace dd4hep {
0024 
0025   /// Namespace for implementation details of the AIDA detector description toolkit
0026   namespace cond  {
0027 
0028     // Forward declarations
0029     class ConditionsHandler;
0030 
0031     /// Implementation of a stack of conditions assembled before application
0032     /** 
0033      *  \author   M.Frank
0034      *  \version  1.0
0035      *  \ingroup  DD4HEP_CONDITIONS
0036      */
0037     class ConditionsMultiLoader : public ConditionsDataLoader   {
0038       typedef std::map<std::string, ConditionsDataLoader*> Loaders;
0039       typedef std::map<std::string, ConditionsDataLoader*> OpenSources;
0040 
0041       Loaders m_loaders;
0042       OpenSources m_openSources;
0043       ConditionsDataLoader* load_source(const std::string& nam,const IOV& req_validity);
0044 
0045     public:
0046       /// Default constructor
0047       ConditionsMultiLoader(Detector& description, ConditionsManager mgr, const std::string& nam);
0048       /// Default destructor
0049       virtual ~ConditionsMultiLoader();
0050 #if 0
0051       /// Load  a condition set given a Detector Element and the conditions name according to their validity
0052       virtual size_t load_single(key_type key,
0053                                  const IOV& req_validity,
0054                                  RangeConditions& conditions);
0055       /// Load  a condition set given a Detector Element and the conditions name according to their validity
0056       virtual size_t load_range( key_type key,
0057                                  const IOV& req_validity,
0058                                  RangeConditions& conditions);
0059 #endif
0060       /// Optimized update using conditions slice data
0061       virtual size_t load_many(  const IOV& /* req_validity */,
0062                                  RequiredItems&  /* work         */,
0063                                  LoadedItems&    /* loaded       */,
0064                                  IOV&       /* conditions_validity */)
0065       {
0066         except("ConditionsLoader","+++ update: Invalid call!");
0067         return 0;
0068       }
0069     };
0070   }     /* End namespace detail                     */
0071 }       /* End namespace dd4hep                       */
0072 #endif  /* DD4HEP_CONDITIONS_MULTICONDITONSLOADER_H   */
0073 
0074 //  AIDA Detector description implementation 
0075 //--------------------------------------------------------------------------
0076 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0077 // All rights reserved.
0078 //
0079 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0080 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0081 //
0082 //  \author  Markus Frank
0083 //  \date    2016-02-02
0084 //  \version 1.0
0085 //
0086 //==========================================================================
0087 
0088 // Framework include files
0089 //#include <ConditionsMultiLoader.h>
0090 #include <DD4hep/Printout.h>
0091 #include <DD4hep/Factories.h>
0092 #include <DD4hep/PluginCreators.h>
0093 #include <DDCond/ConditionsManager.h>
0094 
0095 // Forward declartions
0096 using namespace dd4hep::cond;
0097 
0098 namespace {
0099   void* create_loader(dd4hep::Detector& description, int argc, char** argv)   {
0100     const char* name = argc>0 ? argv[0] : "MULTILoader";
0101     ConditionsManager::Object* mgr = (ConditionsManager::Object*)(argc>0 ? argv[1] : 0);
0102     return new ConditionsMultiLoader(description,ConditionsManager(mgr),name);
0103   }
0104 }
0105 DECLARE_DD4HEP_CONSTRUCTOR(DD4hep_Conditions_multi_Loader,create_loader)
0106 
0107 /// Standard constructor, initializes variables
0108 ConditionsMultiLoader::ConditionsMultiLoader(Detector& description, ConditionsManager mgr, const std::string& nam) 
0109 : ConditionsDataLoader(description, mgr, nam)
0110 {
0111 }
0112 
0113 /// Default Destructor
0114 ConditionsMultiLoader::~ConditionsMultiLoader() {
0115 } 
0116 
0117 ConditionsDataLoader* 
0118 ConditionsMultiLoader::load_source(const std::string& nam,
0119                                    const IOV& req_validity)
0120 {
0121   OpenSources::iterator iop = m_openSources.find(nam);
0122   if ( iop == m_openSources.end() )  {
0123     size_t idx = nam.find(':');
0124     if ( idx == std::string::npos )   {
0125       except("ConditionsMultiLoader","Invalid data source specification: "+nam);
0126     }
0127     std::string ident = nam.substr(0,idx);
0128     Loaders::iterator ild = m_loaders.find(ident);
0129     ConditionsDataLoader* loader = 0;
0130     if ( ild == m_loaders.end() )  {
0131       std::string typ = "DD4hep_Conditions_"+ident+"_Loader";
0132       std::string fac = ident+"_ConditionsDataLoader";
0133       const void* argv[] = {fac.c_str(), m_mgr.ptr(), 0};
0134       loader = createPlugin<ConditionsDataLoader>(typ,m_detector,2,argv);
0135       if ( !loader )  {
0136         except("ConditionsMultiLoader",
0137                "Failed to create conditions loader of type: "+typ+" to read:"+nam);
0138       }
0139     }
0140     else  {
0141       loader = (*ild).second;
0142     }
0143     loader->addSource(nam.substr(idx+1),req_validity);
0144     m_loaders[ident] = loader;
0145     m_openSources[nam] = loader;
0146     return loader;
0147   }
0148   return (*iop).second;
0149 }
0150 #if 0
0151 /// Load  a condition set given a Detector Element and the conditions name according to their validity
0152 size_t ConditionsMultiLoader::load_range(key_type key,
0153                                          const IOV& req_validity,
0154                                          RangeConditions& conditions)
0155 {
0156   size_t len = conditions.size();
0157   // No better idea: Must chack all sources to find the required condition
0158   for(Sources::const_iterator i=m_sources.begin(); i != m_sources.end(); ++i)  {
0159     const IOV& iov = (*i).second;
0160     if ( iov.type == req_validity.type )  {
0161       if ( IOV::key_partially_contained(iov.keyData,req_validity.keyData) )  { 
0162         const std::string& nam = (*i).first;
0163         ConditionsDataLoader* loader = load_source(nam, req_validity);
0164         loader->load_range(key, req_validity, conditions);
0165       }
0166     }
0167   }
0168   return conditions.size() - len;
0169 }
0170 
0171 
0172 size_t ConditionsMultiLoader::load_single(key_type key,
0173                                           const IOV& req_validity,
0174                                           RangeConditions& conditions)
0175 {
0176   size_t len = conditions.size();
0177   // No better idea: Must chack all sources to find the required condition
0178   for(Sources::const_iterator i=m_sources.begin(); i != m_sources.end(); ++i)  {
0179     const IOV& iov = (*i).second;
0180     if ( iov.type == req_validity.type )  {
0181       if ( IOV::key_partially_contained(iov.keyData,req_validity.keyData) )  {
0182         const std::string& nam = (*i).first;
0183         ConditionsDataLoader* loader = load_source(nam, req_validity);
0184         loader->load_single(key, req_validity, conditions);
0185       }
0186     }
0187   }
0188   return conditions.size() - len;
0189 }
0190 #endif