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

Object writing to file. More...

#include <JFileRecorder.hh>

Inheritance diagram for JSUPPORT::JFileRecorder< T >:
JLANG::JAccessibleObjectWriter< T > JLANG::JAccessibleObjectOutput< T > JLANG::JAbstractAccessibleObjectWriter< T > JLANG::JObjectOutput< T > JLANG::JAccessible JLANG::JAccessibleObjectOutput< T > JLANG::JAbstractObjectWriter< T > JLANG::JThrow< JAccessible > JLANG::JObjectOutput< T > JLANG::JAccessible JLANG::JObjectOutput< T > JLANG::JThrow< JAccessible >

Public Types

typedef std::shared_ptr< JAccessibleObjectOutput< T > > helper_type
 

Public Member Functions

 JFileRecorder ()
 Default constructor.
 
 JFileRecorder (const char *file_name)
 Constructor.
 
const std::string & getFilename () const
 Get file name.
 
const void setFilename (const std::string &file_name)
 Set file name.
 
virtual void open (const char *file_name) override
 Open file.
 
void open ()
 Open file.
 
virtual JAccessibleObjectOutput< T > * getHelper () const override
 Get helper.
 
virtual bool put (const T &object) override
 Object output.
 
virtual bool is_open () const override
 Check is device is open.
 
virtual void close () override
 Close device.
 

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.
 

Protected Attributes

std::string fileName
 

Static Protected Attributes

static bool do_throw
 throw option
 

Friends

std::istream & operator>> (std::istream &in, JFileRecorder &recorder)
 Read file recorder from input.
 
std::ostream & operator<< (std::ostream &out, const JFileRecorder &recorder)
 Write file recorder to output.
 

Detailed Description

template<class T>
class JSUPPORT::JFileRecorder< T >

Object writing to file.

This class implements the method open of the JLANG::JAccessible interface. The file format is derived from the file name extension. The method open can be called to open a file after reading the file name.

Definition at line 42 of file JFileRecorder.hh.

Member Typedef Documentation

◆ helper_type

template<class T >
std::shared_ptr< JAccessibleObjectOutput<T> > JLANG::JAccessibleObjectWriter< T >::helper_type
inherited

Definition at line 65 of file JObjectWriter.hh.

Constructor & Destructor Documentation

◆ JFileRecorder() [1/2]

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

Default constructor.

Definition at line 49 of file JFileRecorder.hh.

49 :
51 fileName("")
52 {}
JAccessibleObjectWriter()
Default constructor.

◆ JFileRecorder() [2/2]

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

Constructor.

Parameters
file_namefile name

Definition at line 60 of file JFileRecorder.hh.

60 :
62 fileName(file_name)
63 {}

Member Function Documentation

◆ getFilename()

template<class T >
const std::string & JSUPPORT::JFileRecorder< T >::getFilename ( ) const
inline

Get file name.

Returns
file name

Definition at line 71 of file JFileRecorder.hh.

72 {
73 return fileName;
74 }

◆ setFilename()

template<class T >
const void JSUPPORT::JFileRecorder< T >::setFilename ( const std::string & file_name)
inline

Set file name.

Parameters
file_namefile name

Definition at line 82 of file JFileRecorder.hh.

83 {
84 fileName = file_name;
85 }

◆ open() [1/2]

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

Open file.

Parameters
file_namefile name

Implements JLANG::JAccessible.

Definition at line 93 of file JFileRecorder.hh.

94 {
95 fileName = file_name;
96
97 open();
98 }

◆ open() [2/2]

template<class T >
void JSUPPORT::JFileRecorder< T >::open ( )
inline

Open file.

Definition at line 104 of file JFileRecorder.hh.

105 {
106 using namespace JPP;
107
108 this->reset();
109
110 if (isROOTFile(fileName.c_str())) {
111
112 this->reset(new JRootFileWriter<T>());
113
114 } else if (isDAQFile(fileName.c_str())) {
115
116 this->reset(new JDAQFileWriter<T>());
117
118 } else if (isJppFile(fileName.c_str())) {
119
120 this->reset(new JBinaryFileWriter<T>());
121
122 } else if (isMonteCarloFile(fileName.c_str())) {
123
124 this->reset(new JMonteCarloFileWriter<T>());
125
126 } else if (fileName.empty() || fileName == "/dev/null") {
127
128 this->reset(new JNullAccessibleOutput<T>());
129
130 } else {
131
132 THROW(JProtocolException, "Protocol not defined: " << fileName);
133 }
134
135 if (this->get() != NULL) {
136 this->get()->open(fileName.c_str());
137 }
138
139 if (!this->get()->is_open()) {
140 THROW(JFileOpenException, "Error opening file: " << fileName);
141 }
142 }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Object(s) writing to binary file (i.e. .jpp).
Exception for opening of file.
Protocol exception.
ROOT file object output.
Object(s) writing to binary file (i.e. .dat).
Object(s) writing to Monte Carlo ASCII file (i.e. .evt)
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
bool isROOTFile(const char *file_name)
Check file format.
bool isJppFile(const char *file_name)
Check file format.
bool isDAQFile(const char *file_name)
Check file format.
bool isMonteCarloFile(const char *file_name)
Check file format.
void reset(T &value)
Reset value.
virtual bool is_open() const override
Check is device is open.
Implementation for null output with null access.

◆ getHelper()

template<class T >
virtual JAccessibleObjectOutput< T > * JLANG::JAccessibleObjectWriter< T >::getHelper ( ) const
inlineoverridevirtualinherited

Get helper.

Returns
helper

Implements JLANG::JAbstractAccessibleObjectWriter< T >.

Definition at line 79 of file JObjectWriter.hh.

80 {
81 return this->get();
82 }

◆ put()

template<class T >
virtual bool JLANG::JAbstractObjectWriter< T >::put ( const T & object)
inlineoverridevirtualinherited

Object output.

Parameters
objectobject
Returns
true if OK; else false

Implements JLANG::JObjectOutput< T >.

Definition at line 43 of file JAbstractObjectWriter.hh.

44 {
45 return (this->getHelper() != NULL && this->getHelper()->put(object));
46 }
virtual JObjectOutput< T > * getHelper() const =0
Get helper.
virtual bool put(const T &object) override
Object output.

◆ is_open()

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

Check is device is open.

Returns
true if open; else false

Implements JLANG::JAccessible.

Definition at line 102 of file JAbstractObjectWriter.hh.

103 {
104 if (this->getHelper() != NULL)
105 return this->getHelper()->is_open();
106 else
107 return false;
108 }
virtual JAccessibleObjectOutput< T > * getHelper() const override=0
Get helper.

◆ close()

template<class T >
virtual void JLANG::JAbstractAccessibleObjectWriter< T >::close ( )
inlineoverridevirtualinherited

Close device.

Implements JLANG::JAccessible.

Definition at line 127 of file JAbstractObjectWriter.hh.

128 {
129 if (this->getHelper() != NULL) {
130 this->getHelper()->close();
131 }
132 }

◆ 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 }

Friends And Related Symbol Documentation

◆ operator>>

template<class T >
std::istream & operator>> ( std::istream & in,
JFileRecorder< T > & recorder )
friend

Read file recorder from input.

Parameters
ininput stream
recorderJFileRecorder
Returns
input stream

Definition at line 152 of file JFileRecorder.hh.

153 {
154 in >> recorder.fileName;
155
156 return in;
157 }

◆ operator<<

template<class T >
std::ostream & operator<< ( std::ostream & out,
const JFileRecorder< T > & recorder )
friend

Write file recorder to output.

Parameters
outoutput stream
recorderJFileRecorder
Returns
output stream

Definition at line 167 of file JFileRecorder.hh.

168 {
169 out << recorder.fileName;
170
171 return out;
172 }

Member Data Documentation

◆ fileName

template<class T >
std::string JSUPPORT::JFileRecorder< T >::fileName
protected

Definition at line 175 of file JFileRecorder.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: