Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-21 09:58:05

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 #ifndef DDCOND_CONDITIONSROOTPERSISTENCY_H
0014 #define DDCOND_CONDITIONSROOTPERSISTENCY_H
0015 
0016 // Framework/ROOT include files
0017 #include "DDCond/ConditionsPool.h"
0018 
0019 #include "TNamed.h"
0020 class TFile;
0021 
0022 // C/C++ include files
0023 #include <map>
0024 #include <list>
0025 #include <vector>
0026 #include <memory>
0027 
0028 
0029 /// Namespace for the AIDA detector description toolkit
0030 namespace dd4hep {
0031 
0032   /// Namespace for implementation details of the AIDA detector description toolkit
0033   namespace cond {
0034 
0035     /// Forward declarations
0036     class ConditionsSlice;
0037     class ConditionsIOVPool;
0038 
0039     /// Helper to save conditions pools to ROOT
0040     /** 
0041      *  This is a rathr simplistic persistency mechanism for conditions.
0042      *  It is not suited to actually store and retrieve individual conditions
0043      *  by key. Though it is rather efficient to store and retrive 
0044      *  entire conditions snapshots of the conditions store implemented by DDCond.
0045      *  It e.g. allows to fast load the conditions store for HLT applications,
0046      *  of which we know it takes ages to populate it from a database.
0047      *
0048      *  \author  M.Frank
0049      *  \version 1.0
0050      */
0051     class ConditionsRootPersistency : public TNamed  {
0052     public:
0053       typedef std::vector<Condition>                                  pool_type;
0054       typedef std::pair<std::string, pool_type>                       named_pool_type;
0055       typedef std::pair<std::string,std::pair<std::pair<std::string,int>,IOV::Key> > iov_key_type;
0056       typedef std::list<std::pair<iov_key_type, pool_type> >          persistent_type;
0057 
0058       persistent_type conditionPools {};
0059       persistent_type userPools {};
0060       persistent_type iovPools  {};
0061       float           duration = 0;
0062       enum ImportStrategy  {
0063         IMPORT_ALL             = 1<<0,
0064         IMPORT_EXACT           = 1<<1,
0065         IMPORT_CONTAINED       = 1<<2,
0066         IMPORT_CONTAINED_LOWER = 1<<3,
0067         IMPORT_CONTAINED_UPPER = 1<<4,
0068         IMPORT_EDGE_LOWER      = 1<<5,
0069         IMPORT_EDGE_UPPER      = 1<<6,
0070         LAST
0071       };
0072       /// Load ConditionsIOVPool and populate conditions manager
0073       size_t _import(ImportStrategy     strategy,
0074                      persistent_type&   pers,
0075                      const std::string& id,
0076                      const std::string& iov_type,
0077                      const IOV::Key&    iov_key,
0078                      ConditionsManager  mgr);
0079 
0080       /// Clear object content and release allocated memory
0081       void _clear(persistent_type& pool);
0082       
0083     public:
0084       /// No copy constructor
0085       ConditionsRootPersistency(const ConditionsRootPersistency& copy) = delete;
0086       /// Initializing constructor
0087       ConditionsRootPersistency(const std::string& name, const std::string& title="DD4hep conditions container");
0088       /// Default constructor
0089       ConditionsRootPersistency();
0090       /// Default destructor
0091       virtual ~ConditionsRootPersistency();
0092       /// No assignment
0093       ConditionsRootPersistency& operator=(const ConditionsRootPersistency& copy) = delete;
0094 
0095       /// Clear object content and release allocated memory
0096       void clear();
0097       /// Open ROOT file in read mode
0098       static TFile* openFile(const std::string& fname);      
0099       
0100       /// Add conditions content to be saved. Note, that dependent conditions shall not be saved!
0101       size_t add(const std::string& identifier, const IOV& iov, std::vector<Condition>& conditions);
0102       /// Add conditions content to be saved. Note, that dependent conditions shall not be saved!
0103       size_t add(const std::string& identifier, ConditionsPool& pool);
0104       /// Add conditions content to be saved. Note, that dependent conditions shall not be saved!
0105       size_t add(const std::string& identifier, const UserPool& pool);
0106       /// Add conditions content to be saved. Note, that dependent conditions shall not be saved!
0107       size_t add(const std::string& identifier, const ConditionsIOVPool& pool);
0108 
0109       /// Load conditions content from file.
0110       static std::unique_ptr<ConditionsRootPersistency> load(TFile* file,const std::string& object);
0111       
0112       /// Load conditions content from file.
0113       static std::unique_ptr<ConditionsRootPersistency> load(const std::string& file,const std::string& object)  {
0114         return load(openFile(file), object);
0115       }
0116       
0117       /// Load conditions IOV pool and populate conditions manager
0118       size_t importIOVPool(const std::string& id, const std::string& iov_type, ConditionsManager mgr);
0119       /// Load conditions user pool and populate conditions manager
0120       size_t importUserPool(const std::string& id, const std::string& iov_type, ConditionsManager mgr);
0121       /// Load conditions pool and populate conditions manager
0122       size_t importConditionsPool(const std::string& id, const std::string& iov_type, ConditionsManager mgr);
0123 
0124       /// Load conditions pool and populate conditions manager. Allow tro be selective also for the key
0125       size_t importConditionsPool(ImportStrategy     strategy,
0126                                   const std::string& id,
0127                                   const std::string& iov_type,
0128                                   const IOV::Key&    key,
0129                                   ConditionsManager  mgr);
0130 
0131       /// Save the data content to a root file
0132       int save(TFile* file);
0133       /// Save the data content to a root file
0134       int save(const std::string& file_name);
0135 
0136       /// ROOT object ClassDef
0137       ClassDef(ConditionsRootPersistency,1);
0138     };
0139     
0140   }        /* End namespace cond                            */
0141 }          /* End namespace dd4hep                          */
0142 #endif // DDCOND_CONDITIONSROOTPERSISTENCY_H