Jpp  18.0.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Static Public Attributes | List of all members
JDATABASE::JDetectorsHelper Struct Reference

Auxiliary class for mapping serial number and object identifier of detectors. More...

#include <JDBToolkit.hh>

Inheritance diagram for JDATABASE::JDetectorsHelper:
std::vector< JDetectors >

Public Member Functions

void initialise ()
 Initialise. More...
 
const JDetectorsoperator[] (const std::string &detid)
 Get detector. More...
 
const JDetectorsoperator[] (const int id)
 Get detector. More...
 
int operator() (const std::string &detid)
 Get detector serial number. More...
 
std::string operator() (const int id)
 Get detector identifier. More...
 
int operator() (const std::string &detid, const JType< int > &type)
 Get serial number according given data type. More...
 
std::string operator() (const std::string &detid, const JType< std::string > &type)
 Get detector identifier according given data type. More...
 

Static Public Attributes

static JDetectorsHelper helper
 Helper object. More...
 

Detailed Description

Auxiliary class for mapping serial number and object identifier of detectors.

Definition at line 42 of file JDBToolkit.hh.

Member Function Documentation

void JDATABASE::JDetectorsHelper::initialise ( )
inline

Initialise.

Definition at line 48 of file JDBToolkit.hh.

49  {
50  ResultSet& rs = JDB::get()->StreamDS(getTable<JDetectors>(), JSelector());
51 
52  for (JDetectors parameters; rs >> parameters; ) {
53  this->push_back(parameters);
54  }
55 
56  rs.Close();
57  }
*fatal Wrong number of arguments esac JCookie sh typeset Z DETECTOR typeset Z SOURCE_RUN typeset Z TARGET_RUN set_variable PARAMETERS_FILE $WORKDIR parameters
Definition: diff-Tuna.sh:38
Auxiliary class for specifying selection of database data.
static JDB & get()
Get connection to database.
Definition: JDB.hh:233
const JDetectors& JDATABASE::JDetectorsHelper::operator[] ( const std::string detid)
inline

Get detector.

Parameters
detidobject identifier
Returns
detector

Definition at line 66 of file JDBToolkit.hh.

67  {
68  using namespace std;
69  using namespace JPP;
70 
71  if (this->empty()) {
72  this->initialise();
73  }
74 
75  const_iterator p = find_if(this->begin(), this->end(), make_predicate(&JDetectors::OID, detid));
76 
77  if (p != this->end())
78  return *p;
79  else
80  THROW(JDatabaseException, "Invalid detector identifier " << detid);
81  }
JPredicate< JResult_t T::*, JComparison::eq > make_predicate(JResult_t T::*member, const JResult_t value)
Helper method to create predicate for data member.
Definition: JPredicate.hh:128
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:696
void initialise()
Initialise.
Definition: JDBToolkit.hh:48
const JDetectors& JDATABASE::JDetectorsHelper::operator[] ( const int  id)
inline

Get detector.

Parameters
idserial number
Returns
detector

Definition at line 90 of file JDBToolkit.hh.

91  {
92  using namespace std;
93  using namespace JPP;
94 
95  if (this->empty()) {
96  this->initialise();
97  }
98 
99  const_iterator p = find_if(this->begin(), this->end(), make_predicate(&JDetectors::SERIALNUMBER, id));
100 
101  if (p != this->end())
102  return *p;
103  else
104  THROW(JDatabaseException, "Invalid detector identifier " << id);
105  }
JPredicate< JResult_t T::*, JComparison::eq > make_predicate(JResult_t T::*member, const JResult_t value)
Helper method to create predicate for data member.
Definition: JPredicate.hh:128
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:696
void initialise()
Initialise.
Definition: JDBToolkit.hh:48
int JDATABASE::JDetectorsHelper::operator() ( const std::string detid)
inline

Get detector serial number.

Parameters
detidobject identifier
Returns
serial number

Definition at line 114 of file JDBToolkit.hh.

115  {
116  return (*this)[detid].SERIALNUMBER;
117  }
std::string JDATABASE::JDetectorsHelper::operator() ( const int  id)
inline

Get detector identifier.

Parameters
idserial number
Returns
object identifier

Definition at line 126 of file JDBToolkit.hh.

127  {
128  return (*this)[id].OID;
129  }
int JDATABASE::JDetectorsHelper::operator() ( const std::string detid,
const JType< int > &  type 
)
inline

Get serial number according given data type.

Parameters
detidobject identifier or serial number
typedata type
Returns
object identifier

Definition at line 139 of file JDBToolkit.hh.

140  {
141  using namespace JPP;
142 
143  if (is_integer(detid))
144  return to_value<int>(detid);
145  else
146  return (*this)(detid);
147  }
bool is_integer(const std::string &buffer)
Check if string is an integer.
Definition: JLangToolkit.hh:58
std::string JDATABASE::JDetectorsHelper::operator() ( const std::string detid,
const JType< std::string > &  type 
)
inline

Get detector identifier according given data type.

Parameters
detidobject identifier or serial number
typedata type
Returns
object identifier

Definition at line 157 of file JDBToolkit.hh.

158  {
159  using namespace JPP;
160 
161  if (is_integer(detid))
162  return (*this)(to_value<int>(detid));
163  else
164  return detid;
165  }
bool is_integer(const std::string &buffer)
Check if string is an integer.
Definition: JLangToolkit.hh:58

Member Data Documentation

JDetectorsHelper JDATABASE::JDetectorsHelper::helper
static

Helper object.

Definition at line 171 of file JDBToolkit.hh.


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