Go to the documentation of this file.00001 #include "ForIA/D3PD/D3PDDataLoader.hh"
00002 #include "ForIA/binreloc.h"
00003 #include "TFile.h"
00004
00005 #include <cstdlib>
00006 #include <iostream>
00007
00008 namespace ForIA{
00009
00010 IDataLoader::Creator<D3PDDataLoader> D3PDDataLoaderCreator;
00011
00012 D3PDDataLoader::D3PDDataLoader(): m_file(0){
00013
00014 }
00015
00016 D3PDDataLoader::~D3PDDataLoader(){
00017 if(m_file != 0){
00018 delete m_file;
00019 }
00020 }
00021
00022 bool D3PDDataLoader::open(const string &file)throw(NoFileException){
00023 if(m_file != 0){
00024 delete m_file;
00025 }
00026
00027 char *envPath=0;
00028 envPath = getenv("FORIA_DATA_PATH");
00029
00030 string path;
00031
00032 if(envPath){
00033 path = envPath;
00034 }else{
00035 BrInitError brError;
00036 br_init_lib(&brError);
00037 path = br_find_data_dir(DEFAULTDATADIR);
00038 }
00039
00040 path=path + "/" + file;
00041
00042 string datadir = path.substr(0, path.find_last_of("/"));
00043
00044 std::cout<<"Searching path " << datadir
00045 << " for file " << file.substr(file.find_last_of("/")+1)<<std::endl;
00046
00047 m_file = new TFile(path.c_str(), "READ");
00048 if(m_file->IsZombie()){
00049 delete m_file;
00050 m_file = 0;
00051 throw NoFileException(file);
00052 }
00053
00054 if(m_file == 0) return false;
00055
00056 return true;
00057 }
00058
00059 bool D3PDDataLoader::close(){
00060
00061 if(m_file == 0) return false;
00062
00063 delete m_file;
00064 m_file = 0;
00065
00066 return true;
00067 }
00068
00069 void* D3PDDataLoader::retrieve(const string &name,
00070 const type_info &type) throw(NoFileException){
00071
00072 if(m_file == 0) throw NoFileException();
00073
00074 void *ptr = m_file->GetObjectChecked(name.c_str(), TBuffer::GetClass(type));
00075
00076 return ptr;
00077 }
00078
00079 }