Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
AAObject Struct Reference

AAObject is a base class for I/O-classes that adds the possibility to add 'user' information which will also be stored in the ROOT file. More...

#include <AAObject.hh>

Inheritance diagram for AAObject:
TObject Evt Trk JSIRENE::JTrk_t

Public Member Functions

int idx (const std::string &key) const
 Get index in user data of the item with given key.
 
bool haveusr (const std::string &key) const
 Check availability of user data of the item with given key.
 
int idxusr_checked (const std::string &key) const
 Get index in user data of the item with given key.
 
double getusr (const std::string &key) const
 Get user data item with given key.
 
void setusr (const std::string &key, double value)
 Set user data item with given key.
 
bool delusr (const std::string &key)
 Remove (first) user data item with given key.
 
void clearusr ()
 Clear user data.
 
void printusr (std::ostream &out=std::cout)
 Print user data (i.e.
 
 AAObject ()
 Default constructor.
 
 ~AAObject ()
 

Public Attributes

std::vector< double > usr
 user data
 
std::vector< std::string > usr_names
 user keys
 
TObjectany
 Pointer to "any" user data.
 

Detailed Description

AAObject is a base class for I/O-classes that adds the possibility to add 'user' information which will also be stored in the ROOT file.

Definition at line 18 of file AAObject.hh.

Constructor & Destructor Documentation

◆ AAObject()

AAObject::AAObject ( )
inline

Default constructor.

Definition at line 167 of file AAObject.hh.

167: any(NULL) {}
TObject * any
Pointer to "any" user data.
Definition AAObject.hh:171

◆ ~AAObject()

AAObject::~AAObject ( )
inline

Definition at line 168 of file AAObject.hh.

168{}

Member Function Documentation

◆ idx()

int AAObject::idx ( const std::string & key) const
inline

Get index in user data of the item with given key.

Parameters
keykey
Returns
index (-1 if key does not exists)

Definition at line 29 of file AAObject.hh.

30 {
31 auto i = std::find (usr_names.begin(), usr_names.end(), key );
32 if (i == usr_names.end()) return -1;
33 return i - usr_names.begin();
34 }
std::vector< std::string > usr_names
user keys
Definition AAObject.hh:21

◆ haveusr()

bool AAObject::haveusr ( const std::string & key) const
inline

Check availability of user data of the item with given key.

Parameters
keykey
Returns
true if available; else false

Definition at line 42 of file AAObject.hh.

43 {
44 return idx( key ) >= 0;
45 }
int idx(const std::string &key) const
Get index in user data of the item with given key.
Definition AAObject.hh:29

◆ idxusr_checked()

int AAObject::idxusr_checked ( const std::string & key) const
inline

Get index in user data of the item with given key.


This method throws a run-time exception if no user data are available.

Parameters
keykey
Returns
index (-1 if key does not exists)

Definition at line 54 of file AAObject.hh.

55 {
56 int r = idx( key );
57 if (r < 0)
58 {
59 THROW(Exception, "No user data for key " << key << " in aanet object of type " << this -> ClassName());
60 }
61 return r;
62 }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
General exception.
Definition Exception.hh:13

◆ getusr()

double AAObject::getusr ( const std::string & key) const
inline

Get user data item with given key.


This method throws a run-time exception if no user data are available.

Parameters
keykey
Returns
value

Definition at line 72 of file AAObject.hh.

73 {
74 const int i = idx( key );
75
76 if ( i < 0 )
77 {
78 THROW(Exception, "No user data for key " << key << " in aanet object of type " << this -> ClassName());
79 }
80
81 if ( unsigned(i) >= usr.size() )
82 {
83 THROW(Exception, "Warning: inconsistent user data " << i << " >= " << usr.size());
84 }
85
86 return usr[i];
87 }
std::vector< double > usr
user data
Definition AAObject.hh:20

◆ setusr()

void AAObject::setusr ( const std::string & key,
double value )
inline

Set user data item with given key.


Parameters
keykey
valuevalue

Definition at line 95 of file AAObject.hh.

96 {
97 int i = idx( key );
98 if (i < 0)
99 {
100 if ( usr.size() < usr_names.size() )
101 {
102 // this should not happen, but let's just add empty data
103 usr.resize( usr_names.size() );
104 }
105 else
106 {
107 // this is possible, add empty ("") names
108 usr_names.resize( usr.size() );
109 }
110
111 usr_names.push_back( key );
112 usr.push_back( value );
113 }
114 else
115 {
116 usr[i] = value;
117 }
118 }

◆ delusr()

bool AAObject::delusr ( const std::string & key)
inline

Remove (first) user data item with given key.


Parameters
keykey
Returns
true if data have been removed; else false

Definition at line 126 of file AAObject.hh.

127 {
128 int i = idx( key );
129 if ( i < 0 ) return false;
130
131 usr.erase ( usr.begin() + i );
132 usr_names.erase( usr_names.begin() + i );
133 return true;
134 }

◆ clearusr()

void AAObject::clearusr ( )
inline

Clear user data.

Definition at line 139 of file AAObject.hh.

140 {
141 usr.resize(0);
142 usr_names.resize(0);
143 }

◆ printusr()

void AAObject::printusr ( std::ostream & out = std::cout)
inline

Print user data (i.e.

list of all pairs of keys and values).

Parameters
outoutput stream

Definition at line 150 of file AAObject.hh.

151 {
152 unsigned n = std::max( usr.size(), usr_names.size() );
153
154 for (unsigned i = 0; i < n ; i++)
155 {
156 std::string name = "(unnamed)";
157 if ( i < usr_names.size() && usr_names[i] != "" ) name = usr_names[i];
158 out << i << " \t " << name << " : \t ";
159 if ( i < usr.size() ) out << usr[i] << std::endl;
160 else out << "(none)" << std::endl;
161 }
162 }
const int n
Definition JPolint.hh:791

Member Data Documentation

◆ usr

std::vector<double> AAObject::usr

user data

Definition at line 20 of file AAObject.hh.

◆ usr_names

std::vector<std::string> AAObject::usr_names

user keys

Definition at line 21 of file AAObject.hh.

◆ any

TObject* AAObject::any

Pointer to "any" user data.

Definition at line 171 of file AAObject.hh.


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