Jpp 19.3.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
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.
 
const JDetectorsoperator[] (const std::string &detid)
 Get detector.
 
const JDetectorsoperator[] (const int id)
 Get detector.
 
int operator() (const std::string &detid)
 Get detector serial number.
 
std::string operator() (const int id)
 Get detector identifier.
 
int operator() (const std::string &detid, const JType< int > &type)
 Get serial number according given data type.
 
std::string operator() (const std::string &detid, const JType< std::string > &type)
 Get detector identifier according given data type.
 

Static Public Attributes

static JDetectorsHelper helper
 Helper object.
 

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:235
const char * getTable()
Get table name.
Definition JDB.hh:373

◆ 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.
Database exception.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
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.

◆ 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: