File indexing completed on 2025-10-30 07:56:01
0001 
0002 
0003 
0004 
0005 
0006 
0007 
0008 
0009 
0010 
0011 
0012 
0013 
0014 #ifndef DD4HEP_CONDITIONS_CONDIITONSSNAPSHOTROOTLOADER_H
0015 #define DD4HEP_CONDITIONS_CONDIITONSSNAPSHOTROOTLOADER_H
0016 
0017 
0018 #include <DDCond/ConditionsDataLoader.h>
0019 #include <DDCond/ConditionsRootPersistency.h>
0020 #include <DD4hep/Printout.h>
0021 
0022 
0023 namespace dd4hep {
0024 
0025   
0026   namespace cond  {
0027 
0028     
0029     
0030 
0031 
0032 
0033 
0034     class ConditionsSnapshotRootLoader : public ConditionsDataLoader   {
0035       std::vector<ConditionsRootPersistency*> buffers;
0036       void load_source  (const std::string& nam);
0037     public:
0038       
0039       ConditionsSnapshotRootLoader(Detector& description, ConditionsManager mgr, const std::string& nam);
0040       
0041       virtual ~ConditionsSnapshotRootLoader();
0042       
0043       virtual size_t load_single(key_type key,
0044                                  const IOV& req_validity,
0045                                  RangeConditions& conditions);
0046       
0047       virtual size_t load_range( key_type key,
0048                                  const IOV& req_validity,
0049                                  RangeConditions& conditions);
0050       
0051       virtual size_t load_many(  const IOV& ,
0052                                  RequiredItems&  ,
0053                                  LoadedItems&    ,
0054                                  IOV&       )
0055       {
0056         except("ConditionsLoader","+++ update: Invalid call!");
0057         return 0;
0058       }
0059     };
0060   }    
0061 }      
0062 #endif 
0063 
0064 
0065 #include <DD4hep/Printout.h>
0066 #include <DD4hep/Factories.h>
0067 #include <DD4hep/PluginCreators.h>
0068 #include <DD4hep/detail/ConditionsInterna.h>
0069 
0070 #include <TFile.h>
0071 
0072 
0073 #include <string>
0074 
0075 
0076 using namespace dd4hep::cond;
0077 
0078 namespace {
0079   void* create_loader(dd4hep::Detector& description, int argc, char** argv)   {
0080     const char* name = argc>0 ? argv[0] : "XMLLoader";
0081     ConditionsManagerObject* mgr = (ConditionsManagerObject*)(argc>0 ? argv[1] : 0);
0082     return new ConditionsSnapshotRootLoader(description,ConditionsManager(mgr),name);
0083   }
0084 }
0085 DECLARE_DD4HEP_CONSTRUCTOR(DD4hep_Conditions_root_snapshot_Loader,create_loader)
0086 
0087 
0088 ConditionsSnapshotRootLoader::ConditionsSnapshotRootLoader(Detector& description, ConditionsManager mgr, const std::string& nam) 
0089 : ConditionsDataLoader(description, mgr, nam)
0090 {
0091 }
0092 
0093 
0094 ConditionsSnapshotRootLoader::~ConditionsSnapshotRootLoader() {
0095   buffers.clear();
0096 } 
0097 
0098 void ConditionsSnapshotRootLoader::load_source(const std::string& nam)  {
0099   TFile* f = TFile::Open(nam.c_str());
0100   std::unique_ptr<ConditionsRootPersistency> p =
0101     ConditionsRootPersistency::load(f,"Conditions");
0102   buffers.emplace_back(p.release());
0103 }
0104 
0105 size_t ConditionsSnapshotRootLoader::load_single(key_type   ,
0106                                                  const IOV& ,
0107                                                  RangeConditions& conditions)
0108 {
0109   size_t len = conditions.size();
0110   for(const auto& src : m_sources )
0111     load_source(src.first);
0112 
0113   m_sources.clear();
0114   return conditions.size()-len;
0115 }
0116 
0117 size_t ConditionsSnapshotRootLoader::load_range(key_type   ,
0118                                                 const IOV& ,
0119                                                 RangeConditions& conditions)
0120 {
0121   size_t len = conditions.size();
0122   for(const auto& src : m_sources )
0123     load_source(src.first);
0124   m_sources.clear();
0125   return conditions.size()-len;
0126 }
0127