Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:13:18

0001 // ----------------------------------------------------------------------------
0002 // 'SBaseQAPlugin.h'
0003 // Derek Anderson
0004 // 11.01.2023
0005 //
0006 // Base class for subroutines ("plugins") to be run by the SCorrelatorQAMaker
0007 // module.
0008 // ----------------------------------------------------------------------------
0009 
0010 #ifndef SCORRELATORQAMAKER_SBASEQAPLUGIN_H
0011 #define SCORRELATORQAMAKER_SBASEQAPLUGIN_H
0012 
0013 // c++ utilities
0014 #include <string>
0015 // root libraries
0016 #include <TFile.h>
0017 #include <TSystem.h>
0018 #include <TDirectory.h>
0019 
0020 using namespace std;
0021 
0022 
0023 
0024 namespace SColdQcdCorrelatorAnalysis {
0025 
0026   // SBaseQAPlugin definition -------------------------------------------------
0027 
0028   template <class Config> class SBaseQAPlugin {
0029 
0030     public:
0031 
0032       // ctor/dtor
0033       SBaseQAPlugin()  {};
0034       ~SBaseQAPlugin() {};
0035 
0036       // setters
0037       void SetDebug(const bool debug)        {m_isDebugOn   = debug;}
0038       void SetOutFile(const string file)     {m_outFileName = file;}
0039       void SetOutDir(const string name)      {m_outDirName  = name;}
0040       void SetVerbosity(const uint16_t verb) {m_verbosity   = verb;}
0041       void SetConfig(const Config& cfg)      {m_config      = cfg;}
0042 
0043       // output getters
0044       TFile*      GetOutFile() {return m_outFile;}
0045       TDirectory* GetOutDir()  {return m_outDir;}
0046 
0047     protected:
0048 
0049       void InitOutput() {
0050 
0051         // check output file and create if needed
0052         //   FIXME doesn't work for files already opened yet!
0053         const bool doesFileExist = gSystem -> AccessPathName(m_outFileName.data());
0054         if (!doesFileExist) {
0055           m_outFile = new TFile(m_outFileName.data(), "recreate");
0056         } else {
0057           m_outFile = new TFile(m_outFileName.data(), "update");
0058         }
0059 
0060         // create output directory if needed
0061         const bool doesDirExist = m_outFile -> cd(m_outDirName.data());
0062         if (!doesDirExist) {
0063           m_outDir = (TDirectory*) m_outFile -> mkdir(m_outDirName.data());
0064         } else {
0065           m_outDir = (TDirectory*) m_outFile -> GetDirectory(m_outDirName.data());
0066         }
0067         return;
0068       };  // end 'InitOutput()'
0069 
0070       void CloseOutput() {
0071 
0072         // close output if still open
0073         //   FIXME needs care not to close files that should still be open!
0074         const bool isFileOpen = m_outFile -> IsOpen();
0075         if (isFileOpen) {
0076           m_outFile -> cd();
0077           m_outFile -> Close();
0078         }
0079         return;
0080 
0081       };  // end 'CloseOutput()'
0082 
0083       // io members
0084       TFile*      m_outFile = NULL;
0085       TDirectory* m_outDir  = NULL;
0086 
0087       // atomic members
0088       bool     m_isDebugOn   = false;
0089       string   m_outFileName = "";
0090       string   m_outDirName  = "";
0091       uint16_t m_verbosity   = 0;
0092 
0093       // routine configuration
0094       Config m_config;
0095 
0096   };  // end SBaseQAPlugin Definition
0097 
0098 }  // end SColdQcdCorrelatorAnalysis namespace
0099 
0100 #endif
0101 
0102 // end ------------------------------------------------------------------------