File indexing completed on 2025-01-30 09:16:29
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef DD4HEP_CONDITIONS_XMLCONDITONSLOADER_H
0015 #define DD4HEP_CONDITIONS_XMLCONDITONSLOADER_H
0016
0017
0018 #include <DDCond/ConditionsDataLoader.h>
0019 #include <DD4hep/Printout.h>
0020
0021
0022 namespace dd4hep {
0023
0024
0025 namespace cond {
0026
0027
0028
0029
0030
0031
0032
0033 class ConditionsXmlLoader : public ConditionsDataLoader {
0034 typedef std::vector<Condition> Buffer;
0035 Buffer m_buffer;
0036
0037 size_t load_source (const std::string& nam,
0038 key_type key,
0039 const IOV& req_validity,
0040 RangeConditions& conditions);
0041 public:
0042
0043 ConditionsXmlLoader(Detector& description, ConditionsManager mgr, const std::string& nam);
0044
0045 virtual ~ConditionsXmlLoader();
0046
0047 virtual std::size_t load_single(key_type key,
0048 const IOV& req_validity,
0049 RangeConditions& conditions);
0050
0051 virtual std::size_t load_range( key_type key,
0052 const IOV& req_validity,
0053 RangeConditions& conditions);
0054
0055 virtual std::size_t load_many( const IOV& ,
0056 RequiredItems& ,
0057 LoadedItems& ,
0058 IOV& )
0059 {
0060 except("ConditionsLoader","+++ update: Invalid call!");
0061 return 0;
0062 }
0063 };
0064 }
0065 }
0066 #endif
0067
0068
0069 #include <DD4hep/Printout.h>
0070 #include <DD4hep/Factories.h>
0071 #include <DD4hep/PluginCreators.h>
0072 #include <DD4hep/detail/ConditionsInterna.h>
0073
0074 #include <XML/XMLElements.h>
0075 #include <XML/DocumentHandler.h>
0076 #include <DDCond/ConditionsEntry.h>
0077
0078
0079 #include <string>
0080
0081
0082 using namespace dd4hep::cond;
0083
0084 namespace {
0085 void* create_loader(dd4hep::Detector& description, int argc, char** argv) {
0086 const char* name = argc>0 ? argv[0] : "XMLLoader";
0087 ConditionsManagerObject* mgr = (ConditionsManagerObject*)(argc>0 ? argv[1] : 0);
0088 return new ConditionsXmlLoader(description,ConditionsManager(mgr),name);
0089 }
0090 }
0091 DECLARE_DD4HEP_CONSTRUCTOR(DD4hep_Conditions_xml_Loader,create_loader)
0092
0093
0094 ConditionsXmlLoader::ConditionsXmlLoader(Detector& description, ConditionsManager mgr, const std::string& nam)
0095 : ConditionsDataLoader(description, mgr, nam)
0096 {
0097 }
0098
0099
0100 ConditionsXmlLoader::~ConditionsXmlLoader() {
0101 }
0102
0103 size_t ConditionsXmlLoader::load_source(const std::string& nam,
0104 key_type key,
0105 const IOV& req_validity,
0106 RangeConditions& conditions)
0107 {
0108 std::size_t len = conditions.size();
0109 std::string fac = "XMLConditionsParser";
0110 xml::DocumentHolder doc(xml::DocumentHandler().load(nam));
0111 xml::Handle_t handle = doc.root();
0112 ConditionsStack stack;
0113 char* argv[] = { (char*)handle.ptr(), (char*)&stack, 0};
0114 void* result = dd4hep::createPlugin(fac, m_detector, 2, argv, 0);
0115 if ( result == &m_detector ) {
0116 for (ConditionsStack::iterator c=stack.begin(); c!=stack.end(); ++c) {
0117 Entry* e = (*c);
0118 Condition condition;
0119 except("ConditionsXmlLoader","Fix me: queueUpdate(e) not implemented");
0120 delete e;
0121 if ( condition.isValid() ) {
0122 if ( key == condition->hash ) {
0123 if ( req_validity.contains(condition.iov()) ) {
0124 conditions.emplace_back(condition);
0125 continue;
0126 }
0127 }
0128 m_buffer.emplace_back(condition);
0129 }
0130 }
0131 }
0132 m_sources.erase(m_sources.begin());
0133 stack.clear();
0134 return conditions.size()-len;
0135 }
0136
0137 std::size_t ConditionsXmlLoader::load_single(key_type key,
0138 const IOV& req_validity,
0139 RangeConditions& conditions)
0140 {
0141 std::size_t len = conditions.size();
0142 if ( m_buffer.empty() && !m_sources.empty() ) {
0143 return load_source(m_sources.begin()->first, key, req_validity, conditions);
0144 }
0145 for (Buffer::iterator j=m_buffer.begin(); j!=m_buffer.end(); ++j) {
0146 Condition condition = *j;
0147 const IOV* iov = condition->iov;
0148 if ( IOV::partial_match(req_validity,*iov) ) {
0149 if ( key == condition->hash ) {
0150 conditions.emplace_back(condition);
0151 m_buffer.erase(j);
0152 return conditions.size()-len;
0153 }
0154 }
0155 }
0156 return conditions.size()-len;
0157 }
0158
0159 std::size_t ConditionsXmlLoader::load_range(key_type key,
0160 const IOV& req_validity,
0161 RangeConditions& conditions)
0162 {
0163 std::size_t len = conditions.size();
0164 while ( !m_sources.empty() ) {
0165 load_source(m_sources.begin()->first, key, req_validity, conditions);
0166 }
0167 std::vector<Condition> keep;
0168 for (Buffer::iterator j=m_buffer.begin(); j!=m_buffer.end(); ++j) {
0169 Condition condition = *j;
0170 const IOV* iov = condition->iov;
0171 if ( IOV::partial_match(req_validity,*iov) ) {
0172 if ( key == condition->hash ) {
0173 conditions.emplace_back(condition);
0174 }
0175 }
0176 keep.emplace_back(condition);
0177 }
0178 m_buffer = std::move(keep);
0179 return conditions.size()-len;
0180 }