ATLAS Offline Software
HanOutputFile.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3  */
4 
5 #ifndef dqutilsHanOutputFile_h
6 #define dqutilsHanOutputFile_h
7 
8 #include <TObjString.h>
9 #include <TObject.h>
10 
11 #include <iosfwd>
12 #include <map>
13 #include <nlohmann/json.hpp>
14 #include <optional>
15 #include <string>
16 
18 
19 class TCanvas;
20 class TDirectory;
21 class TFile;
22 class TH1;
23 class TH2;
24 class TStyle;
25 class TGraph;
26 class TImage;
27 class TEfficiency;
28 
29 namespace dqutils
30 {
31  class ATLAS_NOT_THREAD_SAFE HanOutputFile: public TObject
32  {
33  public:
34  HanOutputFile();
35 
36  HanOutputFile(const std::string& fileName);
37 
38  virtual ~HanOutputFile();
39 
40  typedef std::map<std::string, TDirectory*> DirMap_t;
41  typedef std::map<std::string, TObject*> DirStrMap_t;
42  typedef std::map<std::string, std::string> AssMap_t;
43  typedef std::map<std::string, AssMap_t*> DirToAssMap_t;
44 
45  static void getAllGroupDirs(DirMap_t& dirmap, TDirectory* dir, const std::string& dirName);
52  static void getAllGroupDirs_V2(DirStrMap_t& dirstrmap, TObject* obj, // For Version 2 files
53  const std::string& objName);
54  static void getAllAssessments(AssMap_t& dirmap, TDirectory* dir);
55 
59  static void printDQGroupJSON(const nlohmann::json& j, const std::string& location, const char* path_to_file);
60 
61  static std::string getStringName(const std::string& location, int file_version);
62  static std::string getInfo(const std::string& location, int file_version);
63  static std::string getInfo(const std::string& JSON_str);
64  static std::string processJSON_ingetInfo(const nlohmann::ordered_json& j);
65 
66  static std::string getIndentation(const std::string& pathName, const std::string& leadingSpace = "");
67 
74  virtual bool setFile(const std::string& fileName);
75 
76  virtual int getFileVersion(); // V1 or V2
77 
78  virtual void printAllDQGroups();
79 
80  virtual void printAllDQAssessments();
81  virtual void printHistoAssessments();
82 
83  virtual std::string stringListSystemPaths(std::string location);
84  virtual std::string stringAllDQAssessments();
85  virtual std::string stringHistoAssessments();
86  virtual std::string stringAllHistograms();
87 
88  virtual void streamAllDQAssessments(std::ostream& o, bool streamAll);
89  virtual void streamHistoAssessments(std::ostream& o, bool streamAll);
90  virtual void streamAllHistograms(std::ostream& o, bool streamAll);
91 
95  const static int GENERATE_PNG = 1; // Make PNG with TImage
96  const static int GENERATE_JSON = 2; // Make JSON
97  virtual int saveAllHistograms(const std::string& location, bool drawRefs, const std::string& run_min_LB,
98  int cnvsType = 1);
99  //manipulation of dirname and maindir prevents const ref passing; could be done better
100  static bool containsDir(std::string dirname, std::string maindir);
112  static std::optional<std::string> containsKeyInJSON(
113  const std::string& pathInJSON, const std::string& jsonName, const std::string& path_to_JSON);
114 
115  virtual bool saveHistogramToFile(const std::string& nameHis, std::string location, TDirectory* groupDir,
116  bool drawRefs,
117  const std::string& run_min_LB, const std::string& pathName, int cnvsType = 1);
118 
119  virtual std::pair<std::string, std::string> getHistogram(const std::string& nameHis, TDirectory* groupDir,
120  bool drawRefs,
121  const std::string& run_min_LB, const std::string& pathName,
122  int cnvsType = 1);
123 
124  virtual std::string getHistogramPNG(
125  const std::string& nameHis, TDirectory* groupDir, bool drawRefs, const std::string& run_min_LB,
126  const std::string& pathName);
127 
128  virtual std::pair<std::string, std::string> getHistogramJSON(
129  const std::string& nameHis, TDirectory* groupDir, bool drawRefs, const std::string& run_min_LB,
130  const std::string& pathName);
131 
132  virtual bool saveHistogramToFileSuperimposed(const std::string& nameHis, std::string location,
133  TDirectory* groupDir1,
134  TDirectory* groupDir2, bool drawRefs, const std::string& run_min_LB,
135  const std::string& pathName, int cnvsType = 1);
136 
137 
138  virtual bool drawH2(TCanvas* canv, TH2* hist, std::string& drawopt, std::string& display);
139 
140  virtual bool drawH1(
141  TCanvas* canv, TH1* hist, TH1* reference, std::string& drawopt, std::string& display, std::string& AlgoName);
142 
143  virtual bool drawReference(
144  TCanvas* canv, TH1* hRef, TH1* h, std::string& drawopt, std::string& display, std::string& AlgoName);
145  // virtual bool drawGraph(TCanvas* canv,TGraph* g,std::string &drawopt,std::string &display);
146 
147  virtual void ratioplot(TCanvas* myC_main, TH1* h, TH1* href, std::string str);
148 
149  virtual void ratioplot2D(TCanvas* canvas, TH2* h2, TH2* h2Ref, std::string display);
150 
151  virtual void attachFits(TH1* hist, std::string& drawopt, std::string& display);
152 
153  virtual void setupCanvas(std::string& drawopt, std::string& display);
154  virtual void polynomial(TCanvas* c, std::string str, TH1* h);
155 
156  virtual void displayExtra(TCanvas* c, const std::string& str);
157  virtual void axisOption(std::string str, TH1* h);
158 
159  virtual void formatTH1(TCanvas* c, TH1* h) const;
160  virtual void formatTH2(TCanvas* c, TH2* h) const;
161  virtual void formatTGraph(TCanvas* c, TGraph* g) const;
162  virtual void formatTEfficiency(TCanvas* c, TEfficiency* e) const;
163 
164  virtual double getNEntries(std::string location, std::string histname);
165  virtual double getNEntries(const TObject* obj);
166  protected:
167  virtual void clearData();
168  virtual void convertToGraphics(
169  int cnvsType, TCanvas* myC, std::string& json, TImage** img = 0, char** x = 0, int* y = 0);
170  virtual void convertToGraphics(int cnvsType, TCanvas* myC, const std::string& namePNG, const std::string& nameJSON);
171 
172  virtual bool saveFile(
173  int cnvsType, const std::string& pngfName, const std::string& pngContent, const std::string& jsonfName,
174  const std::string& jsonfContent);
175 
176  virtual bool writeToFile(const std::string& fName, const std::string& content);
177 
178  TFile* m_file;
182  TStyle* m_style;
183 
184  ClassDef(HanOutputFile, 0) // Provides functions to manipulate and analyze data-quality monitoring files
185  };
186 } // namespace dqutils
187 
188 #endif
dqutils::ATLAS_NOT_THREAD_SAFE
void getImageBuffer ATLAS_NOT_THREAD_SAFE(TImage **img, TCanvas *myC, char **x, int *y)
Definition: HanOutputFile.cxx:1130
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
json
nlohmann::json json
Definition: HistogramDef.cxx:9
rootconvert.fName
string fName
Definition: rootconvert.py:5
plotmaker.hist
hist
Definition: plotmaker.py:148
dqutils::HanOutputFile::m_assessMap
DirToAssMap_t m_assessMap
Same Dim_indirMaprMap, but for files of version 2.
Definition: HanOutputFile.h:181
dqutils::HanOutputFile::DirStrMap_t
std::map< std::string, TObject * > DirStrMap_t
Definition: HanOutputFile.h:41
dirname
std::string dirname(std::string name)
Definition: utils.cxx:200
reference
Definition: hcg.cxx:437
x
#define x
dqutils::HanOutputFile::m_file
TFile * m_file
Definition: HanOutputFile.h:178
grepfile.content
string content
Definition: grepfile.py:56
systematicsTool.writeToFile
def writeToFile(histDict, fOut)
Definition: systematicsTool.py:1035
dqutils::HanOutputFile
Definition: HanOutputFile.h:32
FortranAlgorithmOptions.fileName
fileName
Definition: FortranAlgorithmOptions.py:13
covarianceTool.pathName
pathName
Definition: covarianceTool.py:704
PixelAthClusterMonAlgCfg.histname
histname
Definition: PixelAthClusterMonAlgCfg.py:106
python.CaloCondTools.g
g
Definition: CaloCondTools.py:15
DeMoAtlasDataLoss.canvas
dictionary canvas
Definition: DeMoAtlasDataLoss.py:187
python.handimod.stringAllDQAssessments
def stringAllDQAssessments(resultsFile)
Definition: handimod.py:788
dqutils::HanOutputFile::DirToAssMap_t
std::map< std::string, AssMap_t * > DirToAssMap_t
Definition: HanOutputFile.h:43
dqutils::HanOutputFile::m_indirMap
DirMap_t m_indirMap
Definition: HanOutputFile.h:179
dqutils
Definition: CoolMdt.h:76
pyroot.display
display
Definition: pyroot.py:44
beamspotman.dir
string dir
Definition: beamspotman.py:623
dqutils::HanOutputFile::DirMap_t
std::map< std::string, TDirectory * > DirMap_t
Definition: HanOutputFile.h:40
dqutils::HanOutputFile::m_indirstrMap
DirStrMap_t m_indirstrMap
Definition: HanOutputFile.h:180
python.handimod.saveAllHistograms
def saveAllHistograms(resultsFile, location, drawRefs, run_min_LB, jsRoot)
Definition: handimod.py:795
python.handimod.stringListSystemPaths
def stringListSystemPaths(resultsFile, location)
Definition: handimod.py:781
y
#define y
h
LArG4AODNtuplePlotter.canv
canv
Definition: LArG4AODNtuplePlotter.py:170
dqutils::HanOutputFile::AssMap_t
std::map< std::string, std::string > AssMap_t
DirMap_t but For Version 2 files.
Definition: HanOutputFile.h:42
str
Definition: BTagTrackIpAccessor.cxx:11
dqutils::HanOutputFile::m_style
TStyle * m_style
Definition: HanOutputFile.h:182
checker_macros.h
Define macros for attributes used to control the static checker.
python.PyAthena.obj
obj
Definition: PyAthena.py:132
DeMoGenerateWWW.maindir
string maindir
Definition: DeMoGenerateWWW.py:15
python.compressB64.c
def c
Definition: compressB64.py:93