lcls2
C++ API: public headers of xtcdata, psalg, psdaq and psana
Loading...
Searching...
No Matches
calib::Query Class Reference

Calibration-database query: a map from QUERY_PAR keys to string values plus a stored query string. More...

#include <Query.hh>

Public Types

enum  AXIS { AXIS_X =0 , AXIS_Y , AXIS_Z }
 Axis selector; set_paremeters() stores it as the AXISNUM parameter. More...
 
enum  CONSTR_TYPE { QUERY_DEFAULT =0 , QUERY_STRING , QUERY_MAP , QUERY_PARS }
 Which constructor (or set_paremeters()) last set up the query; query() builds a query string only for QUERY_MAP and QUERY_PARS. More...
 
enum  QUERY_PAR {
  DETECTOR =0 , EXPERIMENT , CALIBTYPE , RUN ,
  TIME_SEC , VERSION , AXISNUM , MASKBITS ,
  MASKBITSGEO
}
 Keys of the parameter map; parameter_default() gives each key's default string. More...
 
typedef std::map< QUERY_PAR, std::string > map_t
 Map from QUERY_PAR key to its string value.
 

Public Member Functions

 Query ()
 Default query: empty query string and all nine parameters at their defaults (set_qmap()).
 
 Query (const std::string &query)
 Store query as the query string and set all parameters to their defaults; query() returns the string unchanged.
 
 Query (const map_t &qmap)
 Copy qmap as the parameter map (no defaults are added).
 
 Query (const char *det, const char *exp=NULL, const char *ctype=NULL, const unsigned run=0, const unsigned time_sec=0, const char *version=NULL)
 Set the parameters with set_paremeters(det, exp, ctype, run, time_sec, version); axis and mask bits take their defaults (AXIS_X, 0377).
 
virtual ~Query ()
 Destructor; only logs a debug message.
 
 Query (const Query &)=delete
 Copy construction is disabled.
 
Query & operator= (const Query &)=delete
 Copy assignment is disabled.
 
const CONSTR_TYPE & constr_type ()
 Return which constructor (or set_paremeters()) last set up the query.
 
std::string string_members (const char *sep="\n")
 Return "DETECTOR: v", "EXPERIMENT: v", ... "MASKBITSGEO: v" for all nine parameters (values from parameter()), joined by sep.
 
void set_qmap (const map_t *map=NULL)
 Replace the parameter map with *map, or, if map is NULL, set all nine parameters to their defaults.
 
void set_paremeters (const char *det, const char *exp=NULL, const char *ctype=NULL, const unsigned run=0, const unsigned time_sec=0, const char *version=NULL, const AXIS axis=AXIS_X, const unsigned mbits=0377, const unsigned mbitsgeo=0377)
 Set all nine parameters: NULL char pointers (exp, ctype, version) become "NULL" and numbers become decimal strings (so mbits 0377 is stored as "255").
 
void set_paremeter (const QUERY_PAR t, const char *p)
 Set parameter t to the string p.
 
void set_calibtype (const CALIB_TYPE &ctype)
 Set CALIBTYPE to name_of_calibtype(ctype).
 
bool is_set (const QUERY_PAR t)
 Return true if the map has an entry for t.
 
std::string parameter_default (const QUERY_PAR t)
 Return the default string for t: "NULL" for DETECTOR, EXPERIMENT, CALIBTYPE and VERSION; "0" for RUN, TIME_SEC and AXISNUM; "0377" for MASKBITS and MASKBITSGEO.
 
std::string parameter (const QUERY_PAR t)
 Return the value stored for t, or parameter_default(t) if t is not set.
 
int parameter_int (const QUERY_PAR t)
 Return std::stoi(parameter(t)); stoi throws std::invalid_argument for a non-numeric value such as "NULL".
 
unsigned parameter_uint (const QUERY_PAR t)
 Return (unsigned)std::stoi(parameter(t)).
 
uint16_t parameter_uint16 (const QUERY_PAR t)
 Return (uint16_t)std::stoi(parameter(t)).
 
map_t & qmap ()
 Return a reference to the parameter map.
 
std::string query ()
 For QUERY_MAP and QUERY_PARS, build the JSON query with dbnames_collection_query() from DETECTOR, EXPERIMENT, CALIBTYPE, RUN, TIME_SEC and VERSION, store it and return it; otherwise return the stored string.
 

Protected Attributes

std::string _query
 
map_t _qmap
 

Friends

std::ostream & operator<< (std::ostream &os, Query &o)
 Write o.string_members(" ") to os and return os.
 

Detailed Description

Calibration-database query: a map from QUERY_PAR keys to string values plus a stored query string.

query() builds the web-DB JSON query from the map.

Member Typedef Documentation

◆ map_t

typedef std::map<QUERY_PAR, std::string> calib::Query::map_t

Map from QUERY_PAR key to its string value.

Member Enumeration Documentation

◆ AXIS

Axis selector; set_paremeters() stores it as the AXISNUM parameter.

Enumerator
AXIS_X 

Value 0.

AXIS_Y 

Value 1.

AXIS_Z 

Value 2.

◆ CONSTR_TYPE

Which constructor (or set_paremeters()) last set up the query; query() builds a query string only for QUERY_MAP and QUERY_PARS.

Enumerator
QUERY_DEFAULT 

0: set by Query().

QUERY_STRING 

1: set by Query(const std::string&).

QUERY_MAP 

2: set by Query(const map_t&).

QUERY_PARS 

3: set by the parameter constructor and by set_paremeters().

◆ QUERY_PAR

Keys of the parameter map; parameter_default() gives each key's default string.

Enumerator
DETECTOR 

Key 0; default "NULL".

EXPERIMENT 

Key 1; default "NULL".

CALIBTYPE 

Key 2; default "NULL".

RUN 

Key 3; default "0".

TIME_SEC 

Key 4; default "0".

VERSION 

Key 5; default "NULL".

AXISNUM 

Key 6; default "0".

MASKBITS 

Key 7; default "0377".

MASKBITSGEO 

Key 8; default "0377".

Constructor & Destructor Documentation

◆ Query() [1/5]

calib::Query::Query ( )

Default query: empty query string and all nine parameters at their defaults (set_qmap()).

◆ Query() [2/5]

calib::Query::Query ( const std::string &  query)

Store query as the query string and set all parameters to their defaults; query() returns the string unchanged.

◆ Query() [3/5]

calib::Query::Query ( const map_t &  qmap)

Copy qmap as the parameter map (no defaults are added).

Reading DETECTOR for the debug message inserts an empty DETECTOR entry if it is missing.

◆ Query() [4/5]

calib::Query::Query ( const char *  det,
const char *  exp = NULL,
const char *  ctype = NULL,
const unsigned  run = 0,
const unsigned  time_sec = 0,
const char *  version = NULL 
)

Set the parameters with set_paremeters(det, exp, ctype, run, time_sec, version); axis and mask bits take their defaults (AXIS_X, 0377).

◆ ~Query()

virtual calib::Query::~Query ( )
virtual

Destructor; only logs a debug message.

◆ Query() [5/5]

calib::Query::Query ( const Query &  )
delete

Copy construction is disabled.

Member Function Documentation

◆ constr_type()

const CONSTR_TYPE & calib::Query::constr_type ( )
inline

Return which constructor (or set_paremeters()) last set up the query.

◆ is_set()

bool calib::Query::is_set ( const QUERY_PAR  t)

Return true if the map has an entry for t.

◆ operator=()

Query & calib::Query::operator= ( const Query &  )
delete

Copy assignment is disabled.

◆ parameter()

std::string calib::Query::parameter ( const QUERY_PAR  t)

Return the value stored for t, or parameter_default(t) if t is not set.

◆ parameter_default()

std::string calib::Query::parameter_default ( const QUERY_PAR  t)

Return the default string for t: "NULL" for DETECTOR, EXPERIMENT, CALIBTYPE and VERSION; "0" for RUN, TIME_SEC and AXISNUM; "0377" for MASKBITS and MASKBITSGEO.

◆ parameter_int()

int calib::Query::parameter_int ( const QUERY_PAR  t)

Return std::stoi(parameter(t)); stoi throws std::invalid_argument for a non-numeric value such as "NULL".

◆ parameter_uint()

unsigned calib::Query::parameter_uint ( const QUERY_PAR  t)

Return (unsigned)std::stoi(parameter(t)).

stoi reads decimal, so the default "0377" gives 377; it throws for a non-numeric value.

◆ parameter_uint16()

uint16_t calib::Query::parameter_uint16 ( const QUERY_PAR  t)

Return (uint16_t)std::stoi(parameter(t)).

stoi reads decimal, so the default "0377" gives 377; it throws for a non-numeric value.

◆ qmap()

map_t & calib::Query::qmap ( )
inline

Return a reference to the parameter map.

◆ query()

std::string calib::Query::query ( )

For QUERY_MAP and QUERY_PARS, build the JSON query with dbnames_collection_query() from DETECTOR, EXPERIMENT, CALIBTYPE, RUN, TIME_SEC and VERSION, store it and return it; otherwise return the stored string.

Values are passed as strings, so a VERSION left at "NULL" is added to the query as "version":"NULL".

◆ set_calibtype()

void calib::Query::set_calibtype ( const CALIB_TYPE &  ctype)

Set CALIBTYPE to name_of_calibtype(ctype).

◆ set_paremeter()

void calib::Query::set_paremeter ( const QUERY_PAR  t,
const char *  p 
)

Set parameter t to the string p.

◆ set_paremeters()

void calib::Query::set_paremeters ( const char *  det,
const char *  exp = NULL,
const char *  ctype = NULL,
const unsigned  run = 0,
const unsigned  time_sec = 0,
const char *  version = NULL,
const AXIS  axis = AXIS_X,
const unsigned  mbits = 0377,
const unsigned  mbitsgeo = 0377 
)

Set all nine parameters: NULL char pointers (exp, ctype, version) become "NULL" and numbers become decimal strings (so mbits 0377 is stored as "255").

Sets constr_type() to QUERY_PARS. det must not be NULL, as it is passed straight to std::string.

◆ set_qmap()

void calib::Query::set_qmap ( const map_t *  map = NULL)

Replace the parameter map with *map, or, if map is NULL, set all nine parameters to their defaults.

◆ string_members()

std::string calib::Query::string_members ( const char *  sep = "\n")

Return "DETECTOR: v", "EXPERIMENT: v", ... "MASKBITSGEO: v" for all nine parameters (values from parameter()), joined by sep.

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  os,
Query &  o 
)
friend

Write o.string_members(" ") to os and return os.

Member Data Documentation

◆ _qmap

map_t calib::Query::_qmap
protected

◆ _query

std::string calib::Query::_query
protected

The documentation for this class was generated from the following file: