|
lcls2
C++ API: public headers of xtcdata, psalg, psdaq and psana
|
Declares helpers for the calibration web service: libcurl HTTP requests, rapidjson parsing and printing, document lookup, and retrieval of calibration constants. More...
#include <map>#include <string>#include <vector>#include <stdint.h>#include <rapidjson/document.h>#include "psalg/calib/NDArray.hh"Namespaces | |
| namespace | psalg |
| Usage. | |
Functions | |
| 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_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_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::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 | 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. | |
| std::string | psalg::json_doc_to_string (const rapidjson::Value &d) |
| Serialize d to a compact JSON string with rapidjson::Writer. | |
| 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. | |
| rapidjson::Document | psalg::chars_to_json_doc (const char *s) |
| Declared here; no definition was found in MDBWebUtils.cc. | |
| 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. | |
| 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::response_to_json_doc (const std::string &sresp, rapidjson::Document &) |
| Parse sresp as JSON into the given document (chars_to_json_doc()). | |
| 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. | |
| void | psalg::request (std::string &sresp, const char *url=URLWS) |
| HTTP GET url with libcurl and store the response body in sresp (cleared first). | |
| 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). | |
| 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::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 & | 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". | |
| 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. | |
| 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. | |
| 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_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_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 | psalg::db_prefixed_name (const char *name, const char *prefix="cdb_") |
| Return prefix + name (e.g. | |
| 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". | |
| 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. | |
| 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()). | |
| template<typename T > | |
| 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. | |
| 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. | |
| template<typename TDATA > | |
| 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). | |
Variables | |
| static const char * | psalg::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 | psalg::EMPTY_VALUE |
| Null rapidjson::Value returned by find_doc() and value_from_json_doc() when nothing is found. | |
Declares helpers for the calibration web service: libcurl HTTP requests, rapidjson parsing and printing, document lookup, and retrieval of calibration constants.