Jpp  16.0.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 | Protected Attributes | List of all members
JDATABASE::JDetectorsHelper Struct Reference

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

#include <JDBToolkit.hh>

Public Member Functions

void initialise ()
 Initialise. 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...
 

Protected Attributes

std::map< int, std::string > id2det
 
std::map< std::string, int > det2id
 

Detailed Description

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

Definition at line 39 of file JDBToolkit.hh.

Member Function Documentation

void JDATABASE::JDetectorsHelper::initialise ( )
inline

Initialise.

Definition at line 43 of file JDBToolkit.hh.

44  {
45  ResultSet& rs = JDB::get()->StreamDS(getTable<JDetectors>(), JSelector());
46 
47  for (JDetectors parameters; rs >> parameters; ) {
48  det2id[parameters.OID] = parameters.SERIALNUMBER;
49  id2det[parameters.SERIALNUMBER] = parameters.OID;
50  }
51 
52  rs.Close();
53  }
*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.
std::map< std::string, int > det2id
Definition: JDBToolkit.hh:149
std::map< int, std::string > id2det
Definition: JDBToolkit.hh:148
static JDB & get()
Get connection to database.
Definition: JDB.hh:225
int JDATABASE::JDetectorsHelper::operator() ( const std::string &  detid)
inline

Get detector serial number.

Parameters
detidobject identifier
Returns
serial number

Definition at line 62 of file JDBToolkit.hh.

63  {
65 
66  if (p == det2id.end()) {
67 
68  initialise();
69 
70  p = det2id.find(detid);
71 
72  if (p == det2id.end()) {
73  THROW(JDatabaseException, "Invalid detector identifier " << detid);
74  }
75  }
76 
77  return p->second;
78  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:696
std::map< std::string, int > det2id
Definition: JDBToolkit.hh:149
void initialise()
Initialise.
Definition: JDBToolkit.hh:43
std::string JDATABASE::JDetectorsHelper::operator() ( const int  id)
inline

Get detector identifier.

Parameters
idserial number
Returns
object identifier

Definition at line 87 of file JDBToolkit.hh.

88  {
90 
91  if (p == id2det.end()) {
92 
93  initialise();
94 
95  p = id2det.find(id);
96 
97  if (p == id2det.end()) {
98  THROW(JDatabaseException, "Invalid detector identifier " << id);
99  }
100  }
101 
102  return p->second;
103  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:696
void initialise()
Initialise.
Definition: JDBToolkit.hh:43
std::map< int, std::string > id2det
Definition: JDBToolkit.hh:148
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 113 of file JDBToolkit.hh.

114  {
115  using namespace JPP;
116 
117  if (is_integer(detid))
118  return to_value<int>(detid);
119  else
120  return (*this)(detid);
121  }
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 131 of file JDBToolkit.hh.

132  {
133  using namespace JPP;
134 
135  if (is_integer(detid))
136  return (*this)(to_value<int>(detid));
137  else
138  return detid;
139  }
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 145 of file JDBToolkit.hh.

std::map<int, std::string> JDATABASE::JDetectorsHelper::id2det
protected

Definition at line 148 of file JDBToolkit.hh.

std::map<std::string, int> JDATABASE::JDetectorsHelper::det2id
protected

Definition at line 149 of file JDBToolkit.hh.


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