| # Gaudi Framework, version v20r4
Generated: 8 Jan 2009

# 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   virtual std::vector<std::string> getGraphs() const;
    00060
    00061   virtual StatusCode getTHists(TDirectory *td, TList &) const;
    00062   virtual StatusCode getTHists(const std::string& name, TList &) const;
    00063
    00064   virtual StatusCode getTTrees(TDirectory *td, TList &) const;
    00065   virtual StatusCode getTTrees(const std::string& name, TList &) const;
    00066
    00067
    00068   THistSvc(const std::string& name, ISvcLocator *svc );
    00069
    00070
    00071 protected:
    00072
    00073   virtual ~THistSvc();
    00074
    00075 private:
    00076
    00077   class GlobalDirectoryRestore {
    00078   public:
    00079     GlobalDirectoryRestore();
    00080     ~GlobalDirectoryRestore();
    00081   private:
    00082     TDirectory* m_gd;
    00083     TFile* m_gf;
    00084     int m_ge;
    00085   };
    00086
    00087
    00088   struct THistID {
    00089     std::string id;
    00090     bool        temp;
    00091     TObject*    obj;
    00092     TFile*      file;
    00093
    00094     THistID():id(""),temp(true),obj(0),file(0) {}
    00095     THistID(const THistID& rhs):id(rhs.id), temp(rhs.temp),
    00096                                 obj(rhs.obj), file(rhs.file) {}
    00097     THistID(std::string& i, bool& t, TObject* o, TFile* f)
    00098       : id(i), temp(t), obj(o), file(f){}
    00099
    00100     bool operator < (THistID const &rhs) const {
    00101       return (obj < rhs.obj);
    00102     }
    00103   };
    00104
    00105   enum Mode {
    00106     READ,
    00107     WRITE,
    00108     UPDATE,
    00109     APPEND,
    00110     SHARE
    00111   };
    00112
    00113   typedef std::map<std::string, THistID> uidMap;
    00114   typedef std::multimap<std::string, THistID> idMap;
    00115   typedef std::map<TObject*, THistID> objMap;
    00116   typedef std::multimap<std::string, std::string> streamMap;
    00117
    00118   template <typename T>
    00119   StatusCode regHist_i(T* hist, const std::string& name);
    00120   template <typename T>
    00121   StatusCode getHist_i(const std::string& name, T*& hist) const;
    00122   template <typename T>
    00123   StatusCode readHist_i(const std::string& name, T*& hist) const;
    00124
    00125
    00126   StatusCode readHist(const std::string& name, TH1*&) const;
    00127   StatusCode readHist(const std::string& name, TH2*&) const;
    00128   StatusCode readHist(const std::string& name, TH3*&) const;
    00129   StatusCode readTree(const std::string& name, TTree*&) const;
    00130
    00131   void updateFiles();
    00132   StatusCode write();
    00133   StatusCode connect(const std::string&);
    00134   TDirectory* changeDir(const THistSvc::THistID& hid) const;
    00135   std::string dirname(std::string& dir) const;
    00136   void removeDoubleSlash(std::string&) const;
    00137
    00138   bool browseTDir(TDirectory* dir) const;
    00139
    00140   bool findStream(const std::string& name, std::string& root,
    00141                   std::string& rem, TFile*& file) const;
    00142   void parseString(const std::string& id, std::string& root, std::string& rem)
    00143     const;
    00144
    00146   void setupInputFile( Property& inputfile );
    00147
    00149   void setupOutputFile( Property& outputfile );
    00150
    00151   StringArrayProperty m_inputfile, m_outputfile;
    00152   std::vector<std::string> m_Rstream, m_Wstream;
    00153   IntegerProperty m_autoSave;
    00154   BooleanProperty m_print;
    00155
    00156
    00159   std::set<std::string> m_alreadyConnectedInFiles;
    00160
    00163   std::set<std::string> m_alreadyConnectedOutFiles;
    00164
    00165   //  std::map<TObject*, TFile*> m_tobjs;
    00166
    00167   uidMap m_uids;
    00168   idMap  m_ids;
    00169   objMap m_tobjs;
    00170
    00171   std::map<std::string, std::pair<TFile*,Mode> > m_files; // stream->file
    00172   streamMap m_fileStreams;                                // fileName->streams
    00173
    00174   std::map<std::string, std::string > m_sharedFiles; // stream->filename of shared files
    00175   void MergeRootFile( TDirectory *target, TDirectory *source);
    00176
    00177 };
    00178
    00179 #ifndef GAUDISVC_THISTSVC_ICC
    00180  #include "THistSvc.icc"
    00181 #endif
    00182
    00183
    00184 #endif