Utility class that manages reading and writing template histograms to a ROOT file. More...
#include <TemplateArchive.h>
Public Member Functions | |
TemplateArchive (const char *filename, const char *option) | |
constructor to make separate template files | |
TemplateArchive (TDirectory *dir) | |
constructor to use a directory in an existing file | |
~TemplateArchive () | |
Empty destructor. | |
const char * | GetName () const |
TTemplate * | GetTemplate (const char *template_name) |
Gets the template histogram of the given name and returns it. | |
TTemplate * | GetTemplate (const IDs::channel &channel) |
Gets the template histogram of the given name and returns it. | |
void | SaveTemplate (const TTemplate *hTemplate) |
Takes the given histogram and saves it to the ROOT file. | |
Private Attributes | |
TFile * | fTemplateFile |
The ROOT file that contains the templates. | |
TDirectory * | fDirectory |
Utility class that manages reading and writing template histograms to a ROOT file.
Definition at line 18 of file TemplateArchive.h.
TemplateArchive::TemplateArchive | ( | const char * | filename, | |
const char * | option | |||
) |
constructor to make separate template files
Given a file name and a standard ROOT TFile option (e.g. "READ", "RECREATE" etc.) and opens the ROOT file ready for reading and writing
Definition at line 8 of file TemplateArchive.cpp.
References fDirectory, and fTemplateFile.
00008 { 00009 TDirectory* tmp=gDirectory; 00010 fTemplateFile = new TFile(filename, option); 00011 fDirectory=TDirectory::CurrentDirectory(); 00012 tmp->cd(); 00013 }
TemplateArchive::TemplateArchive | ( | TDirectory * | dir | ) |
constructor to use a directory in an existing file
Definition at line 15 of file TemplateArchive.cpp.
References fDirectory.
00015 :fTemplateFile(NULL){ 00016 fDirectory=dir; 00017 }
TemplateArchive::~TemplateArchive | ( | ) |
Empty destructor.
Definition at line 19 of file TemplateArchive.cpp.
References fTemplateFile.
00019 { 00020 if(fTemplateFile) fTemplateFile->Close(); 00021 }
const char* TemplateArchive::GetName | ( | ) | const [inline] |
Definition at line 44 of file TemplateArchive.h.
References fTemplateFile.
Referenced by TemplateFitAPGenerator::TemplateFitAPGenerator().
00044 {return fTemplateFile?fTemplateFile->GetName(): "";}
TTemplate * TemplateArchive::GetTemplate | ( | const IDs::channel & | channel | ) |
Gets the template histogram of the given name and returns it.
Definition at line 23 of file TemplateArchive.cpp.
References GetTemplate(), and TTemplate::MakeName().
00023 { 00024 return GetTemplate(TTemplate::MakeName(ch).c_str()); 00025 }
TTemplate * TemplateArchive::GetTemplate | ( | const char * | template_name | ) |
Gets the template histogram of the given name and returns it.
Definition at line 29 of file TemplateArchive.cpp.
References fDirectory, and fTemplateFile.
Referenced by GetTemplate(), TemplateConvolveAPGenerator::TemplateConvolveAPGenerator(), and TemplateFitAPGenerator::TemplateFitAPGenerator().
00029 { 00030 00031 TTemplate* hTemplate = NULL; 00032 fDirectory->GetObject(template_name, hTemplate); 00033 if(!hTemplate) { 00034 cout<< "TemplateArchive::GetTemplate: ERROR: Unable to find a template called '" 00035 <<template_name<<"' in file '"<<fTemplateFile->GetName()<<"'"<<endl; 00036 } 00037 return hTemplate; 00038 }
void TemplateArchive::SaveTemplate | ( | const TTemplate * | hTemplate | ) |
Takes the given histogram and saves it to the ROOT file.
Definition at line 42 of file TemplateArchive.cpp.
References fDirectory.
Referenced by TemplateCreator::AfterLastEntry().
00042 { 00043 00044 TDirectory* oldDir = TDirectory::CurrentDirectory(); // should be the directory we were already in 00045 if (hTemplate) { 00046 fDirectory->cd(); 00047 hTemplate->Write(); 00048 } 00049 oldDir->cd(); // go back to the old directory 00050 }
TDirectory* TemplateArchive::fDirectory [private] |
Definition at line 24 of file TemplateArchive.h.
Referenced by GetTemplate(), SaveTemplate(), and TemplateArchive().
TFile* TemplateArchive::fTemplateFile [private] |
The ROOT file that contains the templates.
Definition at line 23 of file TemplateArchive.h.
Referenced by GetName(), GetTemplate(), TemplateArchive(), and ~TemplateArchive().