yoda is hosted by Hepforge, IPPP Durham
YODA - Yet more Objects for Data Analysis  1.7.2
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-2017 The YODA collaboration (see AUTHORS for details)
5 //
6 #include "YODA/Reader.h"
7 #include "YODA/ReaderYODA.h"
8 #include "YODA/ReaderAIDA.h"
9 #include "YODA/ReaderFLAT.h"
11 
12 using namespace std;
13 
14 namespace YODA {
15 
16 
17  Reader& mkReader(const string& name) {
18  // Determine the format from the string (a file or file extension)
19  const size_t lastdot = name.find_last_of(".");
20  string fmt = Utils::toLower(lastdot == string::npos ? name : name.substr(lastdot+1));
21  if (fmt == "gz") {
22  #ifndef HAVE_LIBZ
23  throw UserError("YODA was compiled without zlib support: can't read " + name);
24  #endif
25  const size_t lastbutonedot = (lastdot == string::npos) ? string::npos : name.find_last_of(".", lastdot-1);
26  fmt = Utils::toLower(lastbutonedot == string::npos ? name : name.substr(lastbutonedot+1));
27  }
28  // Create the appropriate Reader
29  if (Utils::startswith(fmt, "yoda")) return ReaderYODA::create();
30  if (Utils::startswith(fmt, "aida")) return ReaderAIDA::create();
31  if (Utils::startswith(fmt, "dat" )) return ReaderFLAT::create();
32  if (Utils::startswith(fmt, "flat")) return ReaderFLAT::create();
33  throw UserError("Format cannot be identified from string '" + name + "'");
34  }
35 
36 
37 }
STL namespace.
Error for problems introduced outside YODA, to put it nicely.
Definition: Exceptions.h:100
Reader & mkReader(const std::string &format_name)
Factory function to make a writer object by format name or a filename.
Definition: Reader.cc:17
Pure virtual base class for various output writers.
Definition: Reader.h:21