Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Protected Attributes | Friends | List of all members
JGIZMO::JManager< JKey_t, JValue_t > Class Template Reference

Auxiliary class to manage set of compatible ROOT objects (e.g. More...

#include <JManager.hh>

Inheritance diagram for JGIZMO::JManager< JKey_t, JValue_t >:
JLANG::JPointer< JClass_t > std::map< JKey_t, JValue_t * > JLANG::JAbstractPointer< JClass_t > JLANG::JEquals< JAbstractPointer< JClass_t > >

Public Member Functions

 JManager (JValue_t *master, char wildcard= '%', std::ios::fmtflags format=std::ios::fmtflags())
 Constructor. More...
 
JValue_t * operator[] (JKey_t key)
 Get pointer to object for given key. More...
 
void Write (TDirectory &out, const bool wm=false)
 Write objects to file. More...
 
void Write (const char *file_name, const bool wm=false)
 Write objects to file. More...
 
virtual JClass_t * get () const
 Get pointer. More...
 
virtual void set (JClass_t *p)
 Set pointer. More...
 
template<class T >
void set (const JPointer< T > &pointer)
 Set pointer. More...
 
virtual void reset ()
 Reset pointer. More...
 
template<class T >
void reset (const JPointer< T > &pointer)
 Reset pointer. More...
 
void reset (JClass_t *p)
 Reset 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...
 

Protected Attributes

char wc
 
std::ios::fmtflags fmt
 
JClass_t * __p
 pointer to object More...
 

Friends

TFile & operator<< (TFile &file, JManager &object)
 Write manager to file. More...
 

Detailed Description

template<class JKey_t, class JValue_t = TObject>
class JGIZMO::JManager< JKey_t, JValue_t >

Auxiliary class to manage set of compatible ROOT objects (e.g.

histograms) using unique keys. For each use of the map operator [], it is checked whether the corresponding client object exists. If the corresponding client object does not yet exists, a clone is made of the master object (i.e. the 'client'). The name of the newly created object is derived from the name of the master object by replacing the wild card character with the value of the key according the optional format specifier.

Definition at line 38 of file JManager.hh.

Constructor & Destructor Documentation

template<class JKey_t, class JValue_t = TObject>
JGIZMO::JManager< JKey_t, JValue_t >::JManager ( JValue_t *  master,
char  wildcard = '%',
std::ios::fmtflags  format = std::ios::fmtflags() 
)
inline

Constructor.

Note that the manager owns the master object pointed to. For saving the objects to file, use method Write (all objects are detached from the current ROOT directory).

Parameters
mastermaster object
wildcardwild card character
formatformat specifier for replacement of wildcard character by value of key

Definition at line 54 of file JManager.hh.

56  :
57  JPointer<JValue_t>(master),
59  wc (wildcard),
60  fmt(format)
61  {
62  using namespace std;
63  using namespace JLANG;
64 
65  if (master == NULL) {
66  THROW(JException, "JManager: No master object.");
67  }
68 
69  master->SetDirectory(0);
70 
71  if (string(master->GetName()).find(wc) == string::npos) {
72  THROW(JException, "JManager: Missing wildcard " << master->GetName() << ' ' << wc);
73  }
74  }
General exception.
Definition: JException.hh:40
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:633
std::ios::fmtflags fmt
Definition: JManager.hh:169

Member Function Documentation

template<class JKey_t, class JValue_t = TObject>
JValue_t* JGIZMO::JManager< JKey_t, JValue_t >::operator[] ( JKey_t  key)
inline

Get pointer to object for given key.

Parameters
keykey
Returns
pointer to client object

Definition at line 83 of file JManager.hh.

84  {
85  using namespace std;
86 
87  typename map<JKey_t, JValue_t*>::iterator i = this->find(key);
88 
89  if (i == this->end()) {
90 
91  string buffer = this->get()->GetName();
92  string::size_type ipos = buffer.find(wc);
93 
94  ostringstream os;
95 
96  os.setf(fmt);
97 
98  os << key;
99 
100  buffer.replace(ipos, 1, os.str());
101 
102  JValue_t* p = (JValue_t*) this->get()->Clone(buffer.c_str());
103 
104  p->Reset();
105  p->SetDirectory(0);
106 
107  this->insert(make_pair(key,p));
108 
109  return p;
110 
111  } else {
112 
113  return i->second;
114  }
115  }
std::ios::fmtflags fmt
Definition: JManager.hh:169
template<class JKey_t, class JValue_t = TObject>
void JGIZMO::JManager< JKey_t, JValue_t >::Write ( TDirectory &  out,
const bool  wm = false 
)
inline

Write objects to file.

Parameters
outoutput file or directory
wmwrite master

Definition at line 124 of file JManager.hh.

125  {
126  for (typename std::map<JKey_t, JValue_t*>::iterator i = this->begin(); i != this->end(); ++i) {
127  out.WriteTObject(i->second);
128  }
129 
130  if (wm) {
131  out.WriteTObject(this->get());
132  }
133  }
template<class JKey_t, class JValue_t = TObject>
void JGIZMO::JManager< JKey_t, JValue_t >::Write ( const char *  file_name,
const bool  wm = false 
)
inline

Write objects to file.

Parameters
file_namefile name
wmwrite master

Definition at line 142 of file JManager.hh.

143  {
144  TFile out(file_name, "RECREATE");
145 
146  this->Write(out, wm) ;
147 
148  out.Write();
149  out.Close();
150  }
void Write(TDirectory &out, const bool wm=false)
Write objects to file.
Definition: JManager.hh:124
template<class JClass_t>
virtual JClass_t* JLANG::JPointer< JClass_t >::get ( ) const
inlinevirtualinherited
template<class JClass_t>
virtual void JLANG::JPointer< JClass_t >::set ( JClass_t *  p)
inlinevirtualinherited

Set pointer.

Parameters
ppointer to object

Implements JLANG::JAbstractPointer< JClass_t >.

Reimplemented in JLANG::JSharedPointer< JClass_t, JMemory_t >, JLANG::JSharedPointer< JPHYSICS::JRadiation >, JLANG::JSharedPointer< JAccessibleObjectIterator< KM3NETDAQ::KM3NETDAQ::JDAQEvent > >, JLANG::JSharedPointer< JObjectIterator< T > >, JLANG::JSharedPointer< JFIT::JMEstimator >, JLANG::JSharedPointer< JAbstractAutoPointer< JBase_t > >, JLANG::JSharedPointer< JAccessibleObjectIterator< JNullType > >, JLANG::JSharedPointer< match_type >, JLANG::JSharedPointer< JAccessibleObjectIterator< JDAQSummaryslice > >, JLANG::JSharedPointer< JAccessibleObjectIterator< JTypeList< JDAQEvent, JTypelist_t > > >, JLANG::JSharedPointer< JAccessibleObjectIterator< JTail_t > >, JLANG::JSharedPointer< JLOGGER::JLogger >, JLANG::JSharedPointer< JAccessibleObjectIterator< T > >, JLANG::JSharedPointer< JParserElementInterface >, JLANG::JSharedPointer< const JDETECTOR::JModuleRouter >, JLANG::JSharedPointer< JExceptionHandler >, JLANG::JSharedPointer< JObjectOutput< JHead_t > >, JLANG::JSharedPointer< JAccessibleObjectIterator< JHead_t > >, JLANG::JSharedPointer< JRewindableObjectIterator< JTail_t > >, JLANG::JSharedPointer< JRewindableObjectIterator< JHead_t > >, JLANG::JSharedPointer< JObjectOutput< T > >, JLANG::JSharedPointer< JBase_t >, JLANG::JSharedPointer< JObjectOutput< JTail_t > >, JLANG::JSharedPointer< JPropertiesElementInterface >, JLANG::JSharedPointer< JRewindableObjectIterator< const T > >, JLANG::JSharedPointer< JRewindableObjectIterator< T > >, JLANG::JSharedPointer< JAccessibleObjectOutput< T > >, JLANG::JSharedPointer< JNET::JControlHost >, and JLANG::JSharedPointer< JTOOLS::JMultiMapTransformer >.

Definition at line 75 of file JPointer.hh.

76  {
77  this->__p = p;
78  }
JClass_t * __p
pointer to object
Definition: JPointer.hh:136
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  }
virtual JClass_t * get() const
Get pointer.
Definition: JPointer.hh:64
virtual void set(JClass_t *p)
Set pointer.
Definition: JPointer.hh:75
template<class JClass_t>
virtual void JLANG::JPointer< JClass_t >::reset ( )
inlinevirtualinherited

Reset pointer.

Implements JLANG::JAbstractPointer< JClass_t >.

Reimplemented in JLANG::JSharedPointer< JClass_t, JMemory_t >, JLANG::JSharedPointer< JPHYSICS::JRadiation >, JLANG::JSharedPointer< JAccessibleObjectIterator< KM3NETDAQ::KM3NETDAQ::JDAQEvent > >, JLANG::JSharedPointer< JObjectIterator< T > >, JLANG::JSharedPointer< JFIT::JMEstimator >, JLANG::JSharedPointer< JAbstractAutoPointer< JBase_t > >, JLANG::JSharedPointer< JAccessibleObjectIterator< JNullType > >, JLANG::JSharedPointer< match_type >, JLANG::JSharedPointer< JAccessibleObjectIterator< JDAQSummaryslice > >, JLANG::JSharedPointer< JAccessibleObjectIterator< JTypeList< JDAQEvent, JTypelist_t > > >, JLANG::JSharedPointer< JAccessibleObjectIterator< JTail_t > >, JLANG::JSharedPointer< JLOGGER::JLogger >, JLANG::JSharedPointer< JAccessibleObjectIterator< T > >, JLANG::JSharedPointer< JParserElementInterface >, JLANG::JSharedPointer< const JDETECTOR::JModuleRouter >, JLANG::JSharedPointer< JExceptionHandler >, JLANG::JSharedPointer< JObjectOutput< JHead_t > >, JLANG::JSharedPointer< JAccessibleObjectIterator< JHead_t > >, JLANG::JSharedPointer< JRewindableObjectIterator< JTail_t > >, JLANG::JSharedPointer< JRewindableObjectIterator< JHead_t > >, JLANG::JSharedPointer< JObjectOutput< T > >, JLANG::JSharedPointer< JBase_t >, JLANG::JSharedPointer< JObjectOutput< JTail_t > >, JLANG::JSharedPointer< JPropertiesElementInterface >, JLANG::JSharedPointer< JRewindableObjectIterator< const T > >, JLANG::JSharedPointer< JRewindableObjectIterator< T > >, JLANG::JSharedPointer< JAccessibleObjectOutput< T > >, JLANG::JSharedPointer< JNET::JControlHost >, JLANG::JSharedPointer< JTOOLS::JMultiMapTransformer >, JLANG::JStorage< JClass_t, JMemory_t >, JLANG::JStorage< JDETECTOR::JK40Simulator, JNew >, JLANG::JStorage< JAccessibleObjectIterator< JTail_t >, JNew >, JLANG::JStorage< match_type, JNew >, JLANG::JStorage< JObjectOutput< JTail_t >, JNew >, JLANG::JStorage< JAccessibleObjectIterator< JNullType >, JNew >, JLANG::JStorage< JAccessibleObjectIterator< KM3NETDAQ::KM3NETDAQ::JDAQEvent >, JNew >, JLANG::JStorage< JDETECTOR::JCLBDefaultSimulatorInterface::JStateMachine, JNew >, JLANG::JStorage< JDETECTOR::JPMTSimulator, JNew >, JLANG::JStorage< JObjectIterator< T >, JNew >, JLANG::JStorage< JAccessibleObjectIterator< T >, JNew >, JLANG::JStorage< JRewindableObjectIterator< JTail_t >, JNew >, JLANG::JStorage< JTOOLS::JFunction1D, JNew >, JLANG::JStorage< JDETECTOR::JCLBSimulator, JNew >, JLANG::JStorage< JTOOLS::JMultiMapTransformer, JNew >, JLANG::JStorage< JRewindableObjectIterator< const T >, JNew >, JLANG::JStorage< JBase_t, JNew >, JLANG::JStorage< JParserElementInterface, JNew >, JLANG::JStorage< JFIT::JMEstimator, JNew >, JLANG::JStorage< JAbstractAutoPointer< JBase_t >, JNew >, JLANG::JStorage< JAccessibleObjectIterator< JHead_t >, JNew >, JLANG::JStorage< JPHYSICS::JRadiation, JNew >, JLANG::JStorage< JDETECTOR::JCLBDefaultSimulatorInterface::JTDC, JNew >, JLANG::JStorage< JLANG::JMultiPipe< T, N >, JNew >, JLANG::JStorage< JAccessibleObjectIterator< JDAQSummaryslice >, JNew >, JLANG::JStorage< JObjectOutput< JHead_t >, JNew >, JLANG::JStorage< JAccessibleObjectIterator< JTypeList< JDAQEvent, JTypelist_t > >, JNew >, JLANG::JStorage< JExceptionHandler, JNew >, JLANG::JStorage< TFile >, JLANG::JStorage< JRewindableObjectIterator< T >, JNew >, JLANG::JStorage< JPropertiesElementInterface, JNew >, JLANG::JStorage< JRewindableObjectIterator< JHead_t >, JNew >, JLANG::JStorage< const JDETECTOR::JModuleRouter, JNew >, JLANG::JStorage< JObjectOutput< T >, JNew >, JLANG::JStorage< JIO::JWriter, JNew >, JLANG::JStorage< JNET::JControlHost, JNew >, JLANG::JStorage< JAccessibleObjectOutput< T >, JNew >, JLANG::JStorage< JIO::JReader, JNew >, and JLANG::JStorage< JLOGGER::JLogger, JNew >.

Definition at line 84 of file JPointer.hh.

85  {
86  this->__p = NULL;
87  }
JClass_t * __p
pointer to object
Definition: JPointer.hh:136
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  }
virtual void reset()
Reset pointer.
Definition: JPointer.hh:84
virtual JClass_t * get() const
Get pointer.
Definition: JPointer.hh:64
template<class JClass_t>
void JLANG::JAbstractPointer< JClass_t >::reset ( JClass_t *  p)
inlineinherited

Reset pointer.

Parameters
ppointer to object

Definition at line 92 of file JAbstractPointer.hh.

93  {
94  if (this->get() != p) {
95 
96  this->reset();
97 
98  if (p != NULL) {
99  this->set(p);
100  }
101  }
102  }
virtual void reset()=0
Reset pointer.
virtual void set(JClass_t *p)=0
Set pointer.
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  }
JClass_t * __p
pointer to object
Definition: JPointer.hh:136
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  }
JClass_t * __p
pointer to object
Definition: JPointer.hh:136
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 48 of file JAbstractPointer.hh.

49  {
50  return this->get() == object.get();
51  }
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 81 of file JAbstractPointer.hh.

82  {
83  return this->get() != NULL;
84  }
template<class JClass_t>
JClass_t* JLANG::JAbstractPointer< JClass_t >::operator-> ( ) const
inlineinherited

Smart pointer operator.

Returns
pointer to object

Definition at line 110 of file JAbstractPointer.hh.

111  {
112  if (!is_valid())
113  throw JNullPointerException("JAbstractPointer::operator->()");
114  else
115  return this->get();
116  }
bool is_valid() const
Check validity of pointer.
Exception for null pointer operation.
Definition: JException.hh:198
template<class JClass_t>
JLANG::JAbstractPointer< JClass_t >::operator JClass_t * ( ) const
inlineinherited

Type conversion operator.

Returns
pointer to object

Definition at line 124 of file JAbstractPointer.hh.

125  {
126  return this->get();
127  }

Friends And Related Function Documentation

template<class JKey_t, class JValue_t = TObject>
TFile& operator<< ( TFile &  file,
JManager< JKey_t, JValue_t > &  object 
)
friend

Write manager to file.

Parameters
filefile
objectmanager
Returns
file

Definition at line 160 of file JManager.hh.

161  {
162  object.Write(file);
163 
164  return file;
165  }

Member Data Documentation

template<class JKey_t, class JValue_t = TObject>
char JGIZMO::JManager< JKey_t, JValue_t >::wc
protected

Definition at line 168 of file JManager.hh.

template<class JKey_t, class JValue_t = TObject>
std::ios::fmtflags JGIZMO::JManager< JKey_t, JValue_t >::fmt
protected

Definition at line 169 of file JManager.hh.

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: