00001
00002 #include "cafe/EventListExpander.hpp"
00003
00004 #include <stdexcept>
00005
00006 #include "TFile.h"
00007 #include "TKey.h"
00008 #include "TList.h"
00009 #include "TEventList.h"
00010
00011 namespace cafe {
00012
00013 EventListExpander::EventListExpander(const char *url)
00014 : Expander()
00015 {
00016 const char *ptr = strchr(url, ':') + 1;
00017 TFile file(ptr, "READ");
00018 if(!file.IsZombie()) {
00019 if(TList *keys = file.GetListOfKeys()) {
00020 TIter iter(keys);
00021 while(TKey *k = (TKey *)iter.Next()) {
00022 if(strcmp(k->GetClassName(), "TEventList") == 0) {
00023 if(TEventList *ev_list = dynamic_cast<TEventList*>(file.Get(k->GetName()))) {
00024 _files.push_back(ev_list->GetTitle());
00025 }
00026 }
00027 }
00028 }
00029 } else {
00030 throw std::runtime_error("EventListExpander: cannot open file: " + std::string(url));
00031 }
00032 }
00033
00034 std::string EventListExpander::nextFile()
00035 {
00036 if(_files.empty()) return "";
00037 std::string result = _files.front();
00038 _files.pop_front();
00039 return result;
00040 }
00041 }
00042
00043 ClassImp(cafe::EventListExpander);