Jpp 21.0.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
JSUPPORT::JFileScanner< T > Class Template Reference

Object reading from file. More...

#include <JFileScanner.hh>

Inheritance diagram for JSUPPORT::JFileScanner< T >:
JLANG::JAccessibleObjectReader< T > JLANG::JAccessibleObjectIterator< T > JLANG::JAbstractAccessibleObjectReader< T > JLANG::JObjectIterator< T > JLANG::JAccessible JLANG::JAccessibleObjectIterator< T > JLANG::JAbstractObjectReader< T > JLANG::JThrow< JAccessible > JLANG::JObjectIterator< T > JLANG::JAccessible JLANG::JObjectIterator< T > JLANG::JThrow< JAccessible >

Public Types

typedef JAccessibleObjectReader< T >::helper_type helper_type
 
typedef JObjectIterator< T >::pointer_type pointer_type
 

Public Member Functions

 JFileScanner ()
 Default constructor.
 
 JFileScanner (const char *file_name)
 Constructor.
 
 ~JFileScanner ()
 Destructor.
 
virtual void open (const char *file_name) override
 Open file.
 
virtual void close () override
 Close device.
 
virtual JAccessibleObjectIterator< T > * getHelper () const override
 Get helper.
 
virtual bool hasNext () override
 Check availability of next element.
 
virtual const pointer_typenext () override
 Get next element.
 
virtual skip_type skip (const skip_type ns) override
 Skip items.
 
virtual bool is_open () const override
 Check is device is open.
 
bool is_valid () const
 Check validity of helper.
 

Static Public Member Functions

static void Throw (const bool option)
 Enable/disable throw option.
 
static int Throw (const JException_t &error, const int value=-1)
 Throw exception or return error.
 

Static Protected Attributes

static bool do_throw
 throw option
 

Private Attributes

pointer_type ps
 

Detailed Description

template<class T>
class JSUPPORT::JFileScanner< T >

Object reading from file.

This class implements the method open of the JLANG::JAccessible interface. The file format is derived from the file name extension.

Definition at line 37 of file JFileScanner.hh.

Member Typedef Documentation

◆ helper_type

template<class T >
JAccessibleObjectReader<T>::helper_type JSUPPORT::JFileScanner< T >::helper_type

Definition at line 42 of file JFileScanner.hh.

◆ pointer_type

template<class T >
JObjectIterator<T>::pointer_type JLANG::JAccessibleObjectReader< T >::pointer_type
inherited

Definition at line 99 of file JObjectReader.hh.

Constructor & Destructor Documentation

◆ JFileScanner() [1/2]

template<class T >
JSUPPORT::JFileScanner< T >::JFileScanner ( )
inline

Default constructor.

Definition at line 47 of file JFileScanner.hh.

48 {}

◆ JFileScanner() [2/2]

template<class T >
JSUPPORT::JFileScanner< T >::JFileScanner ( const char * file_name)
inline

Constructor.

Parameters
file_namefile name

Definition at line 56 of file JFileScanner.hh.

57 {
58 open(file_name);
59 }
virtual void open(const char *file_name) override
Open file.

◆ ~JFileScanner()

template<class T >
JSUPPORT::JFileScanner< T >::~JFileScanner ( )
inline

Destructor.

Definition at line 65 of file JFileScanner.hh.

66 {
67 if (this->is_open()) {
68 this->close();
69 }
70 }
virtual void close() override
Close device.
virtual bool is_open() const override
Check is device is open.

Member Function Documentation

◆ open()

template<class T >
virtual void JSUPPORT::JFileScanner< T >::open ( const char * file_name)
inlineoverridevirtual

Open file.

Parameters
file_namefile name

Implements JLANG::JAccessible.

Definition at line 78 of file JFileScanner.hh.

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 }
#define MAKE_STRING(A)
Make string.
Definition JPrint.hh:48
Object reading from binary file (i.e. .jpp).
Exception for opening of file.
Protocol exception.
static void Throw(const bool option)
Definition JThrow.hh:37
DAQ object reading from binary file (i.e. .dat).
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).
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
void reset(T &value)
Reset value.
bool is_valid() const
Check validity of helper.

◆ close()

template<class T >
virtual void JSUPPORT::JFileScanner< T >::close ( )
inlineoverridevirtual

Close device.

Implements JLANG::JAccessible.

Definition at line 116 of file JFileScanner.hh.

117 {
118 if (this->is_valid()) {
119 this->get()->close();
120 this->reset();
121 }
122 }

◆ getHelper()

template<class T >
virtual JAccessibleObjectIterator< T > * JLANG::JAccessibleObjectReader< T >::getHelper ( ) const
inlineoverridevirtualinherited

Get helper.

Returns
helper

Implements JLANG::JAbstractAccessibleObjectReader< T >.

Definition at line 113 of file JObjectReader.hh.

114 {
115 return this->get();
116 }

◆ hasNext()

template<class T >
virtual bool JLANG::JAbstractObjectReader< T >::hasNext ( )
inlineoverridevirtualinherited

Check availability of next element.

Returns
true if the iteration has more elements; else false

Implements JLANG::JObjectIterator< T >.

Definition at line 54 of file JAbstractObjectReader.hh.

55 {
56 return (this->is_valid() && this->getHelper()->hasNext());
57 }
virtual bool hasNext() override
Check availability of next element.
virtual JObjectIterator< T > * getHelper() const =0
Get helper.

◆ next()

template<class T >
virtual const pointer_type & JLANG::JAbstractObjectReader< T >::next ( )
inlineoverridevirtualinherited

Get next element.

Returns
pointer to element

Implements JLANG::JObjectIterator< T >.

Definition at line 65 of file JAbstractObjectReader.hh.

66 {
67 if (this->is_valid())
68 return this->getHelper()->next();
69 else
70 return ps;
71 }

◆ skip()

template<class T >
virtual skip_type JLANG::JAbstractObjectReader< T >::skip ( const skip_type ns)
inlineoverridevirtualinherited

Skip items.

Parameters
nsnumber of items to skip
Returns
number of items skipped

Reimplemented from JLANG::JObjectIterator< T >.

Definition at line 80 of file JAbstractObjectReader.hh.

81 {
82 if (this->is_valid())
83 return this->getHelper()->skip(ns);
84 else
85 return 0;
86 }

◆ is_open()

template<class T >
virtual bool JLANG::JAbstractAccessibleObjectReader< T >::is_open ( ) const
inlineoverridevirtualinherited

Check is device is open.

Returns
true if open; else false

Implements JLANG::JAccessible.

Definition at line 148 of file JAbstractObjectReader.hh.

149 {
150 if (this->is_valid())
151 return this->getHelper()->is_open();
152 else
153 return false;
154 }
virtual JAccessibleObjectIterator< T > * getHelper() const override=0
Get helper.

◆ is_valid()

template<class T >
bool JLANG::JAbstractObjectReader< T >::is_valid ( ) const
inlineinherited

Check validity of helper.

Returns
true if helper not null; else false

Definition at line 35 of file JAbstractObjectReader.hh.

36 {
37 return this->getHelper() != NULL;
38 }

◆ Throw() [1/2]

static void JLANG::JThrow< JAccessible >::Throw ( const bool option)
inlinestaticinherited

Enable/disable throw option.

Parameters
optiontrue enable; false disable

Definition at line 37 of file JThrow.hh.

38 {
39 do_throw = option;
40 }

◆ Throw() [2/2]

static int JLANG::JThrow< JAccessible >::Throw ( const JException_t & error,
const int value = -1 )
inlinestaticinherited

Throw exception or return error.

Parameters
errorexception
valuereturn code
Returns
return code

Definition at line 51 of file JThrow.hh.

52 {
53 using namespace std;
54
55 if (do_throw) {
56 throw error;
57 }
58
59 cerr << error.what() << endl;
60
61 return value;
62 }

Member Data Documentation

◆ ps

template<class T >
pointer_type JLANG::JAbstractObjectReader< T >::ps
privateinherited

Definition at line 89 of file JAbstractObjectReader.hh.

◆ do_throw

bool JLANG::JThrow< JAccessible >::do_throw
staticprotectedinherited

throw option

Set default throw option to true.

Definition at line 28 of file JThrow.hh.


The documentation for this class was generated from the following file: