Jpp
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | Private Attributes | List of all members
JSUPPORT::JDAQFileReader< T, true > Class Template Reference

Template specialisation of JDAQFileReader for DAQ compatible data types. More...

#include <JDAQFileReader.hh>

Inheritance diagram for JSUPPORT::JDAQFileReader< T, true >:
JIO::JBinaryFileReader< T > JLANG::JAccessibleBinaryInputStream JIO::JStreamReader JIO::JReaderObjectIterator< T > JLANG::JAccessibleObjectIterator< T > JLANG::JAccessibleInputStream JIO::JReader JLANG::JAbstractObjectIterator< T > JLANG::JObjectIterator< T > JLANG::JAccessible JLANG::JAccessible JLANG::JBinaryInput JLANG::JAbstractObjectStatus JLANG::JObjectIterator< T > JLANG::JThrow< JAccessible > JLANG::JThrow< JAccessible >

Public Types

typedef JObjectIterator< T >::pointer_type pointer_type
 

Public Member Functions

virtual bool setObject (T &object)
 Set object. More...
 
virtual void open (const char *file_name)
 Open file. More...
 
virtual bool is_open () const
 Check is file is open. More...
 
virtual void close ()
 Close file. More...
 
virtual bool hasNext ()
 Check availability of next element. More...
 
virtual const pointer_typenext ()
 Get next element. More...
 
virtual skip_type skip (const skip_type ns)
 Skip items. More...
 

Static Public Member Functions

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

Protected Member Functions

virtual bool getStatus () const
 Status of reader. More...
 
virtual void clear ()
 Clear status of reader. More...
 
virtual int read (char *buffer, const int length)
 Read byte array. More...
 
JReaderoperator>> (JSerialisable &object)
 Read serialisable data object. More...
 
JReaderoperator>> (bool &value)
 
JReaderoperator>> (char &value)
 
JReaderoperator>> (unsigned char &value)
 
JReaderoperator>> (short &value)
 
JReaderoperator>> (unsigned short &value)
 
JReaderoperator>> (int &value)
 
JReaderoperator>> (unsigned int &value)
 
JReaderoperator>> (long int &value)
 
JReaderoperator>> (unsigned long int &value)
 
JReaderoperator>> (long long int &value)
 
JReaderoperator>> (unsigned long long int &value)
 
JReaderoperator>> (float &value)
 
JReaderoperator>> (double &value)
 
JReaderoperator>> (long double &value)
 
JReaderload (JSerialisable &object)
 Read object. More...
 
template<class T >
JReaderload (T &object)
 Read object. More...
 
 operator bool () const
 Type conversion operator. More...
 
bool operator! () const
 Negated status of this object. More...
 

Protected Attributes

std::istream & in
 
object
 object More...
 
bool has_next
 status More...
 

Static Protected Attributes

static bool do_throw
 throw option More...
 

Private Attributes

JDAQPreamble preamble
 
std::vector< char > buffer
 
pointer_type ps
 

Detailed Description

template<class T>
class JSUPPORT::JDAQFileReader< T, true >

Template specialisation of JDAQFileReader for DAQ compatible data types.

This class provides for an implementation of the JLANG::JAccessibleObjectIterator interface. It overwrites the method setObject of the JLANG::JAbstractObjectIterator interface so that the desired object is read from the file which may contain also other objects.

Definition at line 46 of file JDAQFileReader.hh.

Member Typedef Documentation

◆ pointer_type

template<class T>
typedef JObjectIterator<T>::pointer_type JLANG::JAbstractObjectIterator< T >::pointer_type
inherited

Definition at line 39 of file JAbstractObjectIterator.hh.

Member Function Documentation

◆ setObject()

template<class T >
virtual bool JSUPPORT::JDAQFileReader< T, true >::setObject ( T &  object)
inlinevirtual

Set object.

Parameters
objectreference to object to be set
Returns
true if set; else false

Reimplemented from JIO::JReaderObjectIterator< T >.

Definition at line 56 of file JDAQFileReader.hh.

57  {
58  using namespace std;
59  using namespace KM3NETDAQ;
60  using namespace JIO;
61 
62  for (JStreamReader& in = static_cast<JStreamReader&>(*this); in >> preamble; ) {
63 
64  if (preamble.getLength() < (int) getSizeof<JDAQPreamble>()) {
65 
66  this->setstate(ios::badbit);
67 
68  return false;
69 
70  } else if (preamble.getDataType() == getDataType<T>()) {
71 
72  buffer.resize(preamble.getLength());
73 
74  memcpy(buffer.data(), static_cast<JDAQAbstractPreamble*>(&preamble), getSizeof<JDAQPreamble>());
75 
78 
79  JByteArrayReader bin(buffer.data(), buffer.size());
80 
81  bin >> object;
82 
83  return (bool) in;
84 
85  } else {
86 
87  this->ignore((streamsize) (preamble.getLength() - getSizeof<JDAQPreamble>()));
88  }
89  }
90 
91  return false;
92  }

◆ open()

virtual void JLANG::JAccessibleBinaryInputStream::open ( const char *  file_name)
inlinevirtualinherited

Open file.

Parameters
file_namefile name

Reimplemented from JLANG::JAccessibleInputStream.

Definition at line 52 of file JAccessibleBinaryStream.hh.

53  {
54  std::ifstream::open(file_name, std::ios::binary);
55  }

◆ is_open()

virtual bool JLANG::JAccessibleInputStream::is_open ( ) const
inlinevirtualinherited

Check is file is open.

Returns
true if open; else false

Implements JLANG::JAccessible.

Definition at line 53 of file JAccessibleStream.hh.

54  {
55  return std::ifstream::is_open();
56  }

◆ close()

virtual void JLANG::JAccessibleInputStream::close ( )
inlinevirtualinherited

Close file.

Implements JLANG::JAccessible.

Definition at line 77 of file JAccessibleStream.hh.

78  {
80  }

◆ 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 error,
const int  value = -1 
)
inlinestaticinherited

Throw exception or return error.

Parameters
errorexception
valuereturn code
Returns
return code

Definition at line 50 of file JThrow.hh.

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

◆ getStatus()

virtual bool JIO::JStreamReader::getStatus ( ) const
inlinevirtualinherited

Status of reader.

Returns
status of this reader

Implements JLANG::JAbstractObjectStatus.

Definition at line 43 of file JStreamIO.hh.

44  {
45  return (bool) in;
46  }

◆ clear()

virtual void JIO::JStreamReader::clear ( )
inlinevirtualinherited

Clear status of reader.

Reimplemented from JIO::JReader.

Definition at line 52 of file JStreamIO.hh.

53  {
54  in.clear();
55  }

◆ read()

virtual int JIO::JStreamReader::read ( char *  buffer,
const int  length 
)
inlinevirtualinherited

Read byte array.

Parameters
bufferpointer to byte array
lengthnumber of bytes
Returns
number of bytes read

Implements JLANG::JBinaryInput.

Definition at line 65 of file JStreamIO.hh.

66  {
67  in.read(buffer, length);
68 
69  return in.gcount();
70  }

◆ operator>>() [1/15]

JReader& JIO::JReader::operator>> ( JSerialisable object)
inlineinherited

Read serialisable data object.

Parameters
objectserialisable data object
Returns
JReader

Definition at line 80 of file JSerialisable.hh.

81  {
82  return object.read(*this);
83  }

◆ operator>>() [2/15]

JReader& JIO::JReader::operator>> ( bool &  value)
inlineinherited

Definition at line 86 of file JSerialisable.hh.

86 { read((char*) &value, sizeof(bool)); return *this; }

◆ operator>>() [3/15]

JReader& JIO::JReader::operator>> ( char &  value)
inlineinherited

Definition at line 87 of file JSerialisable.hh.

87 { read((char*) &value, sizeof(char)); return *this; }

◆ operator>>() [4/15]

JReader& JIO::JReader::operator>> ( unsigned char &  value)
inlineinherited

Definition at line 88 of file JSerialisable.hh.

88 { read((char*) &value, sizeof(unsigned char)); return *this; }

◆ operator>>() [5/15]

JReader& JIO::JReader::operator>> ( short &  value)
inlineinherited

Definition at line 89 of file JSerialisable.hh.

89 { read((char*) &value, sizeof(short)); return *this; }

◆ operator>>() [6/15]

JReader& JIO::JReader::operator>> ( unsigned short &  value)
inlineinherited

Definition at line 90 of file JSerialisable.hh.

90 { read((char*) &value, sizeof(unsigned short)); return *this; }

◆ operator>>() [7/15]

JReader& JIO::JReader::operator>> ( int &  value)
inlineinherited

Definition at line 91 of file JSerialisable.hh.

91 { read((char*) &value, sizeof(int)); return *this; }

◆ operator>>() [8/15]

JReader& JIO::JReader::operator>> ( unsigned int &  value)
inlineinherited

Definition at line 92 of file JSerialisable.hh.

92 { read((char*) &value, sizeof(unsigned int)); return *this; }

◆ operator>>() [9/15]

JReader& JIO::JReader::operator>> ( long int &  value)
inlineinherited

Definition at line 93 of file JSerialisable.hh.

93 { read((char*) &value, sizeof(long int)); return *this; }

◆ operator>>() [10/15]

JReader& JIO::JReader::operator>> ( unsigned long int &  value)
inlineinherited

Definition at line 94 of file JSerialisable.hh.

94 { read((char*) &value, sizeof(unsigned long int)); return *this; }

◆ operator>>() [11/15]

JReader& JIO::JReader::operator>> ( long long int &  value)
inlineinherited

Definition at line 95 of file JSerialisable.hh.

95 { read((char*) &value, sizeof(long long int)); return *this; }

◆ operator>>() [12/15]

JReader& JIO::JReader::operator>> ( unsigned long long int &  value)
inlineinherited

Definition at line 96 of file JSerialisable.hh.

96 { read((char*) &value, sizeof(unsigned long long int)); return *this; }

◆ operator>>() [13/15]

JReader& JIO::JReader::operator>> ( float &  value)
inlineinherited

Definition at line 97 of file JSerialisable.hh.

97 { read((char*) &value, sizeof(float)); return *this; }

◆ operator>>() [14/15]

JReader& JIO::JReader::operator>> ( double &  value)
inlineinherited

Definition at line 98 of file JSerialisable.hh.

98 { read((char*) &value, sizeof(double)); return *this; }

◆ operator>>() [15/15]

JReader& JIO::JReader::operator>> ( long double &  value)
inlineinherited

Definition at line 99 of file JSerialisable.hh.

99 { read((char*) &value, sizeof(long double)); return *this; }

◆ load() [1/2]

JReader& JIO::JReader::load ( JSerialisable object)
inlineinherited

Read object.

Parameters
objectobject
Returns
this reader

Definition at line 108 of file JSerialisable.hh.

109  {
110  return object.read(*this);
111  }

◆ load() [2/2]

template<class T >
JReader& JIO::JReader::load ( T &  object)
inlineinherited

Read object.

Parameters
objectobject
Returns
this reader

Definition at line 121 of file JSerialisable.hh.

122  {
123  return *this >> object;
124  }

◆ operator bool()

JLANG::JAbstractObjectStatus::operator bool ( ) const
inlineinherited

Type conversion operator.

Returns
status of this object

Definition at line 33 of file JAbstractObjectStatus.hh.

34  {
35  return this->getStatus();
36  }

◆ operator!()

bool JLANG::JAbstractObjectStatus::operator! ( ) const
inlineinherited

Negated status of this object.

Returns
negated status of this object

Definition at line 44 of file JAbstractObjectStatus.hh.

45  {
46  return !(this->getStatus());
47  }

◆ hasNext()

template<class T>
virtual bool JLANG::JAbstractObjectIterator< T >::hasNext ( )
inlinevirtualinherited

Check availability of next element.

Returns
true if the iteration has more elements; else false

Implements JLANG::JObjectIterator< T >.

Definition at line 56 of file JAbstractObjectIterator.hh.

57  {
58  if (!has_next) {
59  has_next = this->setObject(object);
60  }
61 
62  return has_next;
63  }

◆ next()

template<class T>
virtual const pointer_type& JLANG::JAbstractObjectIterator< T >::next ( )
inlinevirtualinherited

Get next element.

Returns
pointer to element

Implements JLANG::JObjectIterator< T >.

Definition at line 71 of file JAbstractObjectIterator.hh.

72  {
73  if (has_next)
74  ps.reset(&this->object);
75  else
76  ps.reset(NULL);
77 
78  has_next = false;
79 
80  return ps;
81  }

◆ skip()

template<class T>
virtual skip_type JLANG::JObjectIterator< T >::skip ( const skip_type  ns)
inlinevirtualinherited

Member Data Documentation

◆ preamble

template<class T >
JDAQPreamble JSUPPORT::JDAQFileReader< T, true >::preamble
mutableprivate

Definition at line 95 of file JDAQFileReader.hh.

◆ buffer

template<class T >
std::vector<char> JSUPPORT::JDAQFileReader< T, true >::buffer
mutableprivate

Definition at line 96 of file JDAQFileReader.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.

◆ in

std::istream& JIO::JStreamReader::in
protectedinherited

Definition at line 73 of file JStreamIO.hh.

◆ object

template<class T>
T JLANG::JAbstractObjectIterator< T >::object
protectedinherited

object

Definition at line 34 of file JAbstractObjectIterator.hh.

◆ has_next

template<class T>
bool JLANG::JAbstractObjectIterator< T >::has_next
protectedinherited

status

Definition at line 35 of file JAbstractObjectIterator.hh.

◆ ps

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

Definition at line 84 of file JAbstractObjectIterator.hh.


The documentation for this class was generated from the following file:
JLANG::JAbstractObjectIterator::object
T object
object
Definition: JAbstractObjectIterator.hh:34
JEEP::close
void close(std::istream *pf)
Close file.
Definition: JeepToolkit.hh:342
JLANG::skip_type
unsigned int skip_type
Type definition for number of objects to skip.
Definition: JObjectIterator.hh:25
JSUPPORT::JDAQFileReader< T, true >::buffer
std::vector< char > buffer
Definition: JDAQFileReader.hh:96
JLANG::JObjectIterator::hasNext
virtual bool hasNext()=0
Check availability of next element.
KM3NETDAQ::JDAQAbstractPreamble::getLength
int getLength() const
Get length.
Definition: JDAQAbstractPreamble.hh:49
JSUPPORT::JDAQFileReader< T, true >::preamble
JDAQPreamble preamble
Definition: JDAQFileReader.hh:95
JIO::JByteArrayReader
Byte array binary input.
Definition: JByteArrayIO.hh:25
KM3NETDAQ::JDAQAbstractPreamble::getDataType
int getDataType() const
Get data type.
Definition: JDAQAbstractPreamble.hh:60
JLANG::JPointer::reset
virtual void reset()
Reset pointer.
Definition: JPointer.hh:84
JLANG::JBinaryInput::read
virtual int read(char *buffer, const int length)=0
Read byte array.
JLANG::JAbstractObjectIterator::has_next
bool has_next
status
Definition: JAbstractObjectIterator.hh:35
JEEP::open
T * open(const std::string &file_name)
Open file.
Definition: JeepToolkit.hh:302
JLANG::JAbstractObjectIterator::ps
pointer_type ps
Definition: JAbstractObjectIterator.hh:84
JIO::JStreamReader
Binary input based on std::istream.
Definition: JStreamIO.hh:24
std
Definition: jaanetDictionary.h:36
KM3NETDAQ
KM3NeT DAQ data structures and auxiliaries.
Definition: DataQueue.cc:39
JIO
Auxiliary classes and methods for binary I/O.
Definition: JBinaryFileReader.hh:17
JLANG::JAbstractObjectIterator::setObject
virtual bool setObject(T &object)=0
Set object.
JLANG::JThrow< JAccessible >::do_throw
static bool do_throw
throw option
Definition: JThrow.hh:28
JIO::JReaderObjectIterator::in
JReader & in
Definition: JReaderObjectIterator.hh:52
JLANG::JException::what
virtual const char * what() const
Get error message.
Definition: JException.hh:48
KM3NETDAQ::getSizeof< JDAQPreamble >
size_t getSizeof< JDAQPreamble >()
Get size of type.
Definition: JDAQPreambleIO.hh:19
JLANG::JAbstractObjectStatus::getStatus
virtual bool getStatus() const =0
Get status of object.
JIO::JStreamReader::in
std::istream & in
Definition: JStreamIO.hh:73
JLANG::JObjectIterator::next
virtual const pointer_type & next()=0
Get next element.