| # Gaudi Framework, version v23r1 |

Home |  | Generated: Wed Feb 29 2012

# RootDataConnection.h

Go to the documentation of this file.

    00001 // $Id: RootDataConnection.h,v 1.9 2010-09-17 09:00:12 frankb Exp $
    00002 #ifndef GAUDIROOT_ROOTDATACONNECTION_H
    00003 #define GAUDIROOT_ROOTDATACONNECTION_H
    00004
    00005 // Framework include files
    00006 #include "GaudiKernel/ClassID.h"
    00007 #include "GaudiUtils/IIODataManager.h"
    00008 #include <string>
    00009 #include <vector>
    00010 #include <map>
    00011 #include <set>
    00012
    00013 #include "TFile.h"
    00014 #include "RootCnv/RootRefs.h"
    00015
    00016 // Forward declarations
    00017 class TTree;
    00018 class TClass;
    00019 class TBranch;
    00020 class TTreePerfStats;
    00021
    00022 class MsgStream;
    00023 class IRegistry;
    00024 class DataObject;
    00025
    00026 /*
    00027  *  Gaudi namespace declaration
    00028  */
    00029 namespace Gaudi  {
    00030
    00041   class GAUDI_API RootConnectionSetup {
    00042   public:
    00044     typedef std::vector<std::string> StringVec;
    00045   protected:
    00047     virtual ~RootConnectionSetup();
    00049     int refCount;
    00051     MsgStream* m_msgSvc;
    00052
    00053   public:
    00055     StringVec    cacheBranches;
    00057     StringVec    vetoBranches;
    00059     std::string  loadSection;
    00061     int          cacheSize;
    00063     int          learnEntries;
    00065     int          autoFlush;
    00067     int          basketSize;
    00068
    00070     RootConnectionSetup();
    00072     void addRef();
    00074     void release();
    00075
    00077     static long setCompression(const std::string& compression);
    00079     static int compression();
    00080
    00082     void setMessageSvc(MsgStream* m);
    00084     MsgStream& msgSvc() const {  return *m_msgSvc; }
    00085   };
    00086
    00095   class GAUDI_API RootDataConnection : virtual public Gaudi::IDataConnection  {
    00096   public:
    00097
    00108     struct ContainerSection {
    00110       ContainerSection() : start(-1), length(0) {}
    00112       ContainerSection(int s, int l) : start(s), length(l) {}
    00114       ContainerSection(const ContainerSection& s) : start(s.start), length(s.length) {}
    00116       ContainerSection& operator=(const ContainerSection& s) { start=s.start;length=s.length; return *this;}
    00118       int start;
    00120       int length;
    00121     };
    00122
    00124     typedef std::vector<std::string>                                 StringVec;
    00126     typedef std::vector<std::pair<std::string,std::string> >         ParamMap;
    00128     typedef std::map<std::string,TTree*>                             Sections;
    00130     typedef std::vector<ContainerSection>                            ContainerSections;
    00132     typedef std::map<std::string,ContainerSections>                  MergeSections;
    00134     typedef std::vector<RootRef>                                     LinkSections;
    00136     typedef std::set<const IInterface*>                              Clients;
    00137
    00139     MsgStream& msgSvc() const {  return m_setup->msgSvc(); }
    00140
    00141
    00142   protected:
    00144     RootConnectionSetup* m_setup;
    00146     TTreePerfStats*      m_statistics;
    00148     TFile*               m_file;
    00150     TTree               *m_refs;
    00152     Sections             m_sections;
    00154     StringVec            m_dbs;
    00156     StringVec            m_conts;
    00158     StringVec            m_links;
    00160     StringVec            m_mergeFIDs;
    00162     ParamMap             m_params;
    00164     MergeSections        m_mergeSects;
    00166     LinkSections         m_linkSects;
    00168     Clients              m_clients;
    00170     std::string          m_empty;
    00171
    00173     const std::string& empty() const;
    00174
    00176     StatusCode saveRefs();
    00177
    00178   public:
    00188     class Tool {
    00189     protected:
    00190       typedef RootDataConnection::StringVec          StringVec;
    00191       typedef RootDataConnection::ParamMap           ParamMap;
    00192       typedef RootDataConnection::Sections           Sections;
    00193       typedef RootDataConnection::MergeSections      MergeSections;
    00194       typedef RootDataConnection::LinkSections       LinkSections;
    00195       typedef RootDataConnection::ContainerSection   ContainerSection;
    00196       typedef RootDataConnection::ContainerSections  ContainerSections;
    00197
    00199       RootDataConnection* c;
    00200     public:
    00201       TTree*             refs()               const { return c->m_refs;       }
    00202       StringVec&         dbs()                const { return c->m_dbs;        }
    00203       StringVec&         conts()              const { return c->m_conts;      }
    00204       StringVec&         links()              const { return c->m_links;      }
    00205       ParamMap&          params()             const { return c->m_params;     }
    00206       MsgStream&         msgSvc()             const { return c->msgSvc();     }
    00207       const std::string& name()               const { return c->m_name;       }
    00208       Sections&          sections()           const { return c->m_sections;   }
    00209       LinkSections&      linkSections()       const { return c->m_linkSects;  }
    00210       MergeSections&     mergeSections()      const { return c->m_mergeSects; }
    00211
    00213       virtual ~Tool() {}
    00215       virtual void release() { delete this; }
    00217       virtual TBranch* getBranch(const std::string&  section, const std::string& n) = 0;
    00219       virtual RootRef poolRef(size_t /* which */) const { return RootRef(); }
    00220
    00222       virtual StatusCode readRefs() = 0;
    00224       virtual StatusCode saveRefs() = 0;
    00226       virtual int loadRefs(const std::string& section, const std::string& cnt, unsigned long entry, RootObjectRefs& refs) = 0;
    00227     } *m_tool;
    00228     friend class Tool;
    00229
    00231     Tool* makeTool();
    00232
    00233   public:
    00234
    00236     RootDataConnection(const IInterface* own, const std::string& nam, RootConnectionSetup* setup);
    00238     virtual ~RootDataConnection();
    00239
    00241     TFile* file() const                         {  return m_file;                              }
    00243     virtual bool isConnected() const            {  return m_file != 0;                         }
    00245     bool isWritable() const                     {  return m_file != 0 && m_file->IsWritable(); }
    00247     Tool* tool() const                          {  return m_tool;                              }
    00249     const MergeSections& mergeSections() const  {  return m_mergeSects;                        }
    00251     const StringVec& mergeFIDs() const          {  return m_mergeFIDs;                         }
    00252
    00253
    00255     void addClient(const IInterface* client);
    00257     size_t removeClient(const IInterface* client);
    00259     bool lookupClient(const IInterface* client) const;
    00260
    00262     std::pair<const RootRef*,const ContainerSection*>  getMergeSection(const std::string& container, int entry) const;
    00263
    00265     void enableStatistics(const std::string& section);
    00267     void saveStatistics(const std::string& statisticsFile);
    00268
    00270     int loadObj(const std::string& section, const std::string& cnt, unsigned long entry, DataObject*& pObj);
    00271
    00273     int loadRefs(const std::string& section, const std::string& cnt, unsigned long entry, RootObjectRefs& refs)
    00274     { return m_tool->loadRefs(section,cnt,entry,refs); }
    00275
    00277     std::pair<int,unsigned long> saveObj(const std::string& section,const std::string& cnt, TClass* cl, DataObject* pObj,bool fill_missing=false);
    00279     std::pair<int,unsigned long> save(const std::string& section,const std::string& cnt, TClass* cl, void* pObj,bool fill_missing=false);
    00280
    00281
    00283     virtual StatusCode connectRead();
    00285     virtual StatusCode connectWrite(IoType typ);
    00287     virtual StatusCode disconnect();
    00289     virtual StatusCode read(void* const, size_t)   { return StatusCode::FAILURE; }
    00291     virtual StatusCode write(const void*, int)     { return StatusCode::FAILURE; }
    00293     virtual long long int seek(long long int, int) { return -1; }
    00294
    00296     TTree* getSection(const std::string& sect, bool create=false);
    00297
    00299     TBranch* getBranch(const std::string& section,const std::string& branch_name)
    00300     { return m_tool->getBranch(section,branch_name); }
    00302     TBranch* getBranch(const std::string& section, const std::string& branch_name, TClass* cl, void* ptr);
    00303
    00305     void makeRef(IRegistry* pA, RootRef& ref);
    00307     void makeRef(const std::string& name, long clid, int tech, const std::string& db, const std::string& cnt, int entry, RootRef& ref);
    00308
    00310     int makeLink(const std::string& p);
    00311
    00313     const std::string& getDb(int which) const;
    00314
    00316     const std::string& getCont(int which) const
    00317       { return (which>=0)&&(size_t(which)<m_conts.size()) ? *(m_conts.begin()+which) : empty();    }
    00318
    00320     const std::string& getLink(int which) const
    00321       { return (which>=0)&&(size_t(which)<m_links.size()) ? *(m_links.begin()+which) : empty();    }
    00322   };
    00323 }         // End namespace Gaudi
    00324 #endif    // GAUDIROOT_ROOTDATACONNECTION_H

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines