Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:17:16

0001 // Tell emacs that this is a C++ source
0002 //  -*- C++ -*-.
0003 #ifndef FUN4ALL_FUN4ALLHISTOMANAGER_H
0004 #define FUN4ALL_FUN4ALLHISTOMANAGER_H
0005 
0006 #include "Fun4AllBase.h"
0007 
0008 #include <map>
0009 #include <string>
0010 
0011 class TNamed;
0012 
0013 class Fun4AllHistoManager : public Fun4AllBase
0014 {
0015  public:
0016   explicit Fun4AllHistoManager(const std::string &name);
0017   ~Fun4AllHistoManager() override;
0018 
0019   void Print(const std::string &what = "ALL") const override;
0020 
0021   //! Register histogram or TTree object
0022   //! For histograms, enforce error calculation and propagation
0023   bool registerHisto(const std::string &hname, TNamed *h1d, const int replace = 0);
0024 
0025   //! Register histogram or TTree object
0026   //! For histograms, enforce error calculation and propagation
0027   bool registerHisto(TNamed *h1d, const int replace = 0);
0028 
0029   template <typename T>
0030   T *makeHisto(T *t)
0031   {
0032     if (not registerHisto(t))
0033     {
0034       delete t;
0035       t = nullptr;
0036     }
0037     return t;
0038   }
0039   int isHistoRegistered(const std::string &name) const;
0040   TNamed *getHisto(const std::string &hname) const;
0041   TNamed *getHisto(const unsigned int ihisto) const;
0042   std::string getHistoName(const unsigned int ihisto) const;
0043   unsigned int nHistos() const { return Histo.size(); }
0044   void Reset();
0045   int RunAfterClosing();
0046   int dumpHistos(const std::string &filename = "", const std::string &openmode = "RECREATE");
0047   const std::string &OutFileName() { return m_outfilename; }
0048   void setOutfileName(const std::string &filename) { m_outfilename = filename; }
0049   bool dumpHistoSegments() { return m_dumpHistoSegments; }
0050   void dumpHistoSegments(const bool dump) { m_dumpHistoSegments = dump; }
0051   void SetClosingScript(const std::string &script) { m_RunAfterClosingScript = script; }
0052   void SetClosingScriptArgs(const std::string &args) { m_ClosingArgs = args; }
0053   void segment(const int segment) { m_CurrentSegment = segment; }
0054 
0055  private:
0056   std::string m_outfilename;
0057   std::string m_RunAfterClosingScript;
0058   std::string m_ClosingArgs;
0059   std::string m_LastClosedFileName;
0060   std::map<const std::string, TNamed *> Histo;
0061   bool m_dumpHistoSegments = false;
0062   int m_CurrentSegment = 0;
0063 };
0064 
0065 #endif /* __FUN4ALLHISTOMANAGER_H */