Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:16:29

0001 //  AIDA Detector description implementation 
0002 //--------------------------------------------------------------------------
0003 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0004 // All rights reserved.
0005 //
0006 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0007 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0008 //
0009 //  \author  Markus Frank
0010 //  \date    2016-02-02
0011 //  \version 1.0
0012 //
0013 //==========================================================================
0014 #ifndef DD4HEP_CONDITIONS_XMLCONDITONSLOADER_H
0015 #define DD4HEP_CONDITIONS_XMLCONDITONSLOADER_H
0016 
0017 // Framework include files
0018 #include <DDCond/ConditionsDataLoader.h>
0019 #include <DD4hep/Printout.h>
0020 
0021 /// Namespace for the AIDA detector description toolkit
0022 namespace dd4hep {
0023 
0024   /// Namespace for implementation details of the AIDA detector description toolkit
0025   namespace cond  {
0026 
0027     /// Implementation of a stack of conditions assembled before application
0028     /** 
0029      *  \author   M.Frank
0030      *  \version  1.0
0031      *  \ingroup  DD4HEP_CONDITIONS
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       /// Default constructor
0043       ConditionsXmlLoader(Detector& description, ConditionsManager mgr, const std::string& nam);
0044       /// Default destructor
0045       virtual ~ConditionsXmlLoader();
0046       /// Load  a condition set given a Detector Element and the conditions name according to their validity
0047       virtual std::size_t load_single(key_type key,
0048                                       const IOV& req_validity,
0049                                       RangeConditions& conditions);
0050       /// Load  a condition set given a Detector Element and the conditions name according to their validity
0051       virtual std::size_t load_range( key_type key,
0052                                       const IOV& req_validity,
0053                                       RangeConditions& conditions);
0054       /// Optimized update using conditions slice data
0055       virtual std::size_t load_many(  const IOV& /* req_validity */,
0056                                       RequiredItems&  /* work         */,
0057                                       LoadedItems&    /* loaded       */,
0058                                       IOV&       /* conditions_validity */)
0059       {
0060         except("ConditionsLoader","+++ update: Invalid call!");
0061         return 0;
0062       }
0063     };
0064   }    /* End namespace cond                */
0065 }      /* End namespace dd4hep                    */
0066 #endif /* DD4HEP_CONDITIONS_XMLCONDITONSLOADER_H  */
0067 
0068 // #include <ConditionsXmlLoader.h>
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 // C/C++ include files
0079 #include <string>
0080 
0081 // Forward declartions
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 /// Standard constructor, initializes variables
0094 ConditionsXmlLoader::ConditionsXmlLoader(Detector& description, ConditionsManager mgr, const std::string& nam) 
0095 : ConditionsDataLoader(description, mgr, nam)
0096 {
0097 }
0098 
0099 /// Default Destructor
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 )  { // All OK.
0116     for (ConditionsStack::iterator c=stack.begin(); c!=stack.end(); ++c)  {
0117       Entry* e = (*c);
0118       Condition condition;/// = queueUpdate(e);
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 }