Jpp  master_rocky-37-gf0c5bc59d
the software that should make you happy
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

◆ initialise()

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  }
static JDB & get()
Get connection to database.
Definition: JDB.hh:234
Auxiliary class for specifying selection of database data.

◆ operator[]() [1/2]

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  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
Database exception.
Definition: JException.hh:684
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
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JSTDTypes.hh:14
void initialise()
Initialise.
Definition: JDBToolkit.hh:48

◆ operator[]() [2/2]

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  }

◆ operator()() [1/4]

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  }

◆ operator()() [2/4]

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  }

◆ operator()() [3/4]

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

◆ operator()() [4/4]

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  }

Member Data Documentation

◆ helper

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: