Jpp  pmt_effective_area_update_2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Public Attributes | List of all members
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 JAANET::JTrk_t

Public Member Functions

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

Public Attributes

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

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 ( )
inline

Default constructor.

Definition at line 167 of file AAObject.hh.

167 : any(NULL) {}
TObject * any
Pointer to &quot;any&quot; user data.
Definition: AAObject.hh:171
AAObject::~AAObject ( )
inline

Definition at line 168 of file AAObject.hh.

168 {}

Member Function Documentation

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
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
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.
Definition: JException.hh:670
data_type r[M+1]
Definition: JPolint.hh:742
int idx(const std::string &key) const
Get index in user data of the item with given key.
Definition: AAObject.hh:29
General exception.
Definition: Exception.hh:13
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  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:670
int idx(const std::string &key) const
Get index in user data of the item with given key.
Definition: AAObject.hh:29
General exception.
Definition: Exception.hh:13
std::vector< double > usr
user data
Definition: AAObject.hh:20
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  }
std::vector< std::string > usr_names
user keys
Definition: AAObject.hh:21
int idx(const std::string &key) const
Get index in user data of the item with given key.
Definition: AAObject.hh:29
std::vector< double > usr
user data
Definition: AAObject.hh:20
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  }
std::vector< std::string > usr_names
user keys
Definition: AAObject.hh:21
int idx(const std::string &key) const
Get index in user data of the item with given key.
Definition: AAObject.hh:29
std::vector< double > usr
user data
Definition: AAObject.hh:20
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  }
std::vector< std::string > usr_names
user keys
Definition: AAObject.hh:21
std::vector< double > usr
user data
Definition: AAObject.hh:20
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  }
std::vector< std::string > usr_names
user keys
Definition: AAObject.hh:21
then echo Enter input within $TIMEOUT_S seconds echo n User name
Definition: JCookie.sh:42
alias put_queue eval echo n
Definition: qlib.csh:19
std::vector< double > usr
user data
Definition: AAObject.hh:20

Member Data Documentation

std::vector<double> AAObject::usr

user data

Definition at line 20 of file AAObject.hh.

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

user keys

Definition at line 21 of file AAObject.hh.

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: