Creating c++ application

You can find the extended version of this example, known as ExampleAlignmentClient.cpp in our latest release package (or just check it here).

  1. Firstly, you need to create and ExampleAlignmentClient.cpp and include all necessary headers:
    #include "TudasException.h"
    #include "DatabaseAccessProvider.h"
  2. In order to simplify Tudas library use, declare following namespaces:
    using namespace std;
    using namespace tudas;
    using namespace tudas::exceptions;
  3. Create your example main function, where we'll write whole application code:
    int main(int argc, char* argv[]) {
  4. It is recommended to surround all Tudas library invocations with try-catch block in order to properly handle exceptions. The main Tudas exception class is called TudasException. You can catch it and just print the exception (find more details about exceptions handling here):
    DatabaseAccessProvider serviceProvider = NULL;
    try {
          //write your code here
    } catch(TudasException e){
         cout << e;
         if(serviceProvider) {
  5. Before you perform any database operation, you have to initialize DatabaseAccessProvider - main Tudas class, managing connection with Tudas Server and offering all Tudas services. Remember, that once you've created DatabaseAccessProvider object, it should be also initialized by calling initialize() method. Only then, it is fully configured and ready to establish connection with Tudas Server:
    serviceProvider = new DatabaseAccessProvider();
    As you could see in step 4, there is also need of closing DatabaseAccessProvider at the end of your program, preferably during exception handling. We make sure if it has been already initialized and if so, we call close() method.

  6. DatabaseAccessProvider delivers set of services, connected with different functionalities, offered by our system. One of them is RomanPotManager, which is able to, inter alia, save and load roman pot offsets data. To create RomanPotManager, simply invoke getRomanPotManager() on your serviceProvider object:
    RomanPotManager* rpManager = serviceProvider->getRomanPotManager();
  7. In order to save roman pot offsets into the database, we'll need three parameters: start time of validity interval, string label describing measurement and offets structure. Offsets are stored in roman pot label - offset value map (roman pot labels have to be prepared according to standard convention). It may look like as follows:
    map<string, double> offsetsMap;
    offsetsMap["020"] = 1.0;
    offsetsMap["125"] = 2.0;
    offsetsMap["103"] = 3.0;
  8. Finally, you can save your offset data into the database. In this example we use 12345 as validity interval start time and "beta90" as measurement label:
    int offsetsVersion = rpManager->saveOffsets(12340, "beta90", offsetsMap);
    As you can see, the method returns offsetsVersion, which is number describing version of the data in the database. If you save the same data more then once, you'll get successive version number (data in Totem Offline Database is never deleted or overriden, for most of our interfaces, we offer unified versioning mechanism).
  9. Loading data is just reverse process - you offer timestamp and label parameters, and RomanPotManager returns offsets map:
    map<string, double> resultOffsets = rpManager->loadOffsets(12341, "beta90");
    This method always returns the latest version of data connected with specified arguments. Alternatively, you can also manually set version of data that should be loaded from the database. In our case:
    map<string, double> resultOffsets = rpManager->loadOffsets(12341, "beta90", offsetsVersion);
  10. If you'd like to ensure if loaded data is correct, just print a content of resultOffests map:
    for (map<string, double>::iterator iterator = resultOffsets.begin(); iterator != resultOffsets.end(); iterator++) {
        cout << "RP id=" << iterator->first << " value=" << iterator->second << endl;
  11. Now, your application code is complete. You can compile and test it. Assuming that your Tudas lib directory is located on path: ./lib and you have your ExampleAlignmentClient.cpp source code, config.client and log4cpp.config in current directory, all you need to do is to execute commands:
     g++ -I./include -L./lib -ltudas ExampleAlignmentClient.cpp -o ExampleAlignmentClient
Edit | Attach | Watch | Print version | History: r4 < r3 < r2 < r1 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r4 - 2012-09-06 - unknown
    • Cern Search Icon Cern Search
    • TWiki Search Icon TWiki Search
    • Google Search Icon Google Search

    TOTEM All webs login

This site is powered by the TWiki collaboration platform Powered by PerlCopyright & 2008-2023 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
or Ideas, requests, problems regarding TWiki? use Discourse or Send feedback