otsdaq  v2_01_00
DQMHistosBase.cc
1 #include "otsdaq-core/RootUtilities/DQMHistosBase.h"
2 #include "otsdaq-core/Macros/CoutMacros.h"
3 
4 #include <TDirectory.h>
5 #include <TFile.h>
6 #include <TObject.h>
7 #include <TStyle.h>
8 
9 #include <iostream>
10 
11 using namespace ots;
12 
13 
14 //========================================================================================================================
15 DQMHistosBase::DQMHistosBase(void)
16 : theFile_ (0)
17 , myDirectory_ (0)
18 {
19  gStyle->SetPalette(1);
20 }
21 
22 //========================================================================================================================
23 DQMHistosBase::~DQMHistosBase(void)
24 {
25  closeFile();
26 }
27 
28 //========================================================================================================================
29 void DQMHistosBase::openFile (std::string fileName)
30 {
31  closeFile();
32  myDirectory_ = 0;
33  theFile_ = TFile::Open(fileName.c_str(), "RECREATE");
34  theFile_->cd();
35 }
36 
37 //========================================================================================================================
38 void DQMHistosBase::save(void)
39 {
40  std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << "Saving file!" << std::endl;
41  if (theFile_ != 0)
42  theFile_->Write();
43 }
44 
45 //========================================================================================================================
46 void DQMHistosBase::closeFile(void)
47 {
48  if (theFile_ != 0)
49  {
50  theFile_->Close();
51  theFile_ = 0;
52  }
53 }
54 
55 //========================================================================================================================
56 TObject* DQMHistosBase::get(std::string name)
57 {
58  if (theFile_ != 0)
59  return theFile_->Get(name.c_str());
60  return 0;
61 }