00001 #include "TemplateArchive.h" 00002 #include <iostream> 00003 00004 using std::cout; 00005 using std::endl; 00006 00007 // option is standard ROOT file options 00008 TemplateArchive::TemplateArchive(const char* filename, const char* option) { 00009 TDirectory* tmp=gDirectory; 00010 fTemplateFile = new TFile(filename, option); 00011 fDirectory=TDirectory::CurrentDirectory(); 00012 tmp->cd(); 00013 } 00014 00015 TemplateArchive::TemplateArchive(TDirectory* dir):fTemplateFile(NULL){ 00016 fDirectory=dir; 00017 } 00018 00019 TemplateArchive::~TemplateArchive() { 00020 if(fTemplateFile) fTemplateFile->Close(); 00021 } 00022 00023 TTemplate* TemplateArchive::GetTemplate(const IDs::channel& ch) { 00024 return GetTemplate(TTemplate::MakeName(ch).c_str()); 00025 } 00026 00027 // GetTemplate() 00028 // -- gets a template from the template file 00029 TTemplate* TemplateArchive::GetTemplate(const char* template_name) { 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 } 00039 00040 // SaveTemplate() 00041 // -- saves a template to the template file 00042 void TemplateArchive::SaveTemplate(const TTemplate* hTemplate) { 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 }