BdsApi  2.2.6
This is the Blacknest BDS API.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
BdsApi Documentation
Author
Dr Terry Barnaby
Version
2.2.6
Date
2021-05-24

Introduction

This document provides detailed reference information for the BEAM BdsApi software API of the Blacknest Data System (BDS). The API provides the ability to store and access seismic sensor data and metadata as well as administer the BDS system. The API is an object orientated API implemented in 'C++' with a number of object classes. It also has bindings for other languages which include Python and PHP.

The API operates over a network type interface using an RPC type mechanism implemented by BEAM's BOAP RPC system. The BdsApi API makes use of the BEAM 'C++' class library for lower level and system independent functionality. The BEAM 'C++' class library provides a small set of low level 'C++' classes for strings, lists and system interface functions. It also implements the BOAP RPC mechanism used to implement the BdsApi. There is some brief information on the BEAM class library later on in this page and a full API definition is available in the beam-lib documentation.

The BDS Python API is built on top of the standard BDS 'C++' API using the SWIG API generator. Thus all of the standard BDS C++ API documentation applies however there are some differences due to the language facility and syntax differences. The core difference is when returning data from functions. With C++ you can return data by passing references or pointers to objects. In Python this is not generally possible and so objects are returned at the left hand side of functions instead.

This is the reference documentation for the BdsApi. An overall API description and programming manual is provided separately in: BdsDevelopment.pdf

Overview

The BdsApi has been developed using the BOAP (BEAM Object Access Protocol). This provides a simple but powerful Object Orientated RPC mechanism. The BdsApi is written in a high level interface definition language (IDL). The bidl tool generates the client and server side 'C++' interface and implementation files for the API. These are then provided as a set of 'C++' header files and a binary library file for the clients to link to. The BOAP system employs a simple BOAP name server process that provides a translation between object names and network IPAddress/Socket numbers. The BOAP name server runs on the main BDS Server host. More information on the BOAP system can be found in the beam-lib documentation.

The object orientated BDS API implements a number of data storage classes and three BdsServer interface objects. The interface objects are:

  1. Bds::DataAccess BDS Data API: This provides read only access to the data and meta data. It is used by the AutoDRM email and Web systems as well as for user and general program access to the data.
  2. Bds::DataAddAccess BDS DataAdd API: This provides read and restricted write access to enable the adding of data to the system. It will not allow deletions of data to be performed. It is designed to be used by manual and automatic data adding programs.
  3. Bds::AdminAccess BDS Admin API: This provides full read/write access to the data and meta data as well as administrative configuration information.

These access API's are released in that the DataAddAccess API is a subset of the AdminAccess API and the DataAccess API is a subset of the DataAddAccess API. These API access objects should be consulted to view the functionality provided by the BDS system API's.

C++ Examples

There are some examples of client applications using the BdsApi in the bdsExamples directory of the source code. Some simple Data Access client examples are listed below:

/*******************************************************************************
* BdsDataClient1.cpp BDS API example code for a Data Client
* T.Barnaby, BEAM Ltd, 2008-09-02
*******************************************************************************
*
* This is a very basic example of using the BdsApi from a data access
* perspective. It is designed to give an overview of using the API.
* This program gets data in the BKNAS format.
*/
#include <iostream>
#include <stdio.h>
#include <BdsD.h>
#include <BdsC.h>
using namespace Bds;
using namespace std;
// Function to read some data
BError bdsTest(DataAccess& bds){
BError err;
Selection selection;
DataInfo dataInfo;
DataHandle dataHandle;
// Set up selection
#ifndef ZAP
selection.startTime.setString("2002-01-01T00:00:00.000000");
selection.endTime.setString("2002-01-01T00:01:00.000000");
#else
selection.startTime.setString("2002-01-01T23:59:00.000000");
selection.endTime.setString("2002-01-02T00:01:00.000000");
#endif
selection.channels.append(SelectionChannel("BN", "EKA", "", ""));
// Get list of all data available for the selection
if(err = bds.dataSearch(selection, dataInfo)){
return err.set(1, BString("Error: Searching for data: ") + err.getString());
}
// We should now choose which set of data we would like from the list, here we just
// choose the first entry and get the data in appropriate format.
if(!dataInfo.channels.size())
return err.set(1, "No data found");
if(err = bds.dataOpen(dataInfo, "r", "IMS", 0, dataHandle)){
return err;
}
while(1){
if(err = bds.dataFormattedRead(dataHandle, 1024, data)){
return err;
}
if(data.size() == 0)
break;
fwrite(data.data(), 1, data.size(), stdout);
}
return err;
}
int main(int argc, char** argv){
BError err;
BString hostName;
hostName = getenv("BDS_HOST");
if(hostName == "")
hostName = "localhost";
if(argc == 2)
hostName = argv[1];
// Connect to the DataAccess service
if(err = bds.connectService(BString("//") + hostName + "/bdsDataAccess")){
cerr << "Error: " << err.getString() << "\n";
return 1;
}
// Connect to service
if(!err)
err = bds.connect("test", "beam00");
// Run a normal data gathering as a normal data access client would.
if(!err)
err = bdsTest(bds);
if(err){
cerr << "Error: " << err.getString() << "\n";
return 1;
}
return 0;
}
/*******************************************************************************
* BdsDataClient2.cpp BDS API example code for a Data Client
* T.Barnaby, BEAM Ltd, 2008-09-02
*******************************************************************************
*
* This is a very basic example of using the BdsApi from a data access
* perspective. It is designed to give an overview of using the API.
* This program gets data in raw format and outputs it in ASCII.
*/
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <BdsD.h>
#include <BdsC.h>
using namespace Bds;
using namespace std;
// Function to read some data
BError bdsTest(DataAccess& bds){
BError err;
Selection selection;
DataInfo dataInfo;
DataHandle dataHandle;
DataBlock data;
BUInt32 blockNumber = 0;
BUInt c;
BUInt s;
// Set up selection
selection.startTime.setString("2008-01-03T00:00:00.000000");
selection.endTime.setString("2008-01-03T00:01:00.000000");
selection.channels.append(SelectionChannel("BN", "EKA", "", ""));
// Get list of all data available for the selection
if(err = bds.dataSearch(selection, dataInfo)){
return err.set(1, BString("Error: Searching for data: ") + err.getString());
}
// We should now choose which set of data we would like from the list, here we just
// choose the first entry and get the data in appropriate format.
if(!dataInfo.channels.size())
return err.set(1, "No data found");
if(err = bds.dataOpen(dataInfo, "r", "API", 0, dataHandle)){
return err;
}
while(1){
if(err = bds.dataGetBlock(dataHandle, 0, 0, blockNumber, data)){
return err;
}
if(data.startTime >= dataInfo.endTime)
break;
for(s = 0; s < data.channelData[0].size(); s++){
for(c = 0; c < data.channelData.size(); c++){
if(c != 0)
std::cout << ", ";
std::cout << setw(8) << data.channelData[c][s];
}
std::cout << "\n";
}
blockNumber++;
}
return err;
}
int main(int argc, char** argv){
BError err;
BString hostName;
hostName = getenv("BDS_HOST");
if(hostName == "")
hostName = "localhost";
if(argc == 2)
hostName = argv[1];
// Connect to the DataAccess service
if(err = bds.connectService(BString("//") + hostName + "/bdsDataAccess")){
cerr << "Error: " << err.getString() << "\n";
return 1;
}
// Connect to service
if(!err)
err = bds.connect("test", "beam00");
// Run a normal data gathering as a normal data access client would.
if(!err)
err = bdsTest(bds);
if(err){
cerr << "Error: " << err.getString() << "\n";
return 1;
}
return 0;
}
/*******************************************************************************
* BdsMetaData1.cpp BDS API example code for a Meta Data Client
* T.Barnaby, BEAM Ltd, 2009-07-01
*******************************************************************************
*
* This is a very basic example of using the BdsApi from a meta data access
* perspective. It is designed to give an overview of using the API.
* This program gets information on the data channels.
*/
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <BdsD.h>
#include <BdsC.h>
using namespace Bds;
using namespace std;
// Function to read some data
BError bdsTest1(DataAccess& bds){
BError err;
Selection selection;
BIter i;
BUInt n;
BList<Station> stations;
// Set up selection
selection.startTime.setString("2008-01-03T00:00:00.000000");
selection.endTime.setString("2008-01-03T00:01:00.000000");
selection.channels.append(SelectionChannel("BN", "EKA", "", ""));
// Get list of stations available
if(err = bds.stationGetList(selection, stations)){
return err.set(1, BString("Error: Getting stations: ") + err.getString());
}
// This displays some of the information available
for(stations.start(i), n = 0; !stations.isEnd(i); stations.next(i), n++){
Station& c = stations[i];
cout << n << ": Station: " << c.name << " Type: " << c.type << "\n";
cout << " " << "Description: " << c.description
<< " Number of stations " << c.channels.number() << "\n";
}
return err;
}
int main(int argc, char** argv){
BError err;
BString hostName;
hostName = getenv("BDS_HOST");
if(hostName == "")
hostName = "localhost";
if(argc == 2)
hostName = argv[1];
// Connect to the DataAccess service
if(err = bds.connectService(BString("//") + hostName + "/bdsDataAccess")){
cerr << "Error: " << err.getString() << "\n";
return 1;
}
// Connect to service
if(!err)
err = bds.connect("test", "beam00");
// Run a normal data gathering as a normal data access client would.
if(!err)
err = bdsTest1(bds);
if(err){
cerr << "Error: " << err.getString() << "\n";
return 1;
}
return 0;
}

Python Examples

There are some examples of client applications using the BdsApi in the bdsExamples directory of the source code. Some simple Data Access client examples are listed below:

1 #!/usr/bin/python
2 ################################################################################
3 # BdsDataClient1.py BDS API example code for a BDS Data Client
4 # T.Barnaby, BEAM Ltd, 2012-12-19
5 ################################################################################
6 #
7 # Example code to show getting data from the BDS system in a particular format.
8 #
9 import sys
10 import getopt
11 from bdslib import *
12 
13 # Function to read some data
14 def bdsTest(bds):
15  err = BError();
16  selection = Selection();
17 
18  # Set up selection
19  selection.startTime.setString("2008-01-01T00:00:00.000000");
20  selection.endTime.setString("2008-01-01T00:01:00.000000");
21  print("Selection: StartTime:", selection.startTime.getString(), "EndTime:", selection.endTime.getString());
22 
23  selection.channels.append(SelectionChannel("TT", "TSB01", "", ""));
24  # bdsDumpSelection(selection);
25 
26  # Get list of all data available for the selection
27  (err, dataInfo) = bds.dataSearch(selection);
28  if(err):
29  return err.set(1, BString("Error: Searching for data: ") + err.getString());
30 
31  # We should now choose which set of data we would like from the list, here we just
32  # choose all of the data.
33  s = dataInfo.channels.size();
34  if(s == 0):
35  return err.set(1, "No data found");
36 
37  # bdsDumpDataInfo(dataInfo);
38 
39  # Open the data file for reading in IMS format
40  (err, dataHandle) = bds.dataOpen(dataInfo, "r", "IMS", 0);
41  if(err):
42  return err;
43 
44  # Read the formatted data
45  while(1):
46  # print "Loop";
47  (err, data) = bds.dataFormattedRead(dataHandle, 1024);
48  if(err):
49  return err;
50 
51  if(data.number() == 0):
52  break;
53 
54  s = "".join(chr(x) for x in data);
55  print(s);
56 
57  return err;
58 
59 def main():
60  hostName = "localhost";
61  bds = DataAccess();
62 
63  # Connect to the DataAccess service
64  err = bds.connectService("//" + hostName + "/bdsDataAccess");
65  if(err):
66  print("Error: " + str(err) + "\n");
67  return 1;
68 
69  # Connect to service
70  err = bds.connect("test", "beam00");
71  if(err):
72  print("Error: " + str(err) + "\n");
73  return 1;
74 
75  (err, version, name) = bds.getVersion();
76  if(err):
77  print("Error: " + str(err) + "\n");
78  return 1;
79  print("Version:" , version, "Name:", name);
80 
81  err = bdsTest(bds);
82  if(err):
83  print("Error:", err.getErrorNo(), err.getString());
84  return 1;
85 
86  return 0;
87 
88 if __name__ == "__main__":
89  main();
1 #!/usr/bin/python
2 ################################################################################
3 # BdsDataClient2.py BDS API example code for a BDS Data Client
4 # T.Barnaby, BEAM Ltd, 2012-12-19
5 ################################################################################
6 #
7 # Example code to show getting data from the BDS system in raw data format.
8 #
9 import sys
10 import getopt
11 from bdslib import *
12 
13 # Function to read some data
14 def bdsTest(bds):
15  err = BError();
16  selection = Selection();
17  dataInfo = DataInfo();
18 
19  # Set up selection
20  selection.startTime.setString("2008-01-01T00:00:00.000000");
21  selection.endTime.setString("2008-01-01T00:01:00.000000");
22  selection.channels.append(SelectionChannel("TT", "TSB01", "", ""));
23  # bdsDumpSelection(selection);
24 
25  # Get list of all data available for the selection
26  (err, dataInfo) = bds.dataSearch(selection);
27  if(err):
28  return err.set(1, BString("Error: Searching for data: ") + err.getString());
29 
30  # We should now choose which set of data we would like from the list, here we just
31  # choose the first entry and get the data in appropriate format.
32  s = dataInfo.channels.size();
33  if(s == 0):
34  return err.set(1, "No data found");
35 
36  # bdsDumpDataInfo(dataInfo);
37 
38  (err, dataHandle) = bds.dataOpen(dataInfo, "r", "API", 0);
39  if(err):
40  return err;
41 
42  blockNumber = 0;
43  while(1):
44  # print "Loop";
45  (err, data) = bds.dataGetBlock(dataHandle, 0, 1, blockNumber);
46  if(err):
47  return err;
48 
49  # print("DataChannels:", data.channelData.size());
50 
51  print("Data0:", data.channelData[0][0]);
52  blockNumber += 1;
53 
54  return err;
55 
56 def main():
57  hostName = "localhost";
58  bds = DataAccess();
59 
60  # Connect to the DataAccess service
61  err = bds.connectService("//" + hostName + "/bdsDataAccess");
62  if(err):
63  print("Error: " + str(err) + "\n");
64  return 1;
65 
66  # Connect to service
67  err = bds.connect("test", "beam00");
68  if(err):
69  print("Error: " + str(err) + "\n");
70  return 1;
71 
72  (err, version, name) = bds.getVersion();
73  if(err):
74  print("Error: " + str(err) + "\n");
75  return 1;
76  print("Version:" , version, "Name:", name);
77 
78  err = bdsTest(bds);
79  if(err):
80  print("Error:", err.getErrorNo(), err.getString());
81  return 1;
82 
83  return 0;
84 
85 if __name__ == "__main__":
86  main();
1 #!/usr/bin/python
2 ################################################################################
3 # BdsMetaData1.py BDS API example code for a BDS MetaData Client
4 # T.Barnaby, BEAM Ltd, 2012-12-19
5 ################################################################################
6 #
7 # This example shows how to obtain some MetaData from the BDS system.
8 # In this example it gets some information on a Station.
9 # The example assumes the BDS test data is installed.
10 #
11 import sys
12 import getopt
13 from bdslib import *
14 
15 # Function to read display info on Station
16 def bdsTest(bds):
17  err = BError();
18  selection = Selection();
19 
20  # Set up selection
21  selection.startTime.setString("2008-01-01T00:00:00.000000");
22  selection.endTime.setString("2008-01-01T00:01:00.000000");
23  selection.channels.append(SelectionChannel("TT", "TSA", "", ""));
24 # bdsDumpSelection(selection);
25 
26  # Get list of stations available
27  (err, stations) = bds.stationGetList(selection);
28  if(err):
29  return err.set(1, "Error: Getting stations: " + err.getString());
30 
31  # This displays some of the information available
32  for s in stations:
33  print("Station: " + s.name + " Type: " + s.type);
34  print(" " + "Description: " + s.description + " Number of station/channels " + str(s.channels.number()));
35 
36  return err;
37 
38 def main():
39  hostName = "localhost";
40 
41  # Create DataAccess object to connect to BDS Server
42  bds = DataAccess();
43 
44  # Connect to the DataAccess service
45  err = bds.connectService("//" + hostName + "/bdsDataAccess");
46  if(err):
47  print("Error: " + str(err) + "\n");
48  return 1;
49 
50  # Connect to service
51  err = bds.connect("test", "beam00");
52  if(err):
53  print("Error: " + str(err) + "\n");
54  return 1;
55 
56  (err, version, name) = bds.getVersion();
57  if(err):
58  print("Error: " + str(err) + "\n");
59  return 1;
60  print("Version:" , version, "Name:", name);
61 
62  err = bdsTest(bds);
63  if(err):
64  print("Error:", err.getErrorNo(), err.getString());
65  return 1;
66 
67  return 0;
68 
69 if __name__ == "__main__":
70  main();