Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:18:03

0001 //==========================================================================
0002 //  AIDA Detector description implementation 
0003 //--------------------------------------------------------------------------
0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 // All rights reserved.
0006 //
0007 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 //
0010 // Author     : M.Frank
0011 //
0012 //==========================================================================
0013 //
0014 // DDDB is a detector description convention developed by the LHCb experiment.
0015 // For further information concerning the DTD, please see:
0016 // http://lhcb-comp.web.cern.ch/lhcb-comp/Frameworks/DetDesc/Documents/lhcbDtd.pdf
0017 //
0018 //==========================================================================
0019 
0020 // Framework includes
0021 #include "DDDB/DDDBReader.h"
0022 #include "DDDB/DDDBReaderContext.h"
0023 #include "DD4hep/Printout.h"
0024 #include "DD4hep/Primitives.h"
0025 
0026 // C/C++ include files
0027 #include <cstring>
0028 
0029 using namespace std;
0030 using namespace dd4hep;
0031 using namespace dd4hep::DDDB;
0032 
0033 /// Standard constructor
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 /// Access to local context
0044 xml::UriReader::UserContext* DDDBReader::context()    {
0045   return &m_context;
0046 }
0047 
0048 /// Resolve a given URI to a string containing the data
0049 bool DDDBReader::load(const string& system_id, string& buffer)   {
0050   return xml::UriReader::load(system_id, buffer);
0051 }
0052 
0053 /// Resolve a given URI to a string containing the data
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     // Extract the COOL field name from the condition path
0068     // "conddb:/path/to/field@folder"
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       // always remove '@' from the path
0073       id = id.substr(0,slash_pos+1) +  id.substr(at_pos+1);
0074     }
0075     // GET: 1458055061070516000 /lhcb.xml 0 0 SUCCESS
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 /// Inform reader about a locally (e.g. by XercesC) handled source load
0085 void DDDBReader::parserLoaded(const std::string& system_id)  {
0086   xml::UriReader::parserLoaded(system_id);
0087 }
0088 
0089 /// Inform reader about a locally (e.g. by XercesC) handled source load
0090 void DDDBReader::parserLoaded(const std::string& /* system_id */, UserContext* ctxt)  {
0091   DDDBReaderContext* c = (DDDBReaderContext*)ctxt;
0092   c->valid_since = c->event_time;
0093   c->valid_until = c->event_time;
0094 }
0095 
0096 /// Add a blocked path entry
0097 void DDDBReader::blockPath(const std::string& path)  {
0098   m_blockedPathes.insert(path);
0099 }
0100 
0101 /// Check if a URI path is blocked
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 }