DB Class Reference
|
Ratpac-two
|
Public Member Functions | |
| DB () | |
| int | Load (std::string filename, bool printPath=false) |
| int | LoadTable (DBTable *table) |
| int | LoadFile (std::string filename) |
| int | LoadAll (std::string dirname, std::string pattern="*.ratdb") |
| int | LoadDefaults () |
| void | Clear () |
| void | SetServer (std::string url) |
| void | SetDefaultRun (int _run) |
| int | GetDefaultRun () const |
| DBLinkPtr | GetLink (std::string tblname, std::string index="") |
| DBLinkPtr | GetLink (std::string tblname, std::string index, int run) |
| DBLinkGroup | GetLinkGroup (std::string tblname) |
| const DBTableSet & | GetAllTables () |
| template<typename T > | |
| void | Set (const std::string &tblname, const std::string &fieldname, const T &val) |
| template<typename T > | |
| void | Set (const std::string &tblname, const std::string &index, const std::string &fieldname, const T &val) |
| template<typename T > | |
| void | SetArrayIndex (const std::string &tblname, const std::string &fieldname, size_t idx, const T &val) |
| template<typename T > | |
| void | SetArrayIndex (const std::string &tblname, const std::string &index, const std::string &fieldname, size_t idx, const T &val) |
| void | DumpContentsToJson (std::ostream &stream) |
| DBTable * | GetUserTable (std::string tblname, std::string index) |
| DBTable * | GetRunTable (std::string tblname, std::string index, int runNumber) |
| DBTable * | GetDefaultTable (std::string tblname, std::string index) |
| void | RemoveLink (DBLink *link) |
| int | NumLinks () |
| virtual std::vector< int > | FetchIArray (const std::string &tableID, const std::string &fieldname) |
| virtual std::vector< double > | FetchDArray (const std::string &tableID, const std::string &fieldname) |
Static Public Member Functions | |
| static DB * | Get () |
| static bool | ParseTableName (std::string descriptor, std::string &table, std::string &index) |
| static std::vector< RAT::DBTable * > | ReadRATDBFile (const std::string &filename) |
Protected Member Functions | |
| DBTable * | FindTable (std::string tblname, std::string index, int runNumber) |
| DBTable * | FindOrCreateTable (std::string tblname, std::string index, int runNumber) |
Protected Attributes | |
| std::list< RAT::DBLink * > | links |
| std::string | server |
| std::set< std::string > | tableNamesOnServer |
| std::set< RAT::DBTableKey > | tablesNotOnServer |
| HTTPDownloader | downloader |
| DBTableSet | tables |
| std::deque< std::pair< RAT::DBTableKey, bool > > | tablesFromServer |
| int | run |
Static Protected Attributes | |
| static DB * | primary |
Constructor & Destructor Documentation
◆ DB()
| DB::DB | ( | ) |
Create new database in memory with no tables.
Member Function Documentation
◆ Clear()
| void DB::Clear | ( | ) |
Delete all tables from memory.
◆ DumpContentsToJson()
| void DB::DumpContentsToJson | ( | std::ostream & | stream | ) |
Dump all tables in the db to a JSON file.
- Todo:
- : Currently doesn't support server tables
◆ FindOrCreateTable()
|
protected |
Obtain a pointer to a table in memory, or create it if not found.
- Returns
- Pointer to existing table, or pointer to new table, which is also added to
tblset.
◆ FindTable()
|
protected |
Obtain a pointer to a table loaded in memory.
- Returns
- Pointer to table if found, otherwise 0.
◆ Get()
|
inlinestatic |
Obtain pointer to global database
Unless you want a private database, this is the method you should use to obtain a pointer to DB. If the global database has not yet been constructed, it will be constructed when you call this function.
◆ GetAllTables()
|
inline |
Obtain a reference to all tables stored in the databse.
This is useful if you want to iterate over all the tables in the database.
- Todo:
- : Should also implement this for server tables.
◆ GetDefaultRun()
| int DB::GetDefaultRun | ( | ) | const |
Get the default run number used for new links
◆ GetDefaultTable()
|
inline |
Get pointer to a table in default plane: do not use unless you know what you are doing!
◆ GetLink() [1/2]
| DBLinkPtr DB::GetLink | ( | std::string | tblname, |
| std::string | index, | ||
| int | run | ||
| ) |
Obtain a link to a particular table and index with given run.
If you have an empty index, pass "" as the index value.
◆ GetLink() [2/2]
| DBLinkPtr DB::GetLink | ( | std::string | tblname, |
| std::string | index = "" |
||
| ) |
Obtain a link to a particular table and index with default run.
Note that even if your table does not have an index value, you should still use this method, but with an empty index. (The default value)
◆ GetLinkGroup()
| DBLinkGroup DB::GetLinkGroup | ( | std::string | tblname | ) |
Obtain a link to all tables with the same name, but different indexes.
LinkGroups are useful if you want to step through all the instances of the same kind of table, like GEO.
◆ GetRunTable()
|
inline |
Get pointer to a table in run plane: do not use unless you know what you are doing!
◆ GetUserTable()
|
inline |
Get pointer to a table in user plane: do not use unless you know what you are doing!
◆ Load()
| int DB::Load | ( | std::string | filename, |
| bool | printPath = false |
||
| ) |
Load a DB text file or directory of text files in search path.
If passed the name of a file, this function will load all the DB tables it contains into memory. If passed the name of a directory, all of the files in that directory ending in .ratdb will be loaded.
The current directory is searched first, then the $RATSHARE/ratdb directory.
If printFullPath is true, then an info message is printed to stdout (and logged) indicating the path of the file that is loaded. Shows whether $RATSHARE/ratdb was used.
◆ LoadAll()
| int DB::LoadAll | ( | std::string | dirname, |
| std::string | pattern = "*.ratdb" |
||
| ) |
Load all of the DB files in a directory.
Searches dirname for all files matching pattern. Does not search $RATSHARE/ratdb automatically, so a path relative to current directory or an absolute path much be given.
◆ LoadDefaults()
| int DB::LoadDefaults | ( | ) |
Load standard tables into memory.
Currently, the standard tables are $RATSHARE/ratdb/ *.ratdb.
◆ LoadFile()
| int DB::LoadFile | ( | std::string | filename | ) |
Load DB text file of tables into memory.
This function does not search in $RATSHARE/ratdb automatically, so it must be given a file name relative to the current directory or an absolute path.
◆ LoadTable()
| int DB::LoadTable | ( | DBTable * | table | ) |
◆ NumLinks()
|
inline |
Number of still active links to this database.
This is a count of the number of links which have been given out GetLink() and GetLinkGroup(). See DB::links member for more information about what this means. This method is really just for debugging purposes.
◆ ParseTableName()
|
static |
Parse a table name written in the "TABLE" or "TABLE[index]" format.
Handy method for when you are getting a table name from user input. Separates the table name from the index name.
- Parameters
-
[in] descriptor String in the form "TABLE" or "TABLE[index]" [out] table Just the table name [out] index Just the index name. Empty string if no index.
- Returns
- True if
descriptorwas a properly formatted table name.
◆ ReadRATDBFile()
|
static |
Reads a file and returns all the RATDB tables found inside. Works with both RATDB native and JSON files
◆ RemoveLink()
| void DB::RemoveLink | ( | DBLink * | link | ) |
◆ Set() [1/2]
| void DB::Set | ( | const std::string & | tblname, |
| const std::string & | fieldname, | ||
| const T & | val | ||
| ) |
Set field in user plane, no table index.
◆ Set() [2/2]
| void DB::Set | ( | const std::string & | tblname, |
| const std::string & | index, | ||
| const std::string & | fieldname, | ||
| const T & | val | ||
| ) |
Set field in user plane, with table index.
◆ SetArrayIndex() [1/2]
| void DB::SetArrayIndex | ( | const std::string & | tblname, |
| const std::string & | fieldname, | ||
| size_t | idx, | ||
| const T & | val | ||
| ) |
Set array field index in user plane, no table index.
◆ SetArrayIndex() [2/2]
| void DB::SetArrayIndex | ( | const std::string & | tblname, |
| const std::string & | index, | ||
| const std::string & | fieldname, | ||
| size_t | idx, | ||
| const T & | val | ||
| ) |
Set array field index in user plane, with table index.
◆ SetDefaultRun()
| void DB::SetDefaultRun | ( | int | _run | ) |
Set default run number for new links.
◆ SetServer()
| void DB::SetServer | ( | std::string | url | ) |
Set URL of CouchDB server containing RATDB tables
Member Data Documentation
◆ downloader
|
protected |
Helper class to download files over HTTP/HTTPS
◆ links
|
protected |
List of DBLinks which have been issued by GetLink() or GetLinkGroup().
In order to allow a DBLink to do local caching of values, the DB object must retain pointers to all of the previously issued link objects. Then, if something changes, like new tables are loaded or become valid, DB can go out and expire the relevant cached values inside the affected DBLinks.
In the DBLink destructor, RemoveLink() is called to remove the link from the list before its memory is reclaimed.
◆ primary
◆ run
|
protected |
Current run number, used to set all new DBLinks.
◆ server
|
protected |
URL to CouchDB server. Empty string means no server will be used.
◆ tableNamesOnServer
|
protected |
Cache of table names present on the CouchDB server. Check this before issuing a query.
◆ tables
|
protected |
Set of all tables. Run 0 signifies default and run -1 is user-override.
◆ tablesFromServer
|
protected |
FIFO of tables fetched from the server. Second element of pair is indicates if the size from this key "is real". When the same table is added for multiple runs, only the last run should be set to true.
◆ tablesNotOnServer
|
protected |
Cache of full table keys (name, index, run) that are not on the server. Important to cut down on needless network traffic from future queries once a rejection has been received.
The documentation for this class was generated from the following files:
- /home/docs/checkouts/readthedocs.org/user_builds/ratpac/checkouts/latest/src/db/include/RAT/DB.hh
- /home/docs/checkouts/readthedocs.org/user_builds/ratpac/checkouts/latest/src/db/src/DB.cc
Generated by