| # Gaudi Framework, version v21r8 |

Home |  | Generated: 17 Mar 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 &) const;
    00059   virtual StatusCode getTHists(const std::string& name, TList &) const;
    00060
    00061   virtual StatusCode getTTrees(TDirectory *td, TList &) const;
    00062   virtual StatusCode getTTrees(const std::string& name, TList &) const;
    00063
    00064   virtual bool exists(const std::string& name) const;
    00065
    00066   THistSvc(const std::string& name, ISvcLocator *svc );
    00067
    00068   void handle(const Incident&);
    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   mutable MsgStream m_log;
    00113
    00114   typedef std::map<std::string, THistID> uidMap;
    00115   typedef std::multimap<std::string, THistID> idMap;
    00116   typedef std::map<TObject*, THistID> objMap;
    00117   typedef std::multimap<std::string, std::string> streamMap;
    00118
    00119   template <typename T>
    00120   StatusCode regHist_i(T* hist, const std::string& name);
    00121   template <typename T>
    00122   StatusCode getHist_i(const std::string& name, T*& hist, bool quiet=false) const;
    00123   template <typename T>
    00124   StatusCode readHist_i(const std::string& name, T*& hist) const;
    00125
    00126
    00127   StatusCode readHist(const std::string& name, TH1*&) const;
    00128   StatusCode readHist(const std::string& name, TH2*&) const;
    00129   StatusCode readHist(const std::string& name, TH3*&) const;
    00130   StatusCode readTree(const std::string& name, TTree*&) const;
    00131
    00132   void updateFiles();
    00133   StatusCode write();
    00134   StatusCode connect(const std::string&);
    00135   TDirectory* changeDir(const THistSvc::THistID& hid) const;
    00136   std::string dirname(std::string& dir) const;
    00137   void removeDoubleSlash(std::string&) const;
    00138
    00139   bool browseTDir(TDirectory* dir) const;
    00140
    00141   bool findStream(const std::string& name, std::string& root,
    00142                   std::string& rem, TFile*& file) const;
    00143   void parseString(const std::string& id, std::string& root, std::string& rem)
    00144     const;
    00145
    00147   void setupInputFile( Property& inputfile );
    00148
    00150   void setupOutputFile( Property& outputfile );
    00151
    00152   StringArrayProperty m_inputfile, m_outputfile;
    00153   std::vector<std::string> m_Rstream, m_Wstream;
    00154   IntegerProperty m_autoSave, m_compressionLevel, m_maxFileSize;
    00155   BooleanProperty m_print;
    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   bool signaledStop;
    00178
    00179 };
    00180
    00181 #ifndef GAUDISVC_THISTSVC_ICC
    00182  #include "THistSvc.icc"
    00183 #endif
    00184
    00185
    00186 #endif