File indexing completed on 2025-01-30 09:16:28
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef DD4HEP_CONDITIONS_MULTICONDITONSLOADER_H
0016 #define DD4HEP_CONDITIONS_MULTICONDITONSLOADER_H
0017
0018
0019 #include <DDCond/ConditionsDataLoader.h>
0020 #include <DD4hep/Printout.h>
0021
0022
0023 namespace dd4hep {
0024
0025
0026 namespace cond {
0027
0028
0029 class ConditionsHandler;
0030
0031
0032
0033
0034
0035
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
0047 ConditionsMultiLoader(Detector& description, ConditionsManager mgr, const std::string& nam);
0048
0049 virtual ~ConditionsMultiLoader();
0050 #if 0
0051
0052 virtual size_t load_single(key_type key,
0053 const IOV& req_validity,
0054 RangeConditions& conditions);
0055
0056 virtual size_t load_range( key_type key,
0057 const IOV& req_validity,
0058 RangeConditions& conditions);
0059 #endif
0060
0061 virtual size_t load_many( const IOV& ,
0062 RequiredItems& ,
0063 LoadedItems& ,
0064 IOV& )
0065 {
0066 except("ConditionsLoader","+++ update: Invalid call!");
0067 return 0;
0068 }
0069 };
0070 }
0071 }
0072 #endif
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090 #include <DD4hep/Printout.h>
0091 #include <DD4hep/Factories.h>
0092 #include <DD4hep/PluginCreators.h>
0093 #include <DDCond/ConditionsManager.h>
0094
0095
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
0108 ConditionsMultiLoader::ConditionsMultiLoader(Detector& description, ConditionsManager mgr, const std::string& nam)
0109 : ConditionsDataLoader(description, mgr, nam)
0110 {
0111 }
0112
0113
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
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
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
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