File indexing completed on 2025-01-30 09:18:03
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 #include "DDDB/DDDBReader.h"
0022 #include "DDDB/DDDBReaderContext.h"
0023 #include "DD4hep/Printout.h"
0024 #include "DD4hep/Primitives.h"
0025
0026
0027 #include <cstring>
0028
0029 using namespace std;
0030 using namespace dd4hep;
0031 using namespace dd4hep::DDDB;
0032
0033
0034 DDDBReader::DDDBReader(const std::string& dir)
0035 : m_directory(dir), m_match("conddb:")
0036 {
0037 m_context.valid_since = detail::makeTime(1970,1,1);
0038 m_context.valid_until = detail::makeTime(2030,1,1);
0039 m_context.event_time = detail::makeTime(2015,7,1,12,0,0);
0040 m_context.match = m_match;
0041 }
0042
0043
0044 xml::UriReader::UserContext* DDDBReader::context() {
0045 return &m_context;
0046 }
0047
0048
0049 bool DDDBReader::load(const string& system_id, string& buffer) {
0050 return xml::UriReader::load(system_id, buffer);
0051 }
0052
0053
0054 bool DDDBReader::load(const string& system_id,
0055 UserContext* ctxt,
0056 string& buffer)
0057 {
0058 if ( isBlocked(system_id) ) {
0059 buffer = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> <DDDB></DDDB>";
0060 return true;
0061 }
0062 else if ( system_id.substr(0,m_match.length()) == m_match ) {
0063 string mm = m_match + "//";
0064 size_t mm_len = mm.length();
0065 const string& sys = system_id;
0066 string id = sys.c_str() + (sys.substr(0,mm_len) == mm ? mm_len : mm_len-2);
0067
0068
0069 string::size_type at_pos = id.find('@');
0070 if ( at_pos != id.npos ) {
0071 string::size_type slash_pos = id.rfind('/',at_pos);
0072
0073 id = id.substr(0,slash_pos+1) + id.substr(at_pos+1);
0074 }
0075
0076 int ret = getObject(id, ctxt, buffer);
0077 if ( ret == 1 ) return true;
0078 printout(ERROR,"DDDBReader","++ Failed to resolve system id: %s [%s]",
0079 id.c_str(), ::strerror(errno));
0080 }
0081 return false;
0082 }
0083
0084
0085 void DDDBReader::parserLoaded(const std::string& system_id) {
0086 xml::UriReader::parserLoaded(system_id);
0087 }
0088
0089
0090 void DDDBReader::parserLoaded(const std::string& , UserContext* ctxt) {
0091 DDDBReaderContext* c = (DDDBReaderContext*)ctxt;
0092 c->valid_since = c->event_time;
0093 c->valid_until = c->event_time;
0094 }
0095
0096
0097 void DDDBReader::blockPath(const std::string& path) {
0098 m_blockedPathes.insert(path);
0099 }
0100
0101
0102 bool DDDBReader::isBlocked(const std::string& path) const {
0103 for(const auto& p : m_blockedPathes) {
0104 if ( path.find(p) != string::npos ) return true;
0105 }
0106 return false;
0107 }