Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SBaseQAPlugin.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file SBaseQAPlugin.h
1 // ----------------------------------------------------------------------------
2 // 'SBaseQAPlugin.h'
3 // Derek Anderson
4 // 11.01.2023
5 //
6 // Base class for subroutines ("plugins") to be run by the SCorrelatorQAMaker
7 // module.
8 // ----------------------------------------------------------------------------
9 
10 #ifndef SABSTRACTQAPLUGIN_H
11 #define SABSTRACTQAPLUGIN_H
12 
13 // c++ utilities
14 #include <string>
15 // root libraries
16 #include <TFile.h>
17 #include <TSystem.h>
18 #include <TDirectory.h>
19 
20 using namespace std;
21 
22 
23 
24 namespace SColdQcdCorrelatorAnalysis {
25 
26  // SBaseQAPlugin definition -------------------------------------------------
27 
28  template <class Config> class SBaseQAPlugin {
29 
30  public:
31 
32  // ctor/dtor
35 
36  // setters
37  void SetDebug(const bool debug) {m_isDebugOn = debug;}
38  void SetOutFile(const string file) {m_outFileName = file;}
39  void SetOutDir(const string name) {m_outDirName = name;}
40  void SetVerbosity(const uint16_t verb) {m_verbosity = verb;}
41  void SetConfig(const Config& cfg) {m_config = cfg;}
42 
43  // output getters
44  TFile* GetOutFile() {return m_outFile;}
45  TDirectory* GetOutDir() {return m_outDir;}
46 
47  protected:
48 
49  void InitOutput() {
50 
51  // check output file and create if needed
52  // FIXME doesn't work for files already opened yet!
53  const bool doesFileExist = gSystem -> AccessPathName(m_outFileName.data());
54  if (!doesFileExist) {
55  m_outFile = new TFile(m_outFileName.data(), "recreate");
56  } else {
57  m_outFile = new TFile(m_outFileName.data(), "update");
58  }
59 
60  // create output directory if needed
61  const bool doesDirExist = m_outFile -> cd(m_outDirName.data());
62  if (!doesDirExist) {
63  m_outDir = (TDirectory*) m_outFile -> mkdir(m_outDirName.data());
64  } else {
65  m_outDir = (TDirectory*) m_outFile -> GetDirectory(m_outDirName.data());
66  }
67  return;
68  }; // end 'InitOutput()'
69 
70  void CloseOutput() {
71 
72  // close output if still open
73  // FIXME needs care not to close files that should still be open!
74  const bool isFileOpen = m_outFile -> IsOpen();
75  if (isFileOpen) {
76  m_outFile -> cd();
77  m_outFile -> Close();
78  }
79  return;
80 
81  }; // end 'CloseOutput()'
82 
83  // io members
84  TFile* m_outFile = NULL;
85  TDirectory* m_outDir = NULL;
86 
87  // atomic members
88  bool m_isDebugOn = false;
89  string m_outFileName = "";
90  string m_outDirName = "";
91  uint16_t m_verbosity = 0;
92 
93  // routine configuration
95 
96  }; // end SBaseQAPlugin Definition
97 
98 } // end SColdQcdCorrelatorAnalysis namespace
99 
100 #endif
101 
102 // end ------------------------------------------------------------------------