| # Gaudi Framework, version v20r2
Generated: 18 Jul 2008

- Main Page
- Namespaces
- Classes
- Files
- Directories
- Related Pages

- Search for |

- File List
- File Members

# THistSvc.h

Go to the documentation of this file.

    00001 #ifndef GAUDISVC_THISTSVC_H
    00002 #define GAUDISVC_THISTSVC_H
    00003
    00004 #include "GaudiKernel/Service.h"
    00005 #include "GaudiKernel/ITHistSvc.h"
    00006
    00007 #include "TObject.h"
    00008 #include "TH1.h"
    00009 #include "TH2.h"
    00010 #include "TH3.h"
    00011 #include "TTree.h"
    00012 #include "TGraph.h"
    00013 #include "TList.h"
    00014
    00015
    00016 #include <vector>
    00017 #include <string>
    00018 #include <set>
    00019 #include <map>
    00020
    00021 // Forward declarations
    00022 template <class TYPE> class SvcFactory;
    00023
    00024 class THistSvc: public Service, virtual public ITHistSvc {
    00025
    00026 public:
    00027
    00028   virtual StatusCode initialize();
    00029   virtual StatusCode reinitialize();
    00030   virtual StatusCode finalize();
    00031
    00032   // Query the interfaces.
    00033   virtual StatusCode queryInterface( const InterfaceID& riid,
    00034                                      void** ppvInterface );
    00035
    00036
    00037   virtual StatusCode regHist(const std::string& name);
    00038   virtual StatusCode regHist(const std::string& name, TH1*);
    00039   virtual StatusCode regHist(const std::string& name, TH2*);
    00040   virtual StatusCode regHist(const std::string& name, TH3*);
    00041
    00042   virtual StatusCode getHist(const std::string& name, TH1*&) const;
    00043   virtual StatusCode getHist(const std::string& name, TH2*&) const;
    00044   virtual StatusCode getHist(const std::string& name, TH3*&) const;
    00045
    00046   virtual StatusCode regTree(const std::string& name);
    00047   virtual StatusCode regTree(const std::string& name, TTree*);
    00048   virtual StatusCode getTree(const std::string& name, TTree*&) const;
    00049
    00050   virtual StatusCode regGraph(const std::string& name);
    00051   virtual StatusCode regGraph(const std::string& name, TGraph*);
    00052   virtual StatusCode getGraph(const std::string& name, TGraph*&) const;
    00053
    00054   virtual StatusCode deReg(TObject* obj);
    00055   virtual StatusCode deReg(const std::string& name);
    00056
    00057   virtual std::vector<std::string> getHists() const;
    00058   virtual std::vector<std::string> getTrees() const;
    00059
    00060   virtual StatusCode getTHists(TDirectory *td, TList &) const;
    00061   virtual StatusCode getTHists(const std::string& name, TList &) const;
    00062
    00063   virtual StatusCode getTTrees(TDirectory *td, TList &) const;
    00064   virtual StatusCode getTTrees(const std::string& name, TList &) const;
    00065
    00066
    00067   THistSvc(const std::string& name, ISvcLocator *svc );
    00068
    00069
    00070 protected:
    00071
    00072   virtual ~THistSvc();
    00073
    00074 private:
    00075
    00076   class GlobalDirectoryRestore {
    00077   public:
    00078     GlobalDirectoryRestore();
    00079     ~GlobalDirectoryRestore();
    00080   private:
    00081     TDirectory* m_gd;
    00082     TFile* m_gf;
    00083     int m_ge;
    00084   };
    00085
    00086
    00087   struct THistID {
    00088     std::string id;
    00089     bool        temp;
    00090     TObject*    obj;
    00091     TFile*      file;
    00092
    00093     THistID():id(""),temp(true),obj(0),file(0) {}
    00094     THistID(const THistID& rhs):id(rhs.id), temp(rhs.temp),
    00095                                 obj(rhs.obj), file(rhs.file) {}
    00096     THistID(std::string& i, bool& t, TObject* o, TFile* f)
    00097       : id(i), temp(t), obj(o), file(f){}
    00098
    00099     bool operator < (THistID const &rhs) const {
    00100       return (obj < rhs.obj);
    00101     }
    00102   };
    00103
    00104   enum Mode {
    00105     READ,
    00106     WRITE,
    00107     UPDATE,
    00108     APPEND,
    00109     SHARE
    00110   };
    00111
    00112   typedef std::map<std::string, THistID> uidMap;
    00113   typedef std::multimap<std::string, THistID> idMap;
    00114   typedef std::map<TObject*, THistID> objMap;
    00115   typedef std::multimap<std::string, std::string> streamMap;
    00116
    00117   template <typename T>
    00118   StatusCode regHist_i(T* hist, const std::string& name);
    00119   template <typename T>
    00120   StatusCode getHist_i(const std::string& name, T*& hist) const;
    00121   template <typename T>
    00122   StatusCode readHist_i(const std::string& name, T*& hist) const;
    00123
    00124
    00125   StatusCode readHist(const std::string& name, TH1*&) const;
    00126   StatusCode readHist(const std::string& name, TH2*&) const;
    00127   StatusCode readHist(const std::string& name, TH3*&) const;
    00128   StatusCode readTree(const std::string& name, TTree*&) const;
    00129
    00130   void updateFiles();
    00131   StatusCode write();
    00132   StatusCode connect(const std::string&);
    00133   TDirectory* changeDir(const THistSvc::THistID& hid) const;
    00134   std::string dirname(std::string& dir) const;
    00135   void removeDoubleSlash(std::string&) const;
    00136
    00137   bool browseTDir(TDirectory* dir) const;
    00138
    00139   bool findStream(const std::string& name, std::string& root,
    00140                   std::string& rem, TFile*& file) const;
    00141   void parseString(const std::string& id, std::string& root, std::string& rem)
    00142     const;
    00143
    00145   void setupInputFile( Property& inputfile );
    00146
    00148   void setupOutputFile( Property& outputfile );
    00149
    00150   StringArrayProperty m_inputfile, m_outputfile;
    00151   std::vector<std::string> m_Rstream, m_Wstream;
    00152   IntegerProperty m_autoSave;
    00153   BooleanProperty m_print;
    00154
    00155
    00158   std::set<std::string> m_alreadyConnectedInFiles;
    00159
    00162   std::set<std::string> m_alreadyConnectedOutFiles;
    00163
    00164   //  std::map<TObject*, TFile*> m_tobjs;
    00165
    00166   uidMap m_uids;
    00167   idMap  m_ids;
    00168   objMap m_tobjs;
    00169
    00170   std::map<std::string, std::pair<TFile*,Mode> > m_files; // stream->file
    00171   streamMap m_fileStreams;                                // fileName->streams
    00172
    00173   std::map<std::string, std::string > m_sharedFiles; // stream->filename of shared files
    00174   void MergeRootFile( TDirectory *target, TDirectory *source);
    00175
    00176 };
    00177
    00178 #ifndef GAUDISVC_THISTSVC_ICC
    00179  #include "THistSvc.icc"
    00180 #endif
    00181
    00182
    00183 #endif