dqsegdb Package

dqsegdb Package

apicalls Module

dqsegdb.apicalls.InsertMultipleDQXMLFileThreaded(filenames, logger, server='http://slwebtest.virgo.infn.it', hackDec11=False, debug=True, threads=1, testing_options={})[source]

Inserts multiple dqxml files of data into the DQSEGDB.

Input: - filenames is a list of string filenames for DQXML files. - hackDec11 is deprecated (always should be false): This was used to differentiate function against different server APIs before we used numbering an responses to make decisions. - testing_options is a dictionary including (optionally):offset(int),synchronize(time in ‘HH:MM’ format (string))

Output: returns True if it completes sucessfully

dqsegdb.apicalls.coalesceResultDictionary(result_dict)[source]

Takes a dictionary as returned by QueryTimes or QueryTimeless and converts the lists of tuples into actual segment lists (and coalesces them).

Parameters
result_dictdict

This is the input result dictionary from the other api calls

out_result_dictdict

This is the output result dictionary with actual segment lists (and coalesced results).

dqsegdb.apicalls.dqsegdbCascadedQuery(protocol, server, ifo, name, include_list_string, startTime, endTime, debug=False, warnings=True)[source]

Queries server for needed flag_versions to generate the result of a cascaded query (was called a versionless query in S6).

Returns a python dictionary representing the calculated result “versionless” flag and also the python dictionaries (in a list) for the flag_versions necessary to construct the result.

Parameters
protocolstring

Ex: ‘https’

serverstring

Ex: ‘dqsegdb5.phy.syr.edu’

ifostring

Ex: ‘L1’

name: `string`

Ex: ‘DMT-SCIENCE’

versionstring or int

Ex: ‘1’

include_list_stringstring

Ex: “metadata,known,active”

startTimeint

Ex: 999999999

endTimeint

Ex: 999999999

debugbool

Ex: False

warningsbool

show warnings for HTTPError (as well as raising exception), default: True

dqsegdb.apicalls.dqsegdbCheckVersion(protocol, server, ifo, name, version, warnings=True)[source]

Checks for existence of a given version of a flag in the db. Returns true if version exists

Parameters
protocolstring

Ex: ‘https’

serverstring

Ex: ‘dqsegdb5.phy.syr.edu’

ifostring

Ex: ‘L1’

name: `string`

Ex: ‘DMT-SCIENCE’

versionstring or int

Ex: ‘1’

warningsbool

show warnings for HTTPError (as well as raising exception), default: True

dqsegdb.apicalls.dqsegdbFindEndTime(flag_dict)[source]

Determines max end_time from known times in flag_dict

Parameters
flag_dict: `dictionary`

Input dictionary, converted from json using json.loads in previous call

Returns max_end_time: `int`
dqsegdb.apicalls.dqsegdbMaxVersion(protocol, server, ifo, name)[source]

Checks for existence of a flag in the db, returns maximum version if the flag exists exists, 0 if the flag does not exist.

Parameters
protocolstring

Ex: ‘https’

serverstring

Ex: ‘dqsegdb5.phy.syr.edu’

ifostring

Ex: ‘L1’

name: `string`

Ex: ‘DMT-SCIENCE’

dqsegdb.apicalls.dqsegdbQueryTimeless(protocol, server, ifo, name, version, include_list_string, warnings=True)[source]

Issue query to server for ifo:name:version without start and end time Returns the python loaded JSON response converted into a dictionary and queryurl! Returns ———- [dictionary,string(url)]

Parameters
protocolstring

Ex: ‘https’

serverstring

Ex: ‘dqsegdb5.phy.syr.edu’

ifostring

Ex: ‘L1’

name: `string`

Ex: ‘DMT-SCIENCE’

versionstring or int

Ex: ‘1’

include_list_stringstring

Ex: “metadata,known,active”

warningsbool

show warnings for HTTPError (as well as raising exception), default: True

dqsegdb.apicalls.dqsegdbQueryTimes(protocol, server, ifo, name, version, include_list_string, startTime, endTime, warnings=True)[source]

Issue query to server for ifo:name:version with start and end time Returns the python loaded JSON response!

Parameters
protocolstring

Ex: ‘https’

serverstring

Ex: ‘dqsegdb5.phy.syr.edu’

ifostring

Ex: ‘L1’

name: `string`

Ex: ‘DMT-SCIENCE’

versionstring or int

Ex: ‘1’

include_list_stringstring

Ex: “metadata,known,active”

startTimeint

Ex: 999999999

endTimeint

Ex: 999999999

warningsbool

show warnings for HTTPError (as well as raising exception), default: True

dqsegdb.apicalls.dqsegdbQueryTimesCompatible(protocol, server, ifo, name, version, include_list_string, startTime, endTime, warnings=True)[source]

Issue query to server for ifo:name:version with start and end time This is the version that reproduces S6 style query results when the query is empty Returns the python loaded JSON response!

Parameters
protocolstring

Ex: ‘https’

serverstring

Ex: ‘dqsegdb5.phy.syr.edu’

ifostring

Ex: ‘L1’

name: `string`

Ex: ‘DMT-SCIENCE’

versionstring or int

Ex: ‘1’

include_list_stringstring

Ex: “metadata,known,active”

startTimeint

Ex: 999999999

endTimeint

Ex: 999999999

warningsbool

show warnings for HTTPError (as well as raising exception), default: True

dqsegdb.apicalls.dtd_uri_callback(uri)[source]

S6 helper function for XML file writing and parsing using a dtd.

dqsegdb.apicalls.parseKnown(jsonResult)[source]

Accepts jsonResult from reportKnown call and parses into expected format for ligolw_segment_query client to generate xml.

dqsegdb.apicalls.patchWithFailCases(i, url, debug=True, inlogger=None, testing_options={})[source]

Attempts to patch data to a url where the data is in a dictionary format that can be directly dumped to json that the dqsegdb server expects. Correctly fails to making a new version or flag in the database as needed.

dqsegdb.apicalls.queryAPIVersion(protocol, server, verbose, warnings=True)[source]

Construct url and issue query to get the reported list of all IFOs provided by dqsegd and the API version of the server.

Parameters
protocolstring

Ex: ‘https’

serverstring

Ex: ‘dqsegdb5.phy.syr.edu’

warningsbool

show warnings for HTTPError (as well as raising exception), default: True

dqsegdb.apicalls.reportActive(protocol, server, includeSegments, verbose, gps_start_time, gps_end_time, warnings=True)[source]

Construct url and issue query to get the reported list of all active segments for all flags in the time window provided. From the API Doc: Get a JSON string resource containing the active segments for all flags between t1 and t2. Note that this returns exactly what /dq/IFO/FLAG/VERSION does, except for ALL flags over the query period instead of one flag. The clients must assume that they may get empty active lists for flags that are unactive between times t1 and t2.

Parameters
protocolstring

Ex: ‘https’

serverstring

Ex: ‘dqsegdb5.phy.syr.edu’

includeSegmentsboolean

Ex: True

verboseboolean

Ex: True

gps_start_time: `int`

Ex: 999999999

gps_end_time: `int`

Ex: 999999999

warningsbool

show warnings for HTTPError (as well as raising exception), default: True

dqsegdb.apicalls.reportFlags(protocol, server, verbose, warnings=True)[source]

Construct url and issue query to get the reported list of all flags provided by dqsegdb. From the API Doc: Get a JSON formatted string resource describing all the flags in the database. This provides an optimization by returning all flag names and all associated versions in a single call.

Parameters
protocolstring

Ex: ‘https’

serverstring

Ex: ‘dqsegdb5.phy.syr.edu’

warningsbool

show warnings for HTTPError (as well as raising exception), default: True

dqsegdb.apicalls.reportKnown(protocol, server, includeSegments, verbose, gps_start_time, gps_end_time, warnings=True)[source]

Construct url and issue query to get the reported list of all known segments for all flags in the time window provided. From the API Doc: Get a JSON string resource containing the known segments for all flags between t1 and t2. Note that this returns exactly what /dq/IFO/FLAG/VERSION/known does, except for ALL flags over the query period instead of one flag. The clients must assume that they may get empty known lists for flags that are unknown between times t1 and t2.

Parameters
protocolstring

Ex: ‘https’

serverstring

Ex: ‘dqsegdb5.phy.syr.edu’

includeSegmentsboolean

Ex: True

verboseboolean

Ex: True

gps_start_time: `int`

Ex: 999999999

gps_end_time: `int`

Ex: 999999999

warningsbool

show warnings for HTTPError (as well as raising exception), default: True

dqsegdb.apicalls.setupSegment_md(filename, xmlparser, lwtparser, debug)[source]

Helper function used to setup ligolw parser (S6 xml generation tool).

dqsegdb.apicalls.threadedPatchWithFailCases(q, server, debug, inputlogger=None)[source]

Used by InsertMultipleDQXMLFileThreaded to patch data to server. (Deprecated/Incomplete error handling)

dqsegdb.apicalls.waitTill(runTime, timeout=2400)[source]

runTime is time in HH:MM (string) format, action is call to a function to be exceuted at specified time. Function source: http://stackoverflow.com/a/6579355/2769157

clientutils Module

class dqsegdb.clientutils.ShowTypesResult[source]

Bases: object

get_pyvalue(self)[source]
ifos
name
segment_definer_comment
segment_summary_comment
segment_summary_end_time
segment_summary_start_time
version
class dqsegdb.clientutils.ShowTypesResultTable(*args)[source]

Bases: glue.ligolw.table.Table

RowType

alias of ShowTypesResult

tableName = 'show_types_result:table'
validcolumns = {'ifos': 'lstring', 'name': 'lstring', 'segment_definer_comment': 'lstring', 'segment_summary_comment': 'lstring', 'segment_summary_end_time': 'int_4s', 'segment_summary_start_time': 'int_4s', 'version': 'int_4s'}
dqsegdb.clientutils.add_segment_info_ns(doc, proc_id, segdefs, segments, segment_summaries)[source]
dqsegdb.clientutils.add_to_segment_ns(xmldoc, proc_id, seg_def_id, sgmtlist)[source]
dqsegdb.clientutils.add_to_segment_summary_ns(xmldoc, proc_id, seg_def_id, sgmtlist, comment='')[source]
dqsegdb.clientutils.calculate_combined_result(includedJSON, excludedJSON, startTime, endTime, ifo)[source]

Calculate the result of the union of the active times for the included flag less the intersection of that result with the union of the excluded flags Inputs are 2 lists of python dictionaries representing the JSON (already have run json.loads() on the JSON), a start time, and end time, and the ifo name (it does not make sense to include/exclude across multiple ifos)

Parameters
startTimeint

Ex: 999999999

endTimeint

Ex: 999999999

ifostring

Ex: ‘L1’

dqsegdb.clientutils.calculate_versionless_result(jsonResults, startTime, endTime, ifo_input=None)[source]

Construct output segments lists from multiple JSON objects. The jsonResults input is a list of json ojbects and are expected to be in order of decreasing versions.

dqsegdb.clientutils.include_exclude_caller(includedList, excludedList, startTime, endTime, protocol, server, include_list_string)[source]

Function to query the dqsegdb for lists of included and excluded flags. Returns lists of JSON for the included and excluded flags and lists of URLs used to query the database.

Parameters
includedListlist

List of ifo,name,version tuples

excludedListlist

List of ifo,name,version tuples

protocolstring

Ex: ‘https’

serverstring

Ex: ‘dqsegdb5.phy.syr.edu’

include_list_stringstring

Ex: “metadata,known,active”

startTimeint

Ex: 999999999

endTimeint

Ex: 999999999

dqsegdb.clientutils.output_microseconds(input_time)[source]
dqsegdb.clientutils.run_query_segments(doc, process_id, engine, gps_start_time, gps_end_time, include_segments, exclude_segments, result_name)[source]
dqsegdb.clientutils.run_query_types(doc, proc_id, connection, engine, gps_start_time, gps_end_time, included_segments)[source]
dqsegdb.clientutils.run_show_types(doc, connection, engine, gps_start_time, gps_end_time, included_segments_string, excluded_segments_string)[source]
dqsegdb.clientutils.seg_spec_to_sql(spec)[source]

Given a string of the form ifo:name:version, ifo:name:* or ifo:name constructs a SQL caluse to restrict a search to that segment definer

dqsegdb.clientutils.setup_files(dir_name, gps_start_time, gps_end_time)[source]

jsonhelper Module

class dqsegdb.jsonhelper.FlagVersion(ifo, name, version)[source]

Bases: object

Class to set up a flag version object for parsing into JSON

appendActive(self, active_segments)[source]

Appends a segmentlist of active segments to the existing active segments for the object, and coalesces.

appendKnown(self, known_segments)[source]

Appends a segmentlist of known segments to the existing known segments for the object, and coalesces.

buildFlagDictFromVersion(self)[source]
buildURL(self, server='')[source]
class dqsegdb.jsonhelper.InsertFlagVersion(ifo, name, version)[source]

Bases: dqsegdb.jsonhelper.PatchFlagVersion

Class to set up a flag version object for parsing into JSON

Class to extend basic flag version class to include insert_history

Adds metadata for initial inserts

buildFlagDictFromInsertVersion(self)[source]
class dqsegdb.jsonhelper.InsertFlagVersionOld(ifo, name, version)[source]

Bases: dqsegdb.jsonhelper.PatchFlagVersion

Class to set up a flag version object for parsing into JSON

Class to extend basic flag version class to include insert_history

Adds metadata for initial inserts

buildFlagDictFromInsertVersion(self)[source]
class dqsegdb.jsonhelper.PatchFlagVersion(ifo, name, version, hackDec11=False)[source]

Bases: dqsegdb.jsonhelper.FlagVersion

Class to set up a flag version object for parsing into JSON

Class to extend basic flag version class to include insert_history

buildFlagDictFromPatchVersion(self)[source]
coalesceInsertHistory(self)[source]
dqsegdb.jsonhelper.buildFlagDict(ifo, name, version, known_segments, active_segments)[source]

Helper function to build a flag_version dictionary for JSON production.

known_segments and active_segments are assumed to be segmentlist objects Note that this currently does not generate a false “query_metadata” block

dqsegdb.jsonhelper.convertJSONtoXML(json_response)[source]

Incomplete!! Converts a standard JSON response from the dqsegdb server into a DQXML format.

dqsegdb.jsonhelper.convert_json_list_to_segmentlist(jsonlist)[source]

Helper function used to convert json list of lists type object to a segmentlist object

dqsegdb.jsonhelper.convert_segmentlist_to_json(segmentlist_input)[source]

Helper function used to convert segmentlist to json list of lists type object.

dqsegdb.jsonhelper.generated_ascii(json_str, filepath)[source]
dqsegdb.jsonhelper.generated_vdb_ascii(json_str, filepath)[source]

urifunctions Module

dqsegdb.urifunctions.constructFlagQueryURL(protocol, server, ifo)[source]

Simple url construction method for dqsegdb server flag queries.

Parameters
protocolstring

Ex: ‘https’

serverstring

Ex: ‘dqsegdb5.phy.syr.edu’

ifostring

Ex: ‘L1’

dqsegdb.urifunctions.constructSegmentQueryURL(protocol, server, ifo, name, version, include_list_string)[source]

Simple url construction method for dqsegdb server flag:version queries not including restrictions on time ranges.

Parameters
protocolstring

Ex: ‘https’

serverstring

Ex: ‘dqsegdb5.phy.syr.edu’

ifostring

Ex: ‘L1’

name: `string`

Ex: ‘DMT-SCIENCE’

versionstring or int

Ex: ‘1’

include_list_stringstring

Ex: “metadata,known,active”

dqsegdb.urifunctions.constructSegmentQueryURLTimeWindow(protocol, server, ifo, name, version, include_list_string, startTime, endTime)[source]

Simple url construction method for dqsegdb server flag:version queries including restrictions on time ranges.

Parameters
protocolstring

Ex: ‘https’

serverstring

Ex: ‘dqsegdb5.phy.syr.edu’

ifostring

Ex: ‘L1’

name: `string`

Ex: ‘DMT-SCIENCE’

versionstring or int

Ex: ‘1’

include_list_stringstring

Ex: “metadata,known,active”

startTimeint

Ex: 999999999

endTimeint

Ex: 999999999

dqsegdb.urifunctions.constructVersionQueryURL(protocol, server, ifo, name)[source]

Simple url construction method for dqsegdb server version queries.

Parameters
protocolstring

Ex: ‘https’

serverstring

Ex: ‘dqsegdb5.phy.syr.edu’

ifostring

Ex: ‘L1’

name: `string`

Ex: ‘DMT-SCIENCE’

dqsegdb.urifunctions.getDataUrllib2(url, timeout=900, logger=None, warnings=True, **urlopen_kw)[source]

Return response from server

Parameters
urlstr

remote URL to request (HTTP or HTTPS)

timeoutfloat

time (seconds) to wait for reponse

loggerlogging.Logger

logger to print to

**urlopen_kw

other keywords are passed to urllib.request.urlopen()

Returns
responsestr

the text reponse from the server

dqsegdb.urifunctions.handleHTTPError(method, url, e)[source]
dqsegdb.urifunctions.patchDataUrllib2(url, payload, timeout=900, logger=None, **urlopen_kw)[source]

Wrapper method for urllib2 that supports PATCHs to a url.

Parameters
urlstring

Ex: ‘https://dqsegdb5.phy.syr.edu/L1/DMT-SCIENCE/1

payloadstring

JSON formatted string

dqsegdb.urifunctions.putDataUrllib2(url, payload, timeout=900, logger=None, **urlopen_kw)[source]

Wrapper method for urllib2 that supports PUTs to a url.

Parameters
urlstring

Ex: ‘https://dqsegdb5.phy.syr.edu/L1/DMT-SCIENCE/1

payloadstring

JSON formatted string

version Module

dqsegdb._version.get_versions()[source]