yoda is hosted by Hepforge, IPPP Durham
YODA - Yet more Objects for Data Analysis 2.1.0
Reader.cc
Go to the documentation of this file.
1// -*- C++ -*-
2//
3// This file is part of YODA -- Yet more Objects for Data Analysis
4// Copyright (C) 2008-2025 The YODA collaboration (see AUTHORS for details)
5//
6#include "YODA/ReaderYODA.h"
7#include "YODA/ReaderFLAT.h"
9
10#ifdef HAVE_HDF5
11#include "YODA/ReaderH5.h"
12#endif
13
14using namespace std;
15
16namespace YODA {
17
18
19 Reader& mkReader(const string& name) {
20 // Determine the format from the string (a file or file extension)
21 const size_t lastdot = name.find_last_of(".");
22 string fmt = Utils::toLower(lastdot == string::npos ? name : name.substr(lastdot+1));
23 if (fmt == "gz") {
24 #ifndef HAVE_LIBZ
25 throw UserError("YODA was compiled without zlib support: can't read " + name);
26 #endif
27 const size_t lastbutonedot = (lastdot == string::npos) ? string::npos : name.find_last_of(".", lastdot-1);
28 fmt = Utils::toLower(lastbutonedot == string::npos ? name : name.substr(lastbutonedot+1));
29 }
30 // Create the appropriate Reader
31 #ifdef HAVE_HDF5
32 if (Utils::startswith(fmt, "h5")) return ReaderH5::create();
33 #endif
34 if (Utils::startswith(fmt, "yoda")) return ReaderYODA::create();
35 if (Utils::startswith(fmt, "dat" )) return ReaderFLAT::create();
36 if (Utils::startswith(fmt, "flat")) return ReaderFLAT::create();
37 throw UserError("Format cannot be identified from string '" + name + "'");
38 }
39
40
41}
static Reader & create()
Singleton creation function.
static Reader & create()
Singleton creation function.
Definition ReaderH5.cc:28
static Reader & create()
Singleton creation function.
Pure virtual base class for various output writers.
Definition Reader.h:35
Error for problems introduced outside YODA, to put it nicely.
Definition Exceptions.h:86
Anonymous namespace to limit visibility.
Reader & mkReader(const std::string &format_name)
Factory function to make a reader object by format name or a filename.
Definition Reader.cc:19