DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
ConditionsXmlLoader.cpp
Go to the documentation of this file.
1 // AIDA Detector description implementation
2 //--------------------------------------------------------------------------
3 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
4 // All rights reserved.
5 //
6 // For the licensing terms see $DD4hepINSTALL/LICENSE.
7 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
8 //
9 // \author Markus Frank
10 // \date 2016-02-02
11 // \version 1.0
12 //
13 //==========================================================================
14 #ifndef DD4HEP_CONDITIONS_XMLCONDITONSLOADER_H
15 #define DD4HEP_CONDITIONS_XMLCONDITONSLOADER_H
16 
17 // Framework include files
19 #include <DD4hep/Printout.h>
20 
22 namespace dd4hep {
23 
25  namespace cond {
26 
28 
34  typedef std::vector<Condition> Buffer;
36 
37  size_t load_source (const std::string& nam,
38  key_type key,
39  const IOV& req_validity,
40  RangeConditions& conditions);
41  public:
43  ConditionsXmlLoader(Detector& description, ConditionsManager mgr, const std::string& nam);
45  virtual ~ConditionsXmlLoader();
47  virtual std::size_t load_single(key_type key,
48  const IOV& req_validity,
49  RangeConditions& conditions);
51  virtual std::size_t load_range( key_type key,
52  const IOV& req_validity,
53  RangeConditions& conditions);
55  virtual std::size_t load_many( const IOV& /* req_validity */,
56  RequiredItems& /* work */,
57  LoadedItems& /* loaded */,
58  IOV& /* conditions_validity */)
59  {
60  except("ConditionsLoader","+++ update: Invalid call!");
61  return 0;
62  }
63  };
64  } /* End namespace cond */
65 } /* End namespace dd4hep */
66 #endif /* DD4HEP_CONDITIONS_XMLCONDITONSLOADER_H */
67 
68 // #include <ConditionsXmlLoader.h>
69 #include <DD4hep/Printout.h>
70 #include <DD4hep/Factories.h>
71 #include <DD4hep/PluginCreators.h>
73 
74 #include <XML/XMLElements.h>
75 #include <XML/DocumentHandler.h>
76 #include <DDCond/ConditionsEntry.h>
77 
78 // C/C++ include files
79 #include <string>
80 
81 // Forward declartions
82 using namespace dd4hep::cond;
83 
84 namespace {
85  void* create_loader(dd4hep::Detector& description, int argc, char** argv) {
86  const char* name = argc>0 ? argv[0] : "XMLLoader";
87  ConditionsManagerObject* mgr = (ConditionsManagerObject*)(argc>0 ? argv[1] : 0);
88  return new ConditionsXmlLoader(description,ConditionsManager(mgr),name);
89  }
90 }
91 DECLARE_DD4HEP_CONSTRUCTOR(DD4hep_Conditions_xml_Loader,create_loader)
92 
93 ConditionsXmlLoader::ConditionsXmlLoader(Detector& description, ConditionsManager mgr, const std::string& nam)
95 : ConditionsDataLoader(description, mgr, nam)
96 {
97 }
98 
101 }
102 
103 size_t ConditionsXmlLoader::load_source(const std::string& nam,
104  key_type key,
105  const IOV& req_validity,
106  RangeConditions& conditions)
107 {
108  std::size_t len = conditions.size();
109  std::string fac = "XMLConditionsParser";
110  xml::DocumentHolder doc(xml::DocumentHandler().load(nam));
111  xml::Handle_t handle = doc.root();
112  ConditionsStack stack;
113  char* argv[] = { (char*)handle.ptr(), (char*)&stack, 0};
114  void* result = dd4hep::createPlugin(fac, m_detector, 2, argv, 0);
115  if ( result == &m_detector ) { // All OK.
116  for (ConditionsStack::iterator c=stack.begin(); c!=stack.end(); ++c) {
117  Entry* e = (*c);
118  Condition condition;
119  except("ConditionsXmlLoader","Fix me: queueUpdate(e) not implemented");
120  delete e;
121  if ( condition.isValid() ) {
122  if ( key == condition->hash ) {
123  if ( req_validity.contains(condition.iov()) ) {
124  conditions.emplace_back(condition);
125  continue;
126  }
127  }
128  m_buffer.emplace_back(condition);
129  }
130  }
131  }
132  m_sources.erase(m_sources.begin());
133  stack.clear();
134  return conditions.size()-len;
135 }
136 
138  const IOV& req_validity,
139  RangeConditions& conditions)
140 {
141  std::size_t len = conditions.size();
142  if ( m_buffer.empty() && !m_sources.empty() ) {
143  return load_source(m_sources.begin()->first, key, req_validity, conditions);
144  }
145  for (Buffer::iterator j=m_buffer.begin(); j!=m_buffer.end(); ++j) {
146  Condition condition = *j;
147  const IOV* iov = condition->iov;
148  if ( IOV::partial_match(req_validity,*iov) ) {
149  if ( key == condition->hash ) {
150  conditions.emplace_back(condition);
151  m_buffer.erase(j);
152  return conditions.size()-len;
153  }
154  }
155  }
156  return conditions.size()-len;
157 }
158 
160  const IOV& req_validity,
161  RangeConditions& conditions)
162 {
163  std::size_t len = conditions.size();
164  while ( !m_sources.empty() ) {
165  load_source(m_sources.begin()->first, key, req_validity, conditions);
166  }
167  std::vector<Condition> keep;
168  for (Buffer::iterator j=m_buffer.begin(); j!=m_buffer.end(); ++j) {
169  Condition condition = *j;
170  const IOV* iov = condition->iov;
171  if ( IOV::partial_match(req_validity,*iov) ) {
172  if ( key == condition->hash ) {
173  conditions.emplace_back(condition);
174  }
175  }
176  keep.emplace_back(condition);
177  }
178  m_buffer = std::move(keep);
179  return conditions.size()-len;
180 }
dd4hep::cond::ConditionsDataLoader::key_type
Condition::key_type key_type
Definition: ConditionsDataLoader.h:51
dd4hep::RangeConditions
std::vector< Condition > RangeConditions
Definition: Conditions.h:491
dd4hep::IOV::contains
bool contains(const IOV &iov) const
Check for validity containment.
Definition: IOV.cpp:180
dd4hep::cond::ConditionsXmlLoader::Buffer
std::vector< Condition > Buffer
Definition: ConditionsXmlLoader.cpp:34
cond
AlignmentCondition::Object * cond
Definition: AlignmentsCalculator.cpp:68
ConditionsInterna.h
dd4hep::cond::ConditionsXmlLoader::load_source
size_t load_source(const std::string &nam, key_type key, const IOV &req_validity, RangeConditions &conditions)
Definition: ConditionsXmlLoader.cpp:103
dd4hep::cond::ConditionsXmlLoader::load_range
virtual std::size_t load_range(key_type key, const IOV &req_validity, RangeConditions &conditions)
Load a condition set given a Detector Element and the conditions name according to their validity.
Definition: ConditionsXmlLoader.cpp:159
ConditionsDataLoader.h
dd4hep::cond::ConditionsDataLoader::m_sources
Sources m_sources
Property: input data source definitions.
Definition: ConditionsDataLoader.h:62
dd4hep::Handle::isValid
bool isValid() const
Check the validity of the object held by the handle.
Definition: Handle.h:128
dd4hep::xml::Handle_t
Class to easily access the properties of single XmlElements.
Definition: XMLElements.h:380
Factories.h
dd4hep::cond::ConditionsXmlLoader::load_many
virtual std::size_t load_many(const IOV &, RequiredItems &, LoadedItems &, IOV &)
Optimized update using conditions slice data.
Definition: ConditionsXmlLoader.cpp:55
DocumentHandler.h
ConditionsEntry.h
dd4hep::cond::ConditionsManagerObject
Basic conditions manager implementation.
Definition: ConditionsManagerObject.h:54
dd4hep::Condition
Main condition object handle.
Definition: Conditions.h:51
dd4hep::cond::ConditionsXmlLoader::~ConditionsXmlLoader
virtual ~ConditionsXmlLoader()
Default destructor.
Definition: ConditionsXmlLoader.cpp:100
dd4hep::cond
Namespace for implementation details of the AIDA detector description toolkit.
Definition: ConditionsCleanup.h:23
dd4hep::cond::ConditionsXmlLoader
Implementation of a stack of conditions assembled before application.
Definition: ConditionsXmlLoader.cpp:33
dd4hep::createPlugin
void * createPlugin(const std::string &factory, Detector &description, void *(*cast)(void *))
Handler for factories of type: ConstructionFactory.
Definition: PluginCreators.cpp:90
dd4hep::IOV
Class describing the interval of validty.
Definition: IOV.h:67
dd4hep::cond::ConditionsDataLoader::RequiredItems
std::vector< std::pair< key_type, ConditionsLoadInfo * > > RequiredItems
Definition: ConditionsDataLoader.h:54
DECLARE_DD4HEP_CONSTRUCTOR
#define DECLARE_DD4HEP_CONSTRUCTOR(name, func)
Definition: Factories.h:291
dd4hep::cond::ConditionsXmlLoader::ConditionsXmlLoader
ConditionsXmlLoader(Detector &description, ConditionsManager mgr, const std::string &nam)
Default constructor.
Definition: ConditionsXmlLoader.cpp:94
dd4hep::xml::DocumentHolder
Class supporting the basic functionality of an XML document including ownership.
Definition: XMLElements.h:741
dd4hep::IOV::partial_match
static bool partial_match(const IOV &iov, const IOV &test)
Check if IOV 'test' is of same type and is at least partially contained in iov.
Definition: IOV.h:176
dd4hep::cond::ConditionsStack
std::list< Entry * > ConditionsStack
Definition: ConditionsDataLoader.h:34
dd4hep::cond::ConditionsManager
Manager class for condition handles.
Definition: ConditionsManager.h:46
key
unsigned char key
Definition: AlignmentsCalculator.cpp:69
dd4hep::cond::ConditionsDataLoader
Interface for a generic conditions loader.
Definition: ConditionsDataLoader.h:46
dd4hep::xml::DocumentHandler
Class supporting to read and parse XML documents.
Definition: DocumentHandler.h:39
XMLElements.h
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::cond::ConditionsXmlLoader::m_buffer
Buffer m_buffer
Definition: ConditionsXmlLoader.cpp:35
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::Condition::iov
const IOV & iov() const
Access the IOV block.
Definition: Conditions.cpp:139
PluginCreators.h
handle
void handle(const O *o, const C &c, F pmf)
Definition: LCDDConverter.cpp:1105
dd4hep::cond::ConditionsXmlLoader::load_single
virtual std::size_t load_single(key_type key, const IOV &req_validity, RangeConditions &conditions)
Load a condition set given a Detector Element and the conditions name according to their validity.
Definition: ConditionsXmlLoader.cpp:137
dd4hep::cond::Entry
The intermediate conditions data used to populate the DetElement conditions.
Definition: ConditionsEntry.h:36
dd4hep::xml::Document::root
Handle_t root() const
Access the ROOT eleemnt of the DOM document.
Definition: XMLElements.cpp:1040