otsdaq  v2_04_01
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 DQMHistosBase::DQMHistosBase(void) : theFile_(0), myDirectory_(0)
15 {
16  gStyle->SetPalette(1);
17 }
18 
19 //========================================================================================================================
20 DQMHistosBase::~DQMHistosBase(void) { closeFile(); }
21 
22 //========================================================================================================================
23 void DQMHistosBase::openFile(std::string fileName)
24 {
25  closeFile();
26  myDirectory_ = 0;
27  theFile_ = TFile::Open(fileName.c_str(), "RECREATE");
28  theFile_->cd();
29 }
30 
31 //========================================================================================================================
32 void DQMHistosBase::save(void)
33 {
34  std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << "Saving file!" << std::endl;
35  if(theFile_ != 0)
36  theFile_->Write();
37 }
38 
39 //========================================================================================================================
40 void DQMHistosBase::closeFile(void)
41 {
42  if(theFile_ != 0)
43  {
44  theFile_->Close();
45  theFile_ = 0;
46  }
47 }
48 
49 //========================================================================================================================
50 TObject* DQMHistosBase::get(std::string name)
51 {
52  if(theFile_ != 0)
53  return theFile_->Get(name.c_str());
54  return 0;
55 }