diff --git a/include/hepnos/FileDataStore.hpp b/include/hepnos/FileDataStore.hpp index 1e6fcaa8c87df41423f0845d997e2e1f65828d3f..fd0fbcb77dfcfb2acb274189460a7b223de887f0 100644 --- a/include/hepnos/FileDataStore.hpp +++ b/include/hepnos/FileDataStore.hpp @@ -43,6 +43,15 @@ public: return FileNamespace(); } + event_type getEventByID(std::uint64_t id) { + std::stringstream ss; + ss << _path << ".ref/" << std::setfill('0') << std::setw(20) << id; + std::string link = ss.str(); + if(!fs::exists(link)) return FileEvent(); + std::string p = fs::canonical(link).string(); + return FileEvent(p); + } + private: std::string _path; diff --git a/include/hepnos/FileEvent.hpp b/include/hepnos/FileEvent.hpp index 4eefb2e3c6134aeaaf5804cb7386ddc97bc05bb6..21e95e9930dfd98d6272b71146131b0fdf93b63c 100644 --- a/include/hepnos/FileEvent.hpp +++ b/include/hepnos/FileEvent.hpp @@ -13,11 +13,13 @@ namespace hepnos { namespace fs = boost::filesystem; class FileSubRun; +class FileDataStore; class FileEvent : public ProductAccessor { private: + friend class FileDataStore; friend class FileSubRun; friend class FileObjectIterator; @@ -42,6 +44,24 @@ class FileEvent : public ProductAccessor { createRefAndSetID(); } + FileEvent(const std::string& dir) + : ProductAccessor(dir) + , _eventNumber(0) + , _path(dir) { + if(_path.back() != '/') _path += std::string("/"); + std::size_t i,j; + j = _path.size()-1; + if(_path[j] == '/') j--; + i = j; + while(_path[i] != '/') i--; + i += 1; + while(_path[i] == '0') i++; + j += 1; + std::string eventDir(&dir[i], j-i); + if(eventDir.size() > 0) + _eventNumber = std::stoi(eventDir); + } + FileEvent() : ProductAccessor("") , _eventNumber(std::numeric_limits::max())