| # Gaudi Framework, version v21r7 |

Home |  | Generated: 22 Jan 2010

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