Jpp  master_rocky-43-ge265d140c
the software that should make you happy
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | Private Member Functions | List of all members
JSUPPORT::JAutoTreeWriter< JKey_t > Class Template Reference

Auxiliary class to copy input data to corresponding TTree. More...

#include <JAutoTreeWriter.hh>

Inheritance diagram for JSUPPORT::JAutoTreeWriter< JKey_t >:
JTOOLS::JAutoMap< JKey_t, JValue_t > JROOT::JRootOutputFile std::map< JKey_t, JValue_t > JROOT::JRootFile JLANG::JAccessible JLANG::JStorage< JClass_t, JMemory_t > JLANG::JThrow< JAccessible > JLANG::JPointer< JClass_t > JLANG::JNew< JClass_t > JLANG::JAbstractPointer< JClass_t > JLANG::JEquals< JAbstractPointer< JClass_t > >

Classes

struct  JElement_t
 Auxiliary class for element insertion. More...
 

Public Types

typedef JAutoMap< JKey_t, JTreeCopyWriterInterface * >::map_type map_type
 
typedef JAutoMap< JKey_t, JTreeCopyWriterInterface * >::value_type value_type
 
typedef map_type::const_iterator const_iterator
 
typedef map_type::iterator iterator
 
typedef map_type::const_reverse_iterator const_reverse_iterator
 
typedef map_type::reverse_iterator reverse_iterator
 
typedef JPointer< JClass_t > pointer_type
 
typedef JMemory_t< JClass_t > memory_type
 

Public Member Functions

 JAutoTreeWriter ()
 Default constrtuctor. More...
 
template<class T >
 JAutoTreeWriter (JType< T > type)
 Constructor. More...
 
template<class T >
void insert ()
 Insert (list of) data type(s). More...
 
virtual void open (const char *file_name) override
 Open file. More...
 
virtual void close () override
 Close file. More...
 
JNET::JTag getKey (JLANG::JType< T > type)
 Get key for given DAQ data type. More...
 
int getKey (JLANG::JType< T > type)
 Get key for given DAQ data type. More...
 
template<class T , class JElement_t >
void insert (const JAutomate< JElement_t > &automate)
 Insert list of data types. More...
 
TFile * getFile () const
 Get file. More...
 
virtual bool is_open () const override
 Check is file is open. More...
 
virtual void reset () override
 Reset pointer. More...
 
virtual void reset () override
 Reset pointer. More...
 
template<class T >
void reset (const JPointer< T > &pointer)
 Reset pointer. More...
 
template<class T >
void reset (const JPointer< T > &pointer)
 Reset pointer. More...
 
void reset (JClass_t *p)
 Reset pointer. More...
 
void recreate ()
 Recreate object in memory. More...
 
void create ()
 Create object in memory. More...
 
void create (const unsigned int size)
 Create array of objects in memory. More...
 
virtual JClass_t * get () const override
 Get pointer. More...
 
virtual void set (JClass_t *p) override
 Set pointer. More...
 
template<class T >
void set (const JPointer< T > &pointer)
 Set pointer. More...
 
JClass_t *const & getReference () const
 Get rereference to internal pointer. More...
 
JClass_t *& getReference ()
 Get rereference to internal pointer. More...
 
virtual bool equals (const JAbstractPointer &object) const
 Equals. More...
 
bool is_valid () const
 Check validity of pointer. More...
 
JClass_t * operator-> () const
 Smart pointer operator. More...
 
 operator JClass_t * () const
 Type conversion operator. More...
 

Static Public Member Functions

template<class T >
static JKey_t getKey (JType< T > type)
 Get key. More...
 
template<class T >
static value_type getAutoElement (JType< T > type)
 Creation of a map element for given data type. More...
 
static void Throw (const bool option)
 Enable/disable throw option. More...
 
static int Throw (const JException_t &error, const int value=-1)
 Throw exception or return error. More...
 
static void release (JClass_t *p)
 Release memory. More...
 

Protected Member Functions

template<class T , class JElement_t >
void insert (JType< T > type, const JAutomate< JElement_t > &automate)
 Insertion of single data type. More...
 
template<class JHead_t , class JTail_t , class JElement_t >
void insert (JType< JTypeList< JHead_t, JTail_t > > typelist, const JAutomate< JElement_t > &automate)
 Recursive insertion of data types. More...
 
template<class JElement_t >
void insert (JType< JNullType > type, const JAutomate< JElement_t > &automate)
 Template specialisation to terminate insertion of data types. More...
 
void release ()
 Release memory. More...
 

Protected Attributes

JClass_t * __p
 pointer to object More...
 

Static Protected Attributes

static bool do_throw
 throw option More...
 

Private Member Functions

void do_open (const char *file_name)
 Open file. More...
 
void do_close ()
 Close file. More...
 

Detailed Description

template<class JKey_t>
class JSUPPORT::JAutoTreeWriter< JKey_t >

Auxiliary class to copy input data to corresponding TTree.

This class derives from JROOT::JRootOutputFile. It re-implements the methods open and close of the underlying JLANG::JAccessible class so that each TTree is properly attached to and detached from the corresponding TDirectory, respectively.

Definition at line 33 of file JAutoTreeWriter.hh.

Member Typedef Documentation

◆ map_type

template<class JKey_t >
typedef JAutoMap<JKey_t, JTreeCopyWriterInterface*>::map_type JSUPPORT::JAutoTreeWriter< JKey_t >::map_type

Definition at line 39 of file JAutoTreeWriter.hh.

◆ value_type

template<class JKey_t >
typedef JAutoMap<JKey_t, JTreeCopyWriterInterface*>::value_type JSUPPORT::JAutoTreeWriter< JKey_t >::value_type

Definition at line 40 of file JAutoTreeWriter.hh.

◆ const_iterator

template<class JKey_t >
typedef map_type::const_iterator JSUPPORT::JAutoTreeWriter< JKey_t >::const_iterator

Definition at line 42 of file JAutoTreeWriter.hh.

◆ iterator

template<class JKey_t >
typedef map_type::iterator JSUPPORT::JAutoTreeWriter< JKey_t >::iterator

Definition at line 43 of file JAutoTreeWriter.hh.

◆ const_reverse_iterator

template<class JKey_t >
typedef map_type::const_reverse_iterator JSUPPORT::JAutoTreeWriter< JKey_t >::const_reverse_iterator

Definition at line 44 of file JAutoTreeWriter.hh.

◆ reverse_iterator

template<class JKey_t >
typedef map_type::reverse_iterator JSUPPORT::JAutoTreeWriter< JKey_t >::reverse_iterator

Definition at line 45 of file JAutoTreeWriter.hh.

◆ pointer_type

template<class JClass_t , template< class > class JMemory_t = JNew>
typedef JPointer<JClass_t> JLANG::JStorage< JClass_t, JMemory_t >::pointer_type
inherited

Definition at line 32 of file JStorage.hh.

◆ memory_type

template<class JClass_t , template< class > class JMemory_t = JNew>
typedef JMemory_t<JClass_t> JLANG::JStorage< JClass_t, JMemory_t >::memory_type
inherited

Definition at line 33 of file JStorage.hh.

Constructor & Destructor Documentation

◆ JAutoTreeWriter() [1/2]

template<class JKey_t >
JSUPPORT::JAutoTreeWriter< JKey_t >::JAutoTreeWriter ( )
inline

Default constrtuctor.

Definition at line 53 of file JAutoTreeWriter.hh.

54  {}

◆ JAutoTreeWriter() [2/2]

template<class JKey_t >
template<class T >
JSUPPORT::JAutoTreeWriter< JKey_t >::JAutoTreeWriter ( JType< T >  type)
inline

Constructor.

Parameters
typedata type

Definition at line 63 of file JAutoTreeWriter.hh.

64  {
65  this->template insert<T>();
66  }

Member Function Documentation

◆ getKey() [1/3]

template<class JKey_t >
template<class T >
static JKey_t JSUPPORT::JAutoTreeWriter< JKey_t >::getKey ( JType< T >  type)
static

Get key.

This method should be overloaded for the requested data types.

Parameters
typedata type
Returns
key

◆ insert() [1/5]

template<class JKey_t >
template<class T >
void JSUPPORT::JAutoTreeWriter< JKey_t >::insert ( )
inline

Insert (list of) data type(s).

Definition at line 85 of file JAutoTreeWriter.hh.

86  {
87  insert<T>(JTOOLS::JAutomate<JElement_t>());
88  }
Auxiliary class for automatic element creation.
Definition: JAutoMap.hh:46

◆ open()

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

Open file.

Parameters
file_namefile name

Reimplemented from JROOT::JRootOutputFile.

Definition at line 96 of file JAutoTreeWriter.hh.

97  {
98  JRootOutputFile::open(file_name);
99 
100  if (is_open()) {
101  for (iterator i = this->begin(); i != this->end(); ++i) {
102  i->second->SetDirectory(getFile());
103  }
104  }
105  }
TFile * getFile() const
Get file.
Definition: JRootFile.hh:66
virtual bool is_open() const override
Check is file is open.
Definition: JRootFile.hh:77
virtual void open(const char *file_name) override
Open file.
Definition: JRootFile.hh:237
map_type::iterator iterator

◆ close()

template<class JKey_t >
virtual void JSUPPORT::JAutoTreeWriter< JKey_t >::close ( )
inlineoverridevirtual

Close file.

Reimplemented from JROOT::JRootOutputFile.

Definition at line 111 of file JAutoTreeWriter.hh.

112  {
113  // Write objects in memory.
114 
115  if (is_open()) {
116  getFile()->Write();
117  }
118 
119  // Detach TTree from TDirectory to avoid deletion of TTree.
120 
121  for (iterator i = this->begin(); i != this->end(); ++i) {
122  i->second->SetDirectory(0);
123  }
124 
125  // Close file.
126 
127  if (is_open()) {
128  getFile()->Close();
129  }
130 
131  reset();
132 
133  // Reset TTree for next run.
134 
135  for (iterator i = this->begin(); i != this->end(); ++i) {
136  i->second->Reset();
137  }
138  }
virtual void reset() override
Reset pointer.
Definition: JStorage.hh:42

◆ getKey() [2/3]

Get key for given DAQ data type.

Parameters
typedata type
Returns
map element

Definition at line 48 of file JDataWriter.cc.

49  {
50  return getTag<T>();
51  }

◆ getKey() [3/3]

int JSUPPORT::JAutoTreeWriter< int >::getKey ( JLANG::JType< T >  type)

Get key for given DAQ data type.

Parameters
typedata type
Returns
map element

Definition at line 37 of file JRoot.cc.

38  {
39  return KM3NETDAQ::getDataType<T>();
40  }

◆ getAutoElement()

template<class JKey_t , class JValue_t >
template<class T >
static value_type JTOOLS::JAutoMap< JKey_t, JValue_t >::getAutoElement ( JType< T >  type)
staticinherited

Creation of a map element for given data type.

This method should be overloaded for the requested data types if the method insert() is used without argument.

Parameters
typedata type
Returns
element

◆ insert() [2/5]

template<class JKey_t , class JValue_t >
template<class T , class JElement_t >
void JTOOLS::JAutoMap< JKey_t, JValue_t >::insert ( const JAutomate< JElement_t > &  automate)
inlineinherited

Insert list of data types.

Parameters
automatetype defined element

Definition at line 137 of file JAutoMap.hh.

138  {
139  insert(JType<T>(), automate);
140  }
void insert()
Insert list of data types.
Definition: JAutoMap.hh:125

◆ insert() [3/5]

template<class JKey_t , class JValue_t >
template<class T , class JElement_t >
void JTOOLS::JAutoMap< JKey_t, JValue_t >::insert ( JType< T >  type,
const JAutomate< JElement_t > &  automate 
)
inlineprotectedinherited

Insertion of single data type.

Parameters
typedata type
automateelement automate by data type

Definition at line 150 of file JAutoMap.hh.

152  {
153  map_type::insert(automate.getElement(type));
154  }
static JElement_t getElement(JType< T > type)
Get element.
Definition: JAutoMap.hh:54

◆ insert() [4/5]

template<class JKey_t , class JValue_t >
template<class JHead_t , class JTail_t , class JElement_t >
void JTOOLS::JAutoMap< JKey_t, JValue_t >::insert ( JType< JTypeList< JHead_t, JTail_t > >  typelist,
const JAutomate< JElement_t > &  automate 
)
inlineprotectedinherited

Recursive insertion of data types.

Parameters
typelisttype list
automateelement automate by data type

Definition at line 164 of file JAutoMap.hh.

166  {
167  insert(JType<JHead_t>(), automate);
168  insert(JType<JTail_t>(), automate);
169  }

◆ insert() [5/5]

template<class JKey_t , class JValue_t >
template<class JElement_t >
void JTOOLS::JAutoMap< JKey_t, JValue_t >::insert ( JType< JNullType type,
const JAutomate< JElement_t > &  automate 
)
inlineprotectedinherited

Template specialisation to terminate insertion of data types.

Parameters
typenull type
automateelement automate by data type

Definition at line 179 of file JAutoMap.hh.

181  {}

◆ do_open()

void JROOT::JRootOutputFile::do_open ( const char *  file_name)
inlineprivateinherited

Open file.

The file is not opened when a file exists with the given name.

Parameters
file_namefile name

Definition at line 260 of file JRootFile.hh.

261  {
262  set(TFile::Open(file_name, "CREATE"));
263 
264  if (!is_open()) {
265  Throw(MAKE_EXCEPTION(JFileOpenException, "Error opening file " << file_name));
266  }
267  }
#define MAKE_EXCEPTION(JException_t, A)
Make exception.
Definition: JException.hh:703
virtual void set(JClass_t *p) override
Set pointer.
Definition: JPointer.hh:75
static void Throw(const bool option)
Enable/disable throw option.
Definition: JThrow.hh:37

◆ do_close()

void JROOT::JRootOutputFile::do_close ( )
inlineprivateinherited

Close file.

This method calls the TFile::Write method before closing the file.

Definition at line 274 of file JRootFile.hh.

275  {
276  if (getFile() != NULL && getFile()->IsOpen()) {
277  getFile()->Write();
278  getFile()->Close();
279  }
280 
281  reset();
282  }

◆ getFile()

TFile* JROOT::JRootFile::getFile ( ) const
inlineinherited

Get file.

Returns
pointer to file

Definition at line 66 of file JRootFile.hh.

67  {
68  return get();
69  }
virtual JClass_t * get() const override
Get pointer.
Definition: JPointer.hh:64

◆ is_open()

virtual bool JROOT::JRootFile::is_open ( ) const
inlineoverridevirtualinherited

Check is file is open.

Returns
true if open; else false

Implements JLANG::JAccessible.

Definition at line 77 of file JRootFile.hh.

78  {
79  return (getFile() != NULL && getFile()->IsOpen());
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  }
static bool do_throw
throw option
Definition: JThrow.hh:28

◆ 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  }
Definition: JSTDTypes.hh:14

◆ reset() [1/5]

template<class JClass_t , template< class > class JMemory_t = JNew>
virtual void JLANG::JStorage< JClass_t, JMemory_t >::reset ( )
inlineoverridevirtualinherited

◆ reset() [2/5]

template<class JClass_t , template< class > class JMemory_t = JNew>
virtual void JLANG::JPointer< JClass_t >::reset
inlineoverridevirtualinherited

◆ reset() [3/5]

template<class JClass_t , template< class > class JMemory_t = JNew>
template<class T >
void JLANG::JPointer< JClass_t >::reset ( class T  )
inlineinherited

Reset pointer.

Parameters
pointerpointer to object

Definition at line 108 of file JPointer.hh.

109  {
110  this->reset(pointer.get());
111  }

◆ reset() [4/5]

template<class JClass_t >
template<class T >
void JLANG::JPointer< JClass_t >::reset ( const JPointer< T > &  pointer)
inlineinherited

Reset pointer.

Parameters
pointerpointer to object

Definition at line 108 of file JPointer.hh.

109  {
110  this->reset(pointer.get());
111  }

◆ reset() [5/5]

template<class JClass_t >
void JLANG::JAbstractPointer< JClass_t >::reset ( JClass_t *  p)
inlineinherited

Reset pointer.

Parameters
ppointer to object

Definition at line 94 of file JAbstractPointer.hh.

95  {
96  if (this->get() != p) {
97 
98  this->reset();
99 
100  if (p != NULL) {
101  this->set(p);
102  }
103  }
104  }
virtual void set(JClass_t *p)=0
Set pointer.
virtual void reset()=0
Reset pointer.
virtual JClass_t * get() const =0
Get pointer.

◆ recreate()

template<class JClass_t , template< class > class JMemory_t = JNew>
void JLANG::JStorage< JClass_t, JMemory_t >::recreate ( )
inlineinherited

Recreate object in memory.

A new object is created if no memory is allocated yet, else the previously created object is maintained.

Definition at line 57 of file JStorage.hh.

58  {
59  if (!this->is_valid()) {
60  this->set(memory_type::create());
61  }
62  }

◆ create() [1/2]

template<class JClass_t , template< class > class JMemory_t = JNew>
void JLANG::JStorage< JClass_t, JMemory_t >::create ( )
inlineinherited

Create object in memory.

The memory allocated by a previously created object will be released.

Definition at line 69 of file JStorage.hh.

70  {
71  this->reset(memory_type::create());
72  }

◆ create() [2/2]

template<class JClass_t , template< class > class JMemory_t = JNew>
void JLANG::JStorage< JClass_t, JMemory_t >::create ( const unsigned int  size)
inlineinherited

Create array of objects in memory.

The memory allocated by previously created objects will be released.

Parameters
sizenumber of elements

Definition at line 81 of file JStorage.hh.

82  {
83  this->reset(memory_type::create(size));
84  }

◆ release() [1/2]

template<class JClass_t , template< class > class JMemory_t = JNew>
void JLANG::JStorage< JClass_t, JMemory_t >::release ( )
inlineprotectedinherited

Release memory.

Definition at line 91 of file JStorage.hh.

92  {
93  memory_type::release(this->get());
94  }

◆ release() [2/2]

template<class JClass_t >
static void JLANG::JNew< JClass_t >::release ( JClass_t *  p)
inlinestaticinherited

Release memory.

Parameters
ppointer to data

Definition at line 41 of file JMemory.hh.

42  {
43  delete p;
44  }

◆ get()

template<class JClass_t >
virtual JClass_t* JLANG::JPointer< JClass_t >::get ( ) const
inlineoverridevirtualinherited

◆ set() [1/2]

template<class JClass_t >
virtual void JLANG::JPointer< JClass_t >::set ( JClass_t *  p)
inlineoverridevirtualinherited

Set pointer.

Parameters
ppointer to object

Implements JLANG::JAbstractPointer< JClass_t >.

Reimplemented in JLANG::JSharedPointer< JClass_t, JMemory_t >.

Definition at line 75 of file JPointer.hh.

76  {
77  this->__p = p;
78  }

◆ set() [2/2]

template<class JClass_t >
template<class T >
void JLANG::JPointer< JClass_t >::set ( const JPointer< T > &  pointer)
inlineinherited

Set pointer.

Parameters
pointerpointer to object

Definition at line 96 of file JPointer.hh.

97  {
98  this->set(pointer.get());
99  }

◆ getReference() [1/2]

template<class JClass_t >
JClass_t* const& JLANG::JPointer< JClass_t >::getReference ( ) const
inlineinherited

Get rereference to internal pointer.

Returns
reference to internal pointer

Definition at line 119 of file JPointer.hh.

120  {
121  return __p;
122  }

◆ getReference() [2/2]

template<class JClass_t >
JClass_t* & JLANG::JPointer< JClass_t >::getReference ( )
inlineinherited

Get rereference to internal pointer.

Returns
reference to internal pointer

Definition at line 130 of file JPointer.hh.

131  {
132  return __p;
133  }

◆ equals()

template<class JClass_t >
virtual bool JLANG::JAbstractPointer< JClass_t >::equals ( const JAbstractPointer< JClass_t > &  object) const
inlinevirtualinherited

Equals.

The equality is evaluated by comparison of the internal pointers.

Parameters
objectabstract pointer
Returns
true if equals; else false

Definition at line 50 of file JAbstractPointer.hh.

51  {
52  return this->get() == object.get();
53  }

◆ is_valid()

template<class JClass_t >
bool JLANG::JAbstractPointer< JClass_t >::is_valid ( ) const
inlineinherited

Check validity of pointer.

Returns
true if pointer not null; else false

Definition at line 83 of file JAbstractPointer.hh.

84  {
85  return this->get() != NULL;
86  }

◆ operator->()

template<class JClass_t >
JClass_t* JLANG::JAbstractPointer< JClass_t >::operator-> ( ) const
inlineinherited

Smart pointer operator.

Returns
pointer to object

Definition at line 112 of file JAbstractPointer.hh.

113  {
114  if (!is_valid())
115  THROW(JNullPointerException, "JAbstractPointer::operator->()");
116  else
117  return this->get();
118  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
Exception for null pointer operation.
Definition: JException.hh:234

◆ operator JClass_t *()

template<class JClass_t >
JLANG::JAbstractPointer< JClass_t >::operator JClass_t * ( ) const
inlineinherited

Type conversion operator.

Returns
pointer to object

Definition at line 126 of file JAbstractPointer.hh.

127  {
128  return this->get();
129  }

Member Data Documentation

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

◆ __p

template<class JClass_t >
JClass_t* JLANG::JPointer< JClass_t >::__p
protectedinherited

pointer to object

Definition at line 136 of file JPointer.hh.


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