Creating python application

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

  1. Firstly, you need to create and import all necessary packages. Just import Tudas module's classes:
    from tudas import DatabaseAccessProvider
  2. Create your example main method, where we'll write whole application code:
    if __name__ == '__main__':
  3. It is recommended to surround all Tudas library invocations with try-except 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):
        #write your code here
    except TudasException, e:
        print e 
  4. 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 = DatabaseAccessProvider()
    There is also need of closing DatabaseAccessProvider at the end of your program, by calling close() method:
  5. 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:
    rpManager = serviceProvider.getRomanPotManager()
  6. 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 dictionary (roman pot labels have to be prepared according to standard convention). It may look like as follows:
    offsets = {}
    offsets["020"] = 1.0
    offsets["125"] = 2.0
    offsets["103"] = 3.0
  7. 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:
    offsetsVersion = rpManager.saveOffsets(12340, "beta90", offsets)
    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).
  8. Loading data is just reverse process - you offer timestamp and label parameters, and RomanPotManager returns offsets map:
    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:
    resultOffsets = rpManager.loadOffsets(12341, "beta90", offsetsVersion)
  9. If you'd like to ensure if loaded data is correct, just print a content of resultOffests map:
    for romanPotID in resultOffsets.keys() :
        print "RP id=" + romanPotID + " value=" + str(resultOffsets[romanPotID])
  10. 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 example_alignment_client.pysource code in current directory, all you need to do is to execute commands:
     export PYTHONPATH=$PWD/lib/tudas:$PWD/lib/ice:$PYTHOPATH
Edit | Attach | Watch | Print version | History: r3 < r2 < r1 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r3 - 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-2020 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