|
lcls2
C++ API: public headers of xtcdata, psalg, psdaq and psana
|
Usage. More...
Namespaces | |
| namespace | shmem |
| Shared-memory monitoring classes (XtcMonitorMsg, XtcMonitorServer, ShmemClient, ...). | |
| namespace | types |
| Basic psalg type aliases. | |
Classes | |
| class | AllocArray |
| Array<T> whose shape (MaxRank words), a reference count and up to maxElem elements live in one block from an Allocator. More... | |
| class | AllocArray1D |
| Rank-1 AllocArray with std::vector-like push_back(), clear(), size() and capacity(). More... | |
| class | ArrayIO |
| Loads an array of T from a text file in the constructor. More... | |
| class | DirFileIterator |
| Iterates over the entries of a directory whose names contain a pattern; next() returns dirname + "/" + name. More... | |
| class | NDArray |
| XtcData::Array<T> subclass that keeps its own copy of the shape (set_shape() asserts ndim < MAXNDIM) and either points at an external buffer or owns a heap buffer, deleted in the destructor. More... | |
| class | SysLog |
| Static wrappers around syslog(3): init() opens the log, and each message function prefixes the format with a level letter (D, I, W, E or C) in angle brackets. More... | |
Typedefs | |
| typedef long int | NPSHAPE_T |
| long int; shape element type used by ctest_nda_v2(). | |
| typedef uint32_t | index_t |
| uint32_t; index type of the find_edges() results. | |
| typedef double | wfdata_t |
| double. | |
Functions | |
| void | print_json_doc_as_string (const rapidjson::Value &value) |
| Print "In print_json_doc_as_string: " followed by json_doc_to_string(value) to stdout. | |
| void | print_json_doc (const rapidjson::Value &doc, const std::string &offset=" ") |
| Recursively print doc to stdout with a type label per value, indenting nested levels by 4 spaces plus offset; strings are cut to 1000 characters. | |
| void | print_vector_of_strings (const std::vector< std::string > &v, const char *gap=" == ") |
| Print "In print_vector_of_strings" and then each string of v prefixed by gap, one per line, to stdout. | |
| void | print_byte_string_as_float (const std::string &s, const size_t nvals=100) |
| Reinterpret the bytes of s as floats and print their count and the first nvals values to stdout. | |
| std::string | json_value_type (const rapidjson::Value &v) |
| Return a type name for v: "string", "int" (also used for booleans), "number", "object", "array", or a "Non-implemented type: " string for other types (e.g. | |
| std::string | json_doc_to_string (const rapidjson::Value &d) |
| Serialize d to a compact JSON string with rapidjson::Writer. | |
| void | chars_to_json_doc (const char *s, rapidjson::Document &jd) |
| Parse the JSON text s into jd; on a parse error log an ERROR message with the error code and offset. | |
| rapidjson::Document | chars_to_json_doc (const char *s) |
| Declared here; no definition was found in MDBWebUtils.cc. | |
| void | json_doc_to_vector_of_strings (const rapidjson::Value &doc, std::vector< std::string > &vout) |
| Clear vout and, if doc is a non-empty array, fill it with the array's string elements. | |
| size_t | _callback (char *buf, size_t size, size_t nmemb, void *up) |
| libcurl write callback: append size*nmemb bytes from buf to the std::string pointed to by up and return that byte count. | |
| void | response_to_json_doc (const std::string &sresp, rapidjson::Document &) |
| Parse sresp as JSON into the given document (chars_to_json_doc()). | |
| void | string_url_with_query (std::string &surl, const char *dbname, const char *colname, const char *query=NULL, const char *urlws=URLWS) |
| Set surl to urlws/dbname/colname, followed by "?query_string=" and the URL-escaped query if query is not NULL. | |
| void | request (std::string &sresp, const char *url=URLWS) |
| HTTP GET url with libcurl and store the response body in sresp (cleared first). | |
| void | database_names (std::vector< std::string > &dbnames, const char *urlws=URLWS) |
| GET urlws and fill dbnames with the string elements of the returned JSON array (left empty if it is not a non-empty array). | |
| void | collection_names (std::vector< std::string > &colnames, const char *dbname, const char *urlws=URLWS) |
| GET urlws/dbname and fill colnames with the string elements of the returned JSON array (left empty if it is not a non-empty array). | |
| void | find_docs (std::string &sresp, const char *dbname, const char *colname, const char *query=NULL, const char *urlws=URLWS) |
| GET the URL built by string_url_with_query() and store the raw response in sresp. | |
| const rapidjson::Value & | find_doc (rapidjson::Document &outdocs, const char *dbname, const char *colname, const char *query=NULL, const char *urlws=URLWS) |
| Run find_docs(), parse the response into outdocs, and return the element with the largest "time_sec" if query contains "time_sec", else the largest "run". | |
| const rapidjson::Value & | value_from_json_doc (const rapidjson::Value &doc, const char *valname) |
| Return doc[valname], or EMPTY_VALUE if doc has no such member. | |
| void | get_doc_for_docid (rapidjson::Document &jdoc, const char *dbname, const char *colname, const char *docid, const char *urlws=URLWS) |
| GET urlws/dbname/colname/docid and parse the response into jdoc. | |
| void | get_data_for_id (std::string &sresp, const char *dbname, const char *dataid, const char *urlws=URLWS) |
| GET urlws/dbname/gridfs/dataid and store the raw response bytes in sresp. | |
| void | get_data_for_docid (std::string &sresp, const char *dbname, const char *colname, const char *docid, const char *urlws=URLWS) |
| Fetch document docid (get_doc_for_docid()), then fetch into sresp the data whose id is the document's "id_data" string (get_data_for_id()). | |
| void | get_data_for_doc (std::string &sresp, const char *dbname, const char *colname, const rapidjson::Value &jdoc, const char *urlws=URLWS) |
| Call get_data_for_docid() with the "_id" string member of jdoc. | |
| const std::string | db_prefixed_name (const char *name, const char *prefix="cdb_") |
| Return prefix + name (e.g. | |
| void | dbnames_collection_query (std::map< std::string, std::string > &omap, const char *det, const char *exp=NULL, const char *ctype=NULL, const unsigned run=0, const unsigned time_sec=0, const char *version=NULL) |
| Fill omap with "db_det" ("cdb_" + det), "db_exp" ("cdb_" + exp, or empty if exp is NULL), "colname" (det) and "query". | |
| void | calib_doc (rapidjson::Document &doc, const char *detector, const char *experiment=NULL, const char *ctype=NULL, const unsigned run=0, const unsigned time_sec=0, const char *version=NULL, const char *urlws=URLWS) |
| Find the best-matching document (find_doc()) in collection detector of database "cdb_" + experiment if experiment is given, else "cdb_" + detector, and deep-copy it into doc. | |
| void | calib_constants (std::string &sresp, rapidjson::Document &doc, const char *detector, const char *experiment=NULL, const char *ctype=NULL, const unsigned run=0, const unsigned time_sec=0, const char *version=NULL, const char *urlws=URLWS) |
| Like calib_doc(), then download the data referenced by the found document into sresp (get_data_for_doc()). | |
| template<typename T > | |
| void | calib_constants_nda (NDArray< T > &nda, rapidjson::Document &doc, const char *detector, const char *experiment=NULL, const char *ctype=NULL, const unsigned run=0, const unsigned time_sec=0, const char *version=NULL, const char *urlws=URLWS) |
| Run calib_constants(), set the shape of nda from the document's "data_shape" string, and deep-copy the downloaded bytes into nda. | |
| void | calib_constants_doc (rapidjson::Document &docdata, rapidjson::Document &docmeta, const char *detector, const char *experiment=NULL, const char *ctype=NULL, const unsigned run=0, const unsigned time_sec=0, const char *version=NULL, const char *urlws=URLWS) |
| Run calib_constants() with docmeta as the metadata document, then parse the downloaded data as JSON into docdata. | |
| template<typename TDATA > | |
| void | response_string_to_data_array (const std::string &s, const TDATA *&pout, size_t &size) |
| Point pout at the bytes of s reinterpreted as TDATA and set size to s.size()/sizeof(TDATA). | |
| template<typename T > | |
| void | ctest_nda (T *arr, int r, int c) |
| Test helper: print r, c and the r*c elements of arr to stdout, adding each element's index to it (arr[i] = i + arr[i]). | |
| void | ctest_nda_f8 (double *arr, int r, int c) |
| Call ctest_nda<double>(arr, r, c). | |
| void | ctest_nda_i2 (int16_t *arr, int r, int c) |
| Call ctest_nda<int16_t>(arr, r, c). | |
| void | ctest_nda_u2 (uint16_t *arr, int r, int c) |
| Call ctest_nda<uint16_t>(arr, r, c). | |
| template<typename T > | |
| void | ctest_nda_v2 (T *arr, NPSHAPE_T *sh, int &ndim) |
| Test helper: print ndim and the first ndim entries of sh, then print the first 10 elements of arr and add 1 to each of them (always 10, whatever the shape). | |
| template<typename T > | |
| void | ctest_vector (vector< T > &v) |
| Test helper: print the size of v, set v[2] to 222 (not range-checked), then print all elements of v to stdout. | |
| template<typename T > | |
| void | fill_ndarray_const (NDArray< T > &a, const T &c) |
| Set every element of a to c. | |
| template<typename T > | |
| void | fill_ndarray_random (NDArray< T > &a, int range=100) |
| Set every element of a to std::rand() % range, cast to T. | |
| template<typename T > | |
| void | fill_ndarray_normal (NDArray< T > &a, double mean=0, double stddev=1) |
| Set every element of a to a sample from a normal distribution with the given mean and stddev, cast to T. | |
| std::string | ltrim (const std::string &str) |
| Return a copy of str without leading whitespace (space, newline, carriage return, tab, form feed, vertical tab); empty if str is all whitespace. | |
| std::string | rtrim (const std::string &str) |
| Return a copy of str without trailing whitespace (space, newline, carriage return, tab, form feed, vertical tab); empty if str is all whitespace. | |
| std::string | trim (const std::string &str) |
| Return rtrim(ltrim(str)). | |
| std::string | strip (const std::string &str) |
| Return a copy of str with every whitespace character removed (std::isspace in the classic locale). | |
| std::vector< std::string > | files_in_dir (const char *dirname="/reg/neh/home/dubrovin/LCLS/con-detector/work", const char *pattern=0) |
| Return the sorted paths dirname + "/" + name of the entries of dirname ("." and ".." included) whose names contain pattern, or all entries if pattern is null. | |
| void | dir_content (const char *dirname="/reg/neh/home/dubrovin/LCLS/con-detector/work", const char *pattern=0) |
| Print to stdout, one per line, the names of the entries of dirname that contain pattern (all if pattern is null). | |
| template<typename T > | |
| void | ctest_nda_v2 (T *arr, uint32_t *sh, int &ndim) |
| Test helper: print ndim and the first ndim entries of sh, then print the first 5 elements of arr and add each element's index to it (always 5 elements). | |
| template<typename T > | |
| void | _add_edge (const std::vector< T > &v, bool rising, double fraction, double deadtime, T peak, index_t start, double &last, index_t &ipk, T *pkvals, index_t *pkinds) |
| From sample start, find the first sample i where v reaches the level fraction (an absolute level: upward if rising, downward otherwise) and interpolate the edge position linearly between samples i-1 and i (0 if i is 0). | |
| template<typename T > | |
| index_t | find_edges (index_t npkmax, T *pkvals, index_t *pkinds, const std::vector< T > &wf, double baseline, double threshold, double fraction, double deadtime, bool leading_edge) |
| Find pulses in wf that go beyond threshold (above it if threshold > baseline, else below) for more than deadtime samples; for each, store its extreme value in pkvals and the interpolated index of the edge at level fraction*(peak-baseline)+baseline in pkinds (leading edge, or with leading_edge false the trailing edge searched from the peak). | |
Variables | |
| static const char * | URLWS = "https://pswww.slac.stanford.edu/calib_ws" |
| Default base URL of the calibration web service, "https://pswww.slac.stanford.edu/calib_ws". | |
| static rapidjson::Value | EMPTY_VALUE |
| Null rapidjson::Value returned by find_doc() and value_from_json_doc() when nothing is found. | |
Usage.
Waveform pulse edge finder.
#include "psalg/calib/MDBWebUtils.hh"
_ = wu.requests_get(url, query=None) _ = wu.database_names(urlws=cc.URLWS) _ = wu.collection_names(dbname, urlws=cc.URLWS) _ = wu.find_docs(dbname, colname, query={'ctype':'pedestals'}, urlws=cc.URLWS) _ = wu.find_doc(dbname, colname, query={'ctype':'pedestals'}, urlws=cc.URLWS) _ = wu.get_doc_for_docid(dbname, colname, docid, urlws=cc.URLWS) _ = wu.get_data_for_id(dbname, dataid, urlws=cc.URLWS) _ = wu.get_data_for_docid(dbname, colname, docid, urlws=cc.URLWS) _ = wu.get_data_for_doc(dbname, colname, doc, urlws=cc.URLWS) _ = wu.calib_constants(det, exp=None, ctype='pedestals', run=None, time_sec=None, vers=None, urlws=cc.URLWS)
#include "psalg/utils/DirFileIterator.hh"
#include "psalg/calib/NDArray.hh" #include "psalg/calib/NDArrayGenerators.hh"
typedef psalg::types::shape_t shape_t; // uint32_t typedef psalg::types::size_t size_t; // uint32_t
float data[] = {1,2,3,4,5,6,7,8,9,10,11,12}; shape_t sh[2] = {3,4}; size_t ndim = 2;
// use external data buffer: NDArray<float> a(sh, ndim, data);
// set from NDArray or XtcData::Array a NDArray(a);
// use internal data buffer: NDArray<float> b(sh, ndim); // or set it later b.set_data_buffer(data)
// 3: instatiate empty object and initialize it later NDArray<float> c; c.set_shape(sh, ndim); // or alias reshape(sh, ndim) c.set_shape(str_shape); // sets _shape and _rank from string c.set_data_buffer(data); c.set_ndarray(a); // where a is NDArray or XtcData::Array
size_t ndim = a.ndim(); size_t size = a.size(); shape_t* sh = a.shape(); T* data = a.data();
T value = a(1,2);
std::cout << "ostream array: " << a << '
';
Generates an array of hit times and amplitudes for waveform leading (trailing) edges using a constant fraction discriminator algorithm. The baseline and minimum amplitude threshold are used for discriminating hits. The pulse height fraction at which the hit time is derived is also required as input. Note that if the threshold is less than the baseline value, then leading edges are "falling" and trailing edges are "rising". In order for two pulses to be discriminated, the waveform samples below the two pulses must fall below (or above for negative pulses) the fractional value of the threshold; i.e. waveform[i] < fraction*(threshold-baseline)+baseline.
The results are stored in a 2D array such that result[i][0] is the time (waveform sample) of the i'th hit and result[i][1] is the maximum amplitude of the i'th hit.
| typedef uint32_t psalg::index_t |
uint32_t; index type of the find_edges() results.
| typedef long int psalg::NPSHAPE_T |
long int; shape element type used by ctest_nda_v2().
| typedef double psalg::wfdata_t |
double.
Not used in WFAlgos.hh or WFAlgos.cc.
| void psalg::_add_edge | ( | const std::vector< T > & | v, |
| bool | rising, | ||
| double | fraction, | ||
| double | deadtime, | ||
| T | peak, | ||
| index_t | start, | ||
| double & | last, | ||
| index_t & | ipk, | ||
| T * | pkvals, | ||
| index_t * | pkinds | ||
| ) |
From sample start, find the first sample i where v reaches the level fraction (an absolute level: upward if rising, downward otherwise) and interpolate the edge position linearly between samples i-1 and i (0 if i is 0).
If no edge was recorded yet (last < 0) or the edge is more than deadtime after last, store peak in pkvals[ipk] and the edge, truncated to index_t, in pkinds[ipk], then increment ipk and set last. The search is not bounded by the size of v.
| size_t psalg::_callback | ( | char * | buf, |
| size_t | size, | ||
| size_t | nmemb, | ||
| void * | up | ||
| ) |
libcurl write callback: append size*nmemb bytes from buf to the std::string pointed to by up and return that byte count.
| void psalg::calib_constants | ( | std::string & | sresp, |
| rapidjson::Document & | doc, | ||
| const char * | detector, | ||
| const char * | experiment = NULL, |
||
| const char * | ctype = NULL, |
||
| const unsigned | run = 0, |
||
| const unsigned | time_sec = 0, |
||
| const char * | version = NULL, |
||
| const char * | urlws = URLWS |
||
| ) |
Like calib_doc(), then download the data referenced by the found document into sresp (get_data_for_doc()).
If detector is NULL or no document is found, logs a WARNING and clears sresp.
| void psalg::calib_constants_doc | ( | rapidjson::Document & | docdata, |
| rapidjson::Document & | docmeta, | ||
| const char * | detector, | ||
| const char * | experiment = NULL, |
||
| const char * | ctype = NULL, |
||
| const unsigned | run = 0, |
||
| const unsigned | time_sec = 0, |
||
| const char * | version = NULL, |
||
| const char * | urlws = URLWS |
||
| ) |
Run calib_constants() with docmeta as the metadata document, then parse the downloaded data as JSON into docdata.
| void psalg::calib_constants_nda | ( | NDArray< T > & | nda, |
| rapidjson::Document & | doc, | ||
| const char * | detector, | ||
| const char * | experiment = NULL, |
||
| const char * | ctype = NULL, |
||
| const unsigned | run = 0, |
||
| const unsigned | time_sec = 0, |
||
| const char * | version = NULL, |
||
| const char * | urlws = URLWS |
||
| ) |
Run calib_constants(), set the shape of nda from the document's "data_shape" string, and deep-copy the downloaded bytes into nda.
The document is assumed to have "data_shape" (not checked). Instantiated in MDBWebUtils.cc for int, float, double, uint16_t and uint32_t.
| void psalg::calib_doc | ( | rapidjson::Document & | doc, |
| const char * | detector, | ||
| const char * | experiment = NULL, |
||
| const char * | ctype = NULL, |
||
| const unsigned | run = 0, |
||
| const unsigned | time_sec = 0, |
||
| const char * | version = NULL, |
||
| const char * | urlws = URLWS |
||
| ) |
Find the best-matching document (find_doc()) in collection detector of database "cdb_" + experiment if experiment is given, else "cdb_" + detector, and deep-copy it into doc.
Logs a WARNING and leaves doc unchanged if detector is NULL or no document is found.
| rapidjson::Document psalg::chars_to_json_doc | ( | const char * | s | ) |
Declared here; no definition was found in MDBWebUtils.cc.
| void psalg::chars_to_json_doc | ( | const char * | s, |
| rapidjson::Document & | jd | ||
| ) |
Parse the JSON text s into jd; on a parse error log an ERROR message with the error code and offset.
| void psalg::collection_names | ( | std::vector< std::string > & | colnames, |
| const char * | dbname, | ||
| const char * | urlws = URLWS |
||
| ) |
GET urlws/dbname and fill colnames with the string elements of the returned JSON array (left empty if it is not a non-empty array).
| void psalg::ctest_nda | ( | T * | arr, |
| int | r, | ||
| int | c | ||
| ) |
Test helper: print r, c and the r*c elements of arr to stdout, adding each element's index to it (arr[i] = i + arr[i]).
| void psalg::ctest_nda_f8 | ( | double * | arr, |
| int | r, | ||
| int | c | ||
| ) |
Call ctest_nda<double>(arr, r, c).
| void psalg::ctest_nda_i2 | ( | int16_t * | arr, |
| int | r, | ||
| int | c | ||
| ) |
Call ctest_nda<int16_t>(arr, r, c).
| void psalg::ctest_nda_u2 | ( | uint16_t * | arr, |
| int | r, | ||
| int | c | ||
| ) |
Call ctest_nda<uint16_t>(arr, r, c).
| void psalg::ctest_nda_v2 | ( | T * | arr, |
| NPSHAPE_T * | sh, | ||
| int & | ndim | ||
| ) |
Test helper: print ndim and the first ndim entries of sh, then print the first 10 elements of arr and add 1 to each of them (always 10, whatever the shape).
| void psalg::ctest_nda_v2 | ( | T * | arr, |
| uint32_t * | sh, | ||
| int & | ndim | ||
| ) |
Test helper: print ndim and the first ndim entries of sh, then print the first 5 elements of arr and add each element's index to it (always 5 elements).
| void psalg::ctest_vector | ( | vector< T > & | v | ) |
Test helper: print the size of v, set v[2] to 222 (not range-checked), then print all elements of v to stdout.
Test helper: print the size of v and its first 5 elements (not range-checked) to stdout.
| void psalg::database_names | ( | std::vector< std::string > & | dbnames, |
| const char * | urlws = URLWS |
||
| ) |
GET urlws and fill dbnames with the string elements of the returned JSON array (left empty if it is not a non-empty array).
| const std::string psalg::db_prefixed_name | ( | const char * | name, |
| const char * | prefix = "cdb_" |
||
| ) |
Return prefix + name (e.g.
"cdb_" + name); asserts that the result is shorter than 128 characters.
| void psalg::dbnames_collection_query | ( | std::map< std::string, std::string > & | omap, |
| const char * | det, | ||
| const char * | exp = NULL, |
||
| const char * | ctype = NULL, |
||
| const unsigned | run = 0, |
||
| const unsigned | time_sec = 0, |
||
| const char * | version = NULL |
||
| ) |
Fill omap with "db_det" ("cdb_" + det), "db_exp" ("cdb_" + exp, or empty if exp is NULL), "colname" (det) and "query".
The query is a JSON string with "detector" and "ctype", plus "run":{"$lte":run} if run > 0, "time_sec":{"$lte":time_sec} if time_sec > 0 and "version" if version is not NULL. Asserts that run > 0, time_sec > 0 or version is not NULL.
| void psalg::dir_content | ( | const char * | dirname = "/reg/neh/home/dubrovin/LCLS/con-detector/work", |
| const char * | pattern = 0 |
||
| ) |
Print to stdout, one per line, the names of the entries of dirname that contain pattern (all if pattern is null).
A failed opendir() is not checked.
| std::vector< std::string > psalg::files_in_dir | ( | const char * | dirname = "/reg/neh/home/dubrovin/LCLS/con-detector/work", |
| const char * | pattern = 0 |
||
| ) |
Return the sorted paths dirname + "/" + name of the entries of dirname ("." and ".." included) whose names contain pattern, or all entries if pattern is null.
A failed opendir() is not checked. The default dirname is a hard-coded /reg/neh/home/dubrovin path.
| void psalg::fill_ndarray_const | ( | NDArray< T > & | a, |
| const T & | c | ||
| ) |
Set every element of a to c.
| void psalg::fill_ndarray_normal | ( | NDArray< T > & | a, |
| double | mean = 0, |
||
| double | stddev = 1 |
||
| ) |
Set every element of a to a sample from a normal distribution with the given mean and stddev, cast to T.
A default-constructed std::default_random_engine is used, so every call produces the same sequence.
| void psalg::fill_ndarray_random | ( | NDArray< T > & | a, |
| int | range = 100 |
||
| ) |
Set every element of a to std::rand() % range, cast to T.
| const rapidjson::Value & psalg::find_doc | ( | rapidjson::Document & | outdocs, |
| const char * | dbname, | ||
| const char * | colname, | ||
| const char * | query = NULL, |
||
| const char * | urlws = URLWS |
||
| ) |
Run find_docs(), parse the response into outdocs, and return the element with the largest "time_sec" if query contains "time_sec", else the largest "run".
Returns EMPTY_VALUE with a WARNING if the response is not an array or is empty; query must not be NULL. The returned reference points into outdocs.
| void psalg::find_docs | ( | std::string & | sresp, |
| const char * | dbname, | ||
| const char * | colname, | ||
| const char * | query = NULL, |
||
| const char * | urlws = URLWS |
||
| ) |
GET the URL built by string_url_with_query() and store the raw response in sresp.
| index_t psalg::find_edges | ( | index_t | npkmax, |
| T * | pkvals, | ||
| index_t * | pkinds, | ||
| const std::vector< T > & | wf, | ||
| double | baseline, | ||
| double | threshold, | ||
| double | fraction, | ||
| double | deadtime, | ||
| bool | leading_edge | ||
| ) |
Find pulses in wf that go beyond threshold (above it if threshold > baseline, else below) for more than deadtime samples; for each, store its extreme value in pkvals and the interpolated index of the edge at level fraction*(peak-baseline)+baseline in pkinds (leading edge, or with leading_edge false the trailing edge searched from the peak).
Edges within deadtime of the previous one are skipped and at most npkmax peaks are stored. Instantiated in WFAlgos.cc for double, float, int, int64_t and int16_t.
| void psalg::get_data_for_doc | ( | std::string & | sresp, |
| const char * | dbname, | ||
| const char * | colname, | ||
| const rapidjson::Value & | jdoc, | ||
| const char * | urlws = URLWS |
||
| ) |
Call get_data_for_docid() with the "_id" string member of jdoc.
| void psalg::get_data_for_docid | ( | std::string & | sresp, |
| const char * | dbname, | ||
| const char * | colname, | ||
| const char * | docid, | ||
| const char * | urlws = URLWS |
||
| ) |
Fetch document docid (get_doc_for_docid()), then fetch into sresp the data whose id is the document's "id_data" string (get_data_for_id()).
| void psalg::get_data_for_id | ( | std::string & | sresp, |
| const char * | dbname, | ||
| const char * | dataid, | ||
| const char * | urlws = URLWS |
||
| ) |
GET urlws/dbname/gridfs/dataid and store the raw response bytes in sresp.
| void psalg::get_doc_for_docid | ( | rapidjson::Document & | jdoc, |
| const char * | dbname, | ||
| const char * | colname, | ||
| const char * | docid, | ||
| const char * | urlws = URLWS |
||
| ) |
GET urlws/dbname/colname/docid and parse the response into jdoc.
| std::string psalg::json_doc_to_string | ( | const rapidjson::Value & | d | ) |
Serialize d to a compact JSON string with rapidjson::Writer.
| void psalg::json_doc_to_vector_of_strings | ( | const rapidjson::Value & | doc, |
| std::vector< std::string > & | vout | ||
| ) |
Clear vout and, if doc is a non-empty array, fill it with the array's string elements.
| std::string psalg::json_value_type | ( | const rapidjson::Value & | v | ) |
Return a type name for v: "string", "int" (also used for booleans), "number", "object", "array", or a "Non-implemented type: " string for other types (e.g.
null).
| std::string psalg::ltrim | ( | const std::string & | str | ) |
Return a copy of str without leading whitespace (space, newline, carriage return, tab, form feed, vertical tab); empty if str is all whitespace.
| void psalg::print_byte_string_as_float | ( | const std::string & | s, |
| const size_t | nvals = 100 |
||
| ) |
Reinterpret the bytes of s as floats and print their count and the first nvals values to stdout.
nvals is not limited to the data size.
| void psalg::print_json_doc | ( | const rapidjson::Value & | doc, |
| const std::string & | offset = " " |
||
| ) |
Recursively print doc to stdout with a type label per value, indenting nested levels by 4 spaces plus offset; strings are cut to 1000 characters.
| void psalg::print_json_doc_as_string | ( | const rapidjson::Value & | value | ) |
Print "In print_json_doc_as_string: " followed by json_doc_to_string(value) to stdout.
| void psalg::print_vector_of_strings | ( | const std::vector< std::string > & | v, |
| const char * | gap = " == " |
||
| ) |
Print "In print_vector_of_strings" and then each string of v prefixed by gap, one per line, to stdout.
| void psalg::request | ( | std::string & | sresp, |
| const char * | url = URLWS |
||
| ) |
HTTP GET url with libcurl and store the response body in sresp (cleared first).
Logs a WARNING if no content type is received; errors from curl_easy_perform() are not reported.
| void psalg::response_string_to_data_array | ( | const std::string & | s, |
| const TDATA *& | pout, | ||
| size_t & | size | ||
| ) |
Point pout at the bytes of s reinterpreted as TDATA and set size to s.size()/sizeof(TDATA).
Nothing is copied, so pout is valid only while s is unchanged. Instantiated in MDBWebUtils.cc for int, float, double, uint16_t and uint32_t.
| void psalg::response_to_json_doc | ( | const std::string & | sresp, |
| rapidjson::Document & | |||
| ) |
Parse sresp as JSON into the given document (chars_to_json_doc()).
| std::string psalg::rtrim | ( | const std::string & | str | ) |
Return a copy of str without trailing whitespace (space, newline, carriage return, tab, form feed, vertical tab); empty if str is all whitespace.
| void psalg::string_url_with_query | ( | std::string & | surl, |
| const char * | dbname, | ||
| const char * | colname, | ||
| const char * | query = NULL, |
||
| const char * | urlws = URLWS |
||
| ) |
Set surl to urlws/dbname/colname, followed by "?query_string=" and the URL-escaped query if query is not NULL.
| std::string psalg::strip | ( | const std::string & | str | ) |
Return a copy of str with every whitespace character removed (std::isspace in the classic locale).
| std::string psalg::trim | ( | const std::string & | str | ) |
Return rtrim(ltrim(str)).
| const rapidjson::Value & psalg::value_from_json_doc | ( | const rapidjson::Value & | doc, |
| const char * | valname | ||
| ) |
Return doc[valname], or EMPTY_VALUE if doc has no such member.
|
static |
Null rapidjson::Value returned by find_doc() and value_from_json_doc() when nothing is found.
Declared static, so each translation unit has its own copy.
|
static |
Default base URL of the calibration web service, "https://pswww.slac.stanford.edu/calib_ws".