DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
ConditionsMultiLoader.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // \author Markus Frank
11 // \date 2016-02-02
12 // \version 1.0
13 //
14 //==========================================================================
15 #ifndef DD4HEP_CONDITIONS_MULTICONDITONSLOADER_H
16 #define DD4HEP_CONDITIONS_MULTICONDITONSLOADER_H
17 
18 // Framework include files
20 #include <DD4hep/Printout.h>
21 
23 namespace dd4hep {
24 
26  namespace cond {
27 
28  // Forward declarations
29  class ConditionsHandler;
30 
32 
38  typedef std::map<std::string, ConditionsDataLoader*> Loaders;
39  typedef std::map<std::string, ConditionsDataLoader*> OpenSources;
40 
43  ConditionsDataLoader* load_source(const std::string& nam,const IOV& req_validity);
44 
45  public:
47  ConditionsMultiLoader(Detector& description, ConditionsManager mgr, const std::string& nam);
49  virtual ~ConditionsMultiLoader();
50 #if 0
51  virtual size_t load_single(key_type key,
53  const IOV& req_validity,
54  RangeConditions& conditions);
56  virtual size_t load_range( key_type key,
57  const IOV& req_validity,
58  RangeConditions& conditions);
59 #endif
60  virtual size_t load_many( const IOV& /* req_validity */,
62  RequiredItems& /* work */,
63  LoadedItems& /* loaded */,
64  IOV& /* conditions_validity */)
65  {
66  except("ConditionsLoader","+++ update: Invalid call!");
67  return 0;
68  }
69  };
70  } /* End namespace detail */
71 } /* End namespace dd4hep */
72 #endif /* DD4HEP_CONDITIONS_MULTICONDITONSLOADER_H */
73 
74 // AIDA Detector description implementation
75 //--------------------------------------------------------------------------
76 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
77 // All rights reserved.
78 //
79 // For the licensing terms see $DD4hepINSTALL/LICENSE.
80 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
81 //
82 // \author Markus Frank
83 // \date 2016-02-02
84 // \version 1.0
85 //
86 //==========================================================================
87 
88 // Framework include files
89 //#include <ConditionsMultiLoader.h>
90 #include <DD4hep/Printout.h>
91 #include <DD4hep/Factories.h>
92 #include <DD4hep/PluginCreators.h>
94 
95 // Forward declartions
96 using namespace dd4hep::cond;
97 
98 namespace {
99  void* create_loader(dd4hep::Detector& description, int argc, char** argv) {
100  const char* name = argc>0 ? argv[0] : "MULTILoader";
101  ConditionsManager::Object* mgr = (ConditionsManager::Object*)(argc>0 ? argv[1] : 0);
102  return new ConditionsMultiLoader(description,ConditionsManager(mgr),name);
103  }
104 }
105 DECLARE_DD4HEP_CONSTRUCTOR(DD4hep_Conditions_multi_Loader,create_loader)
106 
107 ConditionsMultiLoader::ConditionsMultiLoader(Detector& description, ConditionsManager mgr, const std::string& nam)
109 : ConditionsDataLoader(description, mgr, nam)
110 {
111 }
112 
115 }
116 
118 ConditionsMultiLoader::load_source(const std::string& nam,
119  const IOV& req_validity)
120 {
121  OpenSources::iterator iop = m_openSources.find(nam);
122  if ( iop == m_openSources.end() ) {
123  size_t idx = nam.find(':');
124  if ( idx == std::string::npos ) {
125  except("ConditionsMultiLoader","Invalid data source specification: "+nam);
126  }
127  std::string ident = nam.substr(0,idx);
128  Loaders::iterator ild = m_loaders.find(ident);
129  ConditionsDataLoader* loader = 0;
130  if ( ild == m_loaders.end() ) {
131  std::string typ = "DD4hep_Conditions_"+ident+"_Loader";
132  std::string fac = ident+"_ConditionsDataLoader";
133  const void* argv[] = {fac.c_str(), m_mgr.ptr(), 0};
134  loader = createPlugin<ConditionsDataLoader>(typ,m_detector,2,argv);
135  if ( !loader ) {
136  except("ConditionsMultiLoader",
137  "Failed to create conditions loader of type: "+typ+" to read:"+nam);
138  }
139  }
140  else {
141  loader = (*ild).second;
142  }
143  loader->addSource(nam.substr(idx+1),req_validity);
144  m_loaders[ident] = loader;
145  m_openSources[nam] = loader;
146  return loader;
147  }
148  return (*iop).second;
149 }
150 #if 0
151 size_t ConditionsMultiLoader::load_range(key_type key,
153  const IOV& req_validity,
154  RangeConditions& conditions)
155 {
156  size_t len = conditions.size();
157  // No better idea: Must chack all sources to find the required condition
158  for(Sources::const_iterator i=m_sources.begin(); i != m_sources.end(); ++i) {
159  const IOV& iov = (*i).second;
160  if ( iov.type == req_validity.type ) {
161  if ( IOV::key_partially_contained(iov.keyData,req_validity.keyData) ) {
162  const std::string& nam = (*i).first;
163  ConditionsDataLoader* loader = load_source(nam, req_validity);
164  loader->load_range(key, req_validity, conditions);
165  }
166  }
167  }
168  return conditions.size() - len;
169 }
170 
171 
172 size_t ConditionsMultiLoader::load_single(key_type key,
173  const IOV& req_validity,
174  RangeConditions& conditions)
175 {
176  size_t len = conditions.size();
177  // No better idea: Must chack all sources to find the required condition
178  for(Sources::const_iterator i=m_sources.begin(); i != m_sources.end(); ++i) {
179  const IOV& iov = (*i).second;
180  if ( iov.type == req_validity.type ) {
181  if ( IOV::key_partially_contained(iov.keyData,req_validity.keyData) ) {
182  const std::string& nam = (*i).first;
183  ConditionsDataLoader* loader = load_source(nam, req_validity);
184  loader->load_single(key, req_validity, conditions);
185  }
186  }
187  }
188  return conditions.size() - len;
189 }
190 #endif
dd4hep::cond::ConditionsMultiLoader::Loaders
std::map< std::string, ConditionsDataLoader * > Loaders
Definition: ConditionsMultiLoader.cpp:38
dd4hep::cond::ConditionsDataLoader::key_type
Condition::key_type key_type
Definition: ConditionsDataLoader.h:51
dd4hep::RangeConditions
std::vector< Condition > RangeConditions
Definition: Conditions.h:491
cond
AlignmentCondition::Object * cond
Definition: AlignmentsCalculator.cpp:68
dd4hep::IOV::key_partially_contained
static bool key_partially_contained(const Key &key, const Key &test)
Check if IOV 'test' has an overlap on the upper interval edge with IOV 'key'.
Definition: IOV.h:165
dd4hep::cond::ConditionsMultiLoader::~ConditionsMultiLoader
virtual ~ConditionsMultiLoader()
Default destructor.
Definition: ConditionsMultiLoader.cpp:114
dd4hep::cond::ConditionsMultiLoader::load_source
ConditionsDataLoader * load_source(const std::string &nam, const IOV &req_validity)
Definition: ConditionsMultiLoader.cpp:118
ConditionsDataLoader.h
dd4hep::cond::ConditionsDataLoader::m_sources
Sources m_sources
Property: input data source definitions.
Definition: ConditionsDataLoader.h:62
dd4hep::cond::ConditionsMultiLoader::OpenSources
std::map< std::string, ConditionsDataLoader * > OpenSources
Definition: ConditionsMultiLoader.cpp:39
ConditionsManager.h
Factories.h
dd4hep::cond::ConditionsDataLoader::addSource
void addSource(const std::string &source)
Add data source definition to loader.
Definition: ConditionsDataLoader.cpp:53
dd4hep::cond::ConditionsManagerObject
Basic conditions manager implementation.
Definition: ConditionsManagerObject.h:54
dd4hep::cond
Namespace for implementation details of the AIDA detector description toolkit.
Definition: ConditionsCleanup.h:23
dd4hep::IOV
Class describing the interval of validty.
Definition: IOV.h:67
dd4hep::cond::ConditionsMultiLoader
Implementation of a stack of conditions assembled before application.
Definition: ConditionsMultiLoader.cpp:37
dd4hep::cond::ConditionsDataLoader::m_mgr
ConditionsManager m_mgr
Reference to conditions manager used to queue update requests.
Definition: ConditionsDataLoader.h:60
dd4hep::cond::ConditionsDataLoader::RequiredItems
std::vector< std::pair< key_type, ConditionsLoadInfo * > > RequiredItems
Definition: ConditionsDataLoader.h:54
dd4hep::IOV::keyData
Key keyData
IOV key (if second==first, discrete, otherwise range)
Definition: IOV.h:82
DECLARE_DD4HEP_CONSTRUCTOR
#define DECLARE_DD4HEP_CONSTRUCTOR(name, func)
Definition: Factories.h:291
dd4hep::cond::ConditionsMultiLoader::m_openSources
OpenSources m_openSources
Definition: ConditionsMultiLoader.cpp:42
dd4hep::cond::ConditionsManager
Manager class for condition handles.
Definition: ConditionsManager.h:46
dd4hep::IOV::type
unsigned int type
IOV buffer type: Must be a bitmap!
Definition: IOV.h:86
dd4hep::cond::ConditionsMultiLoader::load_many
virtual size_t load_many(const IOV &, RequiredItems &, LoadedItems &, IOV &)
Optimized update using conditions slice data.
Definition: ConditionsMultiLoader.cpp:61
key
unsigned char key
Definition: AlignmentsCalculator.cpp:69
dd4hep::cond::ConditionsDataLoader
Interface for a generic conditions loader.
Definition: ConditionsDataLoader.h:46
dd4hep::Handle::ptr
T * ptr() const
Access to the held object.
Definition: Handle.h:153
dd4hep::cond::ConditionsMultiLoader::ConditionsMultiLoader
ConditionsMultiLoader(Detector &description, ConditionsManager mgr, const std::string &nam)
Default constructor.
Definition: ConditionsMultiLoader.cpp:108
dd4hep::cond::ConditionsDataLoader::m_detector
Detector & m_detector
Reference to main detector description object.
Definition: ConditionsDataLoader.h:58
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::Detector
The main interface to the dd4hep detector description package.
Definition: Detector.h:90
dd4hep::cond::ConditionsDataLoader::LoadedItems
std::map< key_type, Condition > LoadedItems
Definition: ConditionsDataLoader.h:53
Printout.h
dd4hep::cond::ConditionsMultiLoader::m_loaders
Loaders m_loaders
Definition: ConditionsMultiLoader.cpp:41
PluginCreators.h