| # Gaudi Framework, version v22r4 |

Home |  | Generated: Fri Sep 2 2011

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

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines