| # Gaudi Framework, version v21r10p1 |

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