GRSISort "v4.0.0.5"
An extension of the ROOT analysis Framework
Loading...
Searching...
No Matches
GSnapshot.cxx
Go to the documentation of this file.
1#include "GSnapshot.h"
2
3#include "TCanvas.h"
4#include "TDatime.h"
5#include "TH2.h"
6#include "TList.h"
7#include "TSystem.h"
8#include "TEnv.h"
9
11{
12 static GSnapshot snapshot;
13 return snapshot;
14}
15
16GSnapshot::GSnapshot(const char* snapshot_dir)
17{
18 if(snapshot_dir != nullptr) {
19 fSnapshotDir = snapshot_dir;
20 } else if(gEnv->Defined("GRUT.SnapshotDir")) {
21 fSnapshotDir = gEnv->GetValue("GRUT.SnapshotDir", "");
22 } else {
23 fSnapshotDir = Form("%s/snapshot", getenv("GRSISYS"));
24 }
25
26 // True from AccessPathName() means file does not exist.
27 bool dir_exists = !gSystem->AccessPathName(fSnapshotDir.c_str());
28
29 if(dir_exists) {
30 Long_t id = 0;
31 Long_t size = 0;
32 Long_t flags = 0;
33 Long_t modtime = 0;
34 gSystem->GetPathInfo(fSnapshotDir.c_str(), &id, &size, &flags, &modtime);
35 bool output_dir_is_dir = (flags & 2) != 0;
36 fCanWriteHere = output_dir_is_dir;
37 } else {
38 gSystem->mkdir(fSnapshotDir.c_str(), true);
39 fCanWriteHere = true;
40 }
41}
42
43void GSnapshot::Snapshot(TCanvas* can)
44{
45 if((can == nullptr) && gPad) {
46 can = gPad->GetCanvas();
47 }
48 if(!fCanWriteHere || (can == nullptr)) {
49 return;
50 }
51
52 // bool needs_png = false;
53 // for(auto obj : *can->GetListOfPrimitives()) {
54 // if(obj->InheritsFrom(TH2::Class())) {
55 // needs_png = true;
56 // break;
57 // }
58 //}
59 // const char* ext = needs_png ? "png" : "pdf";
60
61 std::string ext = gEnv->GetValue("GRUT.SnapshotExt", "");
62 if(ext.length() == 0) {
63 ext = "pdf"; // TODO, make this smarter again...
64 }
65
66 int date = 0;
67 int time = 0;
68 TDatime::GetDateTime(TDatime().Get(), date, time);
69
70 can->SaveAs(Form("%s/%s_%d_%d.%s", fSnapshotDir.c_str(), can->GetName(), date, time, ext.c_str()));
71}
static GSnapshot & Get()
Definition GSnapshot.cxx:10
bool fCanWriteHere
Definition GSnapshot.h:25
GSnapshot(const char *snapshot_dir=nullptr)
Definition GSnapshot.cxx:16
std::string fSnapshotDir
Definition GSnapshot.h:24
void Snapshot(TCanvas *can=nullptr)
Definition GSnapshot.cxx:43