Jpp test-rotations-new
the software that should make you happy
Loading...
Searching...
No Matches
JFileScanner.hh
Go to the documentation of this file.
1#ifndef __JSUPPORT__JFILESCANNER__
2#define __JSUPPORT__JFILESCANNER__
3
4#include <string>
5
7#include "JLang/JException.hh"
8#include "Jeep/JPrint.hh"
14
15
16/**
17 * \author mdejong
18 */
19
20namespace JSUPPORT {}
21namespace JPP { using namespace JSUPPORT; }
22
23namespace JSUPPORT {
24
28
29
30 /**
31 * Object reading from file.
32 *
33 * This class implements the method open of the JLANG::JAccessible interface.
34 * The file format is derived from the file name extension.
35 */
36 template<class T>
39 {
40 public:
41
43
44 /**
45 * Default constructor.
46 */
48 {}
49
50
51 /**
52 * Constructor.
53 *
54 * \param file_name file name
55 */
56 JFileScanner(const char* file_name)
57 {
58 open(file_name);
59 }
60
61
62 /**
63 * Destructor.
64 */
66 {
67 if (this->is_open()) {
68 this->close();
69 }
70 }
71
72
73 /**
74 * Open file.
75 *
76 * \param file_name file name
77 */
78 virtual void open(const char* file_name) override
79 {
80 using namespace std;
81 using namespace JPP;
82
83 JAccessible::Throw(true);
84
85 if (getProtocol(file_name) == ROOT_FILE_FORMAT)
86 this->reset(new JRootFileReader<T>());
87 else if (getFilenameExtension(file_name) == ROOT_FILE_FORMAT)
88 this->reset(new JRootFileReader<T>());
89 else if (getFilenameExtension(file_name) == DAQ_FILE_FORMAT)
90 this->reset(new JDAQFileReader<T>());
91 else if (getFilenameExtension(file_name) == JPP_FILE_FORMAT)
92 this->reset(new JBinaryFileReader<T>());
93 else if (getFilenameExtension(file_name) == MONTE_CARLO_FILE_FORMAT)
95 else if (getFilenameExtension(file_name) == GZIP_FILE_FORMAT)
97 else
98 this->Throw(JProtocolException(MAKE_STRING("Protocol not defined: " << file_name)));
99
100 if (this->is_valid()) {
101
102 this->get()->open(file_name);
103
104 if (!this->get()->is_open()) {
105 if (getFilenameExtension(file_name) != ROOT_FILE_FORMAT) {
106 JAccessible::Throw(JFileOpenException("File not opened."));
107 }
108 }
109 }
110 }
111
112
113 /**
114 * Close device.
115 */
116 virtual void close() override
117 {
118 if (this->is_valid()) {
119 this->get()->close();
120 this->reset();
121 }
122 }
123 };
124}
125
126#endif
Exceptions.
Specifications of file name extensions.
I/O formatting auxiliaries.
#define MAKE_STRING(A)
Make string.
Definition JPrint.hh:63
Object reading from binary file (i.e. .jpp).
Exception for opening of file.
virtual JAccessibleObjectIterator< T > * get() const override
Definition JPointer.hh:64
Protocol exception.
static void Throw(const bool option)
Definition JThrow.hh:37
DAQ object reading from binary file (i.e. .dat).
Object reading from file.
JFileScanner(const char *file_name)
Constructor.
virtual void close() override
Close device.
JAccessibleObjectReader< T >::helper_type helper_type
virtual void open(const char *file_name) override
Open file.
JFileScanner()
Default constructor.
~JFileScanner()
Destructor.
Template definition of Monte Carlo object reader for ASCII formatted file (i.e. '....
Template definition of Monte Carlo object reader for gzipped ASCII formatted file (i....
std::string getFilenameExtension(const std::string &file_name)
Get file name extension, i.e. part after last JEEP::FILENAME_SEPARATOR if any.
std::string getProtocol(const std::string &file_name)
Get protocol, i.e. part before first JEEP::PROTOCOL_SEPARATOR if any.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Support classes and methods for experiment specific I/O.
static const char *const DAQ_FILE_FORMAT
file name extension DAQ binary format
static const char *const GZIP_FILE_FORMAT
file name extension gzip format
static const char *const JPP_FILE_FORMAT
file name extension Jpp binary format
static const char *const ROOT_FILE_FORMAT
file name extension ROOT format
static const char *const MONTE_CARLO_FILE_FORMAT
file name extension ASCII format
virtual bool is_open() const override
Check is device is open.
Auxiliary class for object reading with named access.