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_CONDIITONSSNAPSHOTROOTLOADER_H
0015 #define DD4HEP_CONDITIONS_CONDIITONSSNAPSHOTROOTLOADER_H
0016 
0017 // Framework include files
0018 #include <DDCond/ConditionsDataLoader.h>
0019 #include <DDCond/ConditionsRootPersistency.h>
0020 #include <DD4hep/Printout.h>
0021 
0022 /// Namespace for the AIDA detector description toolkit
0023 namespace dd4hep {
0024 
0025   /// Namespace for implementation details of the AIDA detector description toolkit
0026   namespace cond  {
0027 
0028     /// Implementation of a stack of conditions assembled before application
0029     /** 
0030      *  \author   M.Frank
0031      *  \version  1.0
0032      *  \ingroup  DD4HEP_CONDITIONS
0033      */
0034     class ConditionsSnapshotRootLoader : public ConditionsDataLoader   {
0035       std::vector<ConditionsRootPersistency*> buffers;
0036       void load_source  (const std::string& nam);
0037     public:
0038       /// Default constructor
0039       ConditionsSnapshotRootLoader(Detector& description, ConditionsManager mgr, const std::string& nam);
0040       /// Default destructor
0041       virtual ~ConditionsSnapshotRootLoader();
0042       /// Load  a condition set given a Detector Element and the conditions name according to their validity
0043       virtual size_t load_single(key_type key,
0044                                  const IOV& req_validity,
0045                                  RangeConditions& conditions);
0046       /// Load  a condition set given a Detector Element and the conditions name according to their validity
0047       virtual size_t load_range( key_type key,
0048                                  const IOV& req_validity,
0049                                  RangeConditions& conditions);
0050       /// Optimized update using conditions slice data
0051       virtual size_t load_many(  const IOV& /* req_validity */,
0052                                  RequiredItems&  /* work         */,
0053                                  LoadedItems&    /* loaded       */,
0054                                  IOV&       /* conditions_validity */)
0055       {
0056         except("ConditionsLoader","+++ update: Invalid call!");
0057         return 0;
0058       }
0059     };
0060   }    /* End namespace cond                             */
0061 }      /* End namespace dd4hep                            */
0062 #endif /* DD4HEP_CONDITIONS_CONDIITONSSNAPSHOTROOTLOADER_H  */
0063 
0064 //#include <ConditionsSnapshotRootLoader.h>
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 // C/C++ include files
0073 #include <string>
0074 
0075 // Forward declartions
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 /// Standard constructor, initializes variables
0088 ConditionsSnapshotRootLoader::ConditionsSnapshotRootLoader(Detector& description, ConditionsManager mgr, const std::string& nam) 
0089 : ConditionsDataLoader(description, mgr, nam)
0090 {
0091 }
0092 
0093 /// Default Destructor
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   /* key */,
0106                                                  const IOV& /* req_validity */,
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   /* key */,
0118                                                 const IOV& /* req_validity */,
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