Python PVA Prototype Siniša Veseli Software Engineer AES / Software Services Group EPICS v4 Group Meeting November 19, 2013.

Slides:



Advertisements
Similar presentations
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 15 Introduction to Rails.
Advertisements

Connecting to Databases. relational databases tables and relations accessed using SQL database -specific functionality –transaction processing commit.
Lists Chapter 4 Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X.
Lecture 04 – Classes.  Python has a number of classes built-in  lists, dictionaries, sets, int, float, boolean, strings  We can define our own classes.
EPICS V4/areaDetector Integration
PvData,pvAccess,pvIOC,pvService Status EPICS Meeting June 2011 NSRRC,Hsinchu, Taiwan Marty Kraimer, Guobao Shen, and Matej Sekoranja.
Bitvis Utility Library Concepts and usage Your partner for SW and FPGA
AE6382 VBA - Excel l VBA is Visual Basic for Applications l The goal is to demonstrate how VBA can be used to leverage the power of Excel u VBA syntax.
Lucene Part3‏. Lucene High Level Infrastructure When you look at building your search solution, you often find that the process is split into two main.
 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Sets and Maps Chapter 9. Chapter 9: Sets and Maps2 Chapter Objectives To understand the Java Map and Set interfaces and how to use them To learn about.
Usage of the Python Programming Language in the CMS Experiment Rick Wilkinson (Caltech), Benedikt Hegner (CERN) On behalf of CMS Offline & Computing 1.
Pragmatic Application Building: Step by Step Jay Sissom Principal Systems Analyst Indiana University
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
Python in PHP: Applications Jon Parise 2002 International PHP Conference Frankfurt, Germany November 6, 2002.
Options for User Input Options for getting information from the user –Write event-driven code Con: requires a significant amount of new code to set-up.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 25 – Perl and CGI (Common Gateway Interface) Outline 25.1 Introduction 25.2 Perl 25.3 String Processing.
DØ Channel Archiver Tutorial V.Sirotenko, 4/4/2001.
SEAL V1 Status 12 February 2003 P. Mato / CERN Shared Environment for Applications at LHC.
Introduction to Object-oriented Programming CSIS 3701: Advanced Object Oriented Programming.
1 Introduction to PHP. 2 What is this “PHP” thing? Official description: “PHP, which stands for "PHP: Hypertext Preprocessor" is a widely-used Open Source.
AIT 616 Fall 2002 PHP. AIT 616 Fall 2002 PHP  Special scripting language used to dynamically generate web documents  Open source – Free!!!  Performs.
Avro Apache Course: Distributed class Student ID: AM Name: Azzaya Galbazar
Working Out with KURL! Shayne Koestler Kinetic Data.
Thank You ©2012, Cognizant. Rapido has been created by the Research and Development team from QE&A Technology CoE Rapido is continuously enhanced and.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 22 Java Collections.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 22 Java Collections.
PHP TUTORIAL. HISTORY OF PHP  PHP as it's known today is actually the successor to a product named PHP/FI.  Created in 1994 by Rasmus Lerdorf, the very.
Imperial College Tracker Slow Control & Monitoring.
Data Abstraction UW CSE 140 Winter What is a program? – A sequence of instructions to achieve some particular purpose What is a library? – A collection.
Copyright © 2002, Systems and Computer Engineering, Carleton University Hashtable.ppt * Object-Oriented Software Development Unit 8.
Serialization. Serialization is the process of converting an object into an intermediate format that can be stored (e.g. in a file or transmitted across.
JDBC Java and Databases. RHS – SOC 2 JDBC JDBC – Java DataBase Connectivity An API (i.e. a set of classes and methods), for working with databases in.
Cohesion and Coupling CS 4311
The european ITM Task Force data structure F. Imbeaux.
MASAR Server & Application Guobao Shen Photon Sciences Department Brookhaven National Laboratory Collaboration Working Group Oct 02, 2013.
Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special.
AppSec USA 2014 Denver, Colorado CMS Hacking 101 Hacking and Securing Popular Open Source Content Management Systems.
Built-in Data Structures in Python An Introduction.
EPICS Access from Python Geoff Savage DØ Workshop Thursday June 22, 2000.
ICAPRG301A Week 2 Strings and things Charles Babbage Developed the design for the first computer which he called a difference engine, though.
Functions CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
Google App Engine MemCache ae-09-session
Apr. 8, 2002Calibration Database Browser Workshop1 Database Access Using D0OM H. Greenlee Calibration Database Browser Workshop Apr. 8, 2002.
Python Primer 1: Types and Operators © 2013 Goodrich, Tamassia, Goldwasser1Python Primer.
Core Java Introduction Byju Veedu Ness Technologies httpdownload.oracle.com/javase/tutorial/getStarted/intro/definition.html.
INFSO-RI Enabling Grids for E-sciencE Ganga 4 – The Ganga Evolution Andrew Maier.
ENEE150 – 0102 ANDREW GOFFIN Project 4 & Function Pointers.
Hash Tables © Rick Mercer.  Outline  Discuss what a hash method does  translates a string key into an integer  Discuss a few strategies for implementing.
Copyright © GENIVI Alliance 2015
Classes, Interfaces and Packages
PvaPy: Python API for EPICS PV Access Siniša Veseli Scientific Software Engineering & Data Management Advanced Photon Source EPICS Meeting October 2015.
1 PHP Intro PHP Introduction After this lecture, you should be able to: Know the fundamental concepts of Web Scripting Languages in general, PHP in particular.
EPICS and LabVIEW Tony Vento, National Instruments
Sets and Maps Chapter 9. Chapter Objectives  To understand the Java Map and Set interfaces and how to use them  To learn about hash coding and its use.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
Data Abstraction UW CSE 160 Spring What is a program? – A sequence of instructions to achieve some particular purpose What is a library? – A collection.
CLASSES AND OBJECTS Chapter 3 : constructor, Separate files, validating data.
Pyragen A PYTHON WRAPPER GENERATOR TO APPLICATION CORE LIBRARIES Fernando PEREIRA, Christian THEIS - HSE/RP EDMS tech note:
Monitoring Dynamic IOC Installations Using the alive Record Dohn Arms Beamline Controls & Data Acquisition Group Advanced Photon Source.
This material is based upon work supported by the U.S. Department of Energy Office of Science under Cooperative Agreement DE-SC , the State of Michigan.
Modularization of Geant4 Dynamic loading of modules Configurable build using CMake Pere Mato Witek Pokorski
Computer Programming Fundamentals
Chapter 3: Using Methods, Classes, and Objects
Functions CIS 40 – Introduction to Programming in Python
ns-3 Waf build system ns-3 Annual Meeting June 2017
pvData,pvAccess,pvIOC,pvService Overview and Status EPICS Meeting
Exploring the Power of EPDM Tasks - Working with and Developing Tasks in EPDM By: Marc Young XLM Solutions
Python Primer 1: Types and Operators
pvData,pvAccess,pvIOC,pvService Overview and Status EPICS Meeting
Presentation transcript:

Python PVA Prototype Siniša Veseli Software Engineer AES / Software Services Group EPICS v4 Group Meeting November 19, 2013

Outline  Introduction  Build  Basic Usage  Objects  Advanced Usage  Implementation Details  Future Work EPICS v4 Group Meeting November 19,

Introduction  Goal: provide python API for PV Access that is: -Simple to build and use: one should be able to get started in minutes -Flexible: retain full PV Access functionality, anything that can be done via C++ APIs should be doable with python PVA API -Python look and feel: enable easy conversion to and from python objects (dictionaries, lists, etc.), use python operators, etc.  Strategy: use boost.python to wrap PV Access C++ libraries -Enables one to leveraging existing functionality and reduce implementation effort -Simplifies maintenance: future improvements in C++ infrastructure should benefit python PVA API -Problem: No well-defined high level C++ API => must EPICS v4 Group Meeting November 19,

Build  Prerequisites (prototype uses versions listed in parenthesis) -EPICS base release (v ) -EPICS4 CPP release (v4.3.0): nothing special needs to be done for build -Python development header files/libraries (v2.7.3) -Boost (v1.54.0): build must have boost_python library  Current build process: 1)Edit configure/RELEASE.local and add environment variables pointing to external dependencies 2)make 3)Create soft link pvaccess.so => libpvaccess.so in lib/$EPICS_HOST_ARCH 4)Prepare setup file (PYTHONPATH needs to have entry pointing to $PVAPY_DIR/lib/$EPICS_HOST_ARCH)  Plan: -Eliminate steps 1, 3 and 4 -Provide standard python module build/packaging scripts EPICS v4 Group Meeting November 19,

Basic Usage  Source setup file (or export PYTHONPATH=$PVAPY_DIR/lib/$EPICS_HOST_ARCH:$PYTHONPATH)  Inspect package contents: $ python -c "import pvaccess; print dir(pvaccess)”  Start test IOC from $EPICS4_DIR/pvaSrv/testApp/iocBoot/testDbPv directory: $../../bin/linux-x86_64/testDbPv st.cmd # in terminal 2  Use Channel class to get/set PVs: $ python >>> from pvaccess import * # never do that in scripts >>> c = Channel('int01') >>> print c.get() uri:ev4:nt/2012/pwd:NTScalar int value 0 >>> c.put(PvInt(7)) >>> print c.get() uri:ev4:nt/2012/pwd:NTScalar int value 7 EPICS v4 Group Meeting November 19,

PVObject Class  Base for all python PVA objects is PvObject - PV structure, initialized via python dictionary of key:value pairs that describe underlying PV structure: key is a string and value one of PVTYPE, [PVTYPE], {key:value,…}, [{key:value,…}] - PVTYPE: BOOLEAN, BYTE, UBYTE, SHORT,…,STRING - Scalar Array: represented as a list with a single PVTYPE element describing element type, e.g. [INT] - Structure Array: represented as list a with a single dictionary element describing element structure, e.g. [{‘x’ : INT, ‘y’ : FLOAT}] - Has setters/getters for all field types, e.g. >setInt(key, value) >getInt(key) >setScalarArray(key, value) >getScalarArray(key) >setStructure(key, value) >getStructure(key) EPICS v4 Group Meeting November 19,

PvObject Examples >>> pv = PvObject({'i' : INT, 's' : STRING}) >>> print pv structure int i 0 string s >>> # Can set entire object with key/value dictionary >>> pv.set({'i' : 12, 's' : 'abcd'}) >>> print pv structure int i 12 string s abcd >>> # Can use getters/setters for each field >>> pv.getString('s') 'abcd' >>> pv.setString('s', 'xyz') >>> pv.getString('s') 'xyz' EPICS v4 Group Meeting November 19,

PvObject Examples >>> pv = PvObject({'i': INT, 'slist' : [STRING], 'dict' : {'b' : BOOLEAN, 'dict2' : {'d' : DOUBLE}, 'flist' : [FLOAT]}}) >>> print pv structure int i 0 string[] slist [] structure dict boolean b 0 float[] flist [] structure dict2 double d 0 >>> # Can use incomplete dictionaries to set fields >>> pv.set({'i' : 15, 'dict' : {'flist' : [1.1, 2.2, 3.3]}}) >>> print pv structure int i 15 string[] slist [] structure dict boolean b 0 float[] flist [1.1,2.2,3.3] structure dict2 double d 0 EPICS v4 Group Meeting November 19,

PvObject Examples >>> # Conversion to dictionary >>> pv.toDict() {'i': 15, 'slist': [], 'dict': {'b': False, 'dict2': {'d': 0.0}, 'flist': [ , , ]}} >>> # Get structure field >>> pv.getStructure('dict') {'b': False, 'dict2': {'d': 0.0}, 'flist': [ , , ]} >>> # Get original structure dictionary >>> pv.getStructureDict() {'i': pvaccess.PvType.INT, 'slist': [pvaccess.PvType.STRING], 'dict': {'b': pvaccess.PvType.BOOLEAN, 'dict2': {'d': pvaccess.PvType.DOUBLE}, 'flist': [pvaccess.PvType.FLOAT]}} EPICS v4 Group Meeting November 19,

Derived Object Classes  Each scalar type has its own class: PvBoolean, PvByte, …, PvString  Can be initialized using scalar value  Have setters/getters >>> s = PvString('abc') >>> print s abc >>> d = PvDouble( ) >>> print d >>> l = PvLong( L) >>> print l >>> l.get() L >>> l.set(13L) >>> l.get() 13L EPICS v4 Group Meeting November 19,

Derived Object Classes  Scalar array type class: PvScalarArray, PvByte, …, PvString  Initialized using scalar type  Setter/getter >>> array = PvScalarArray(INT) >>> print array structure int[] value [] >>> array.set([1,2,3,4,5]) >>> print array structure int[] value [1,2,3,4,5] EPICS v4 Group Meeting November 19,

Channel Class  Provides get/put functionality >>> c = Channel('bigstring01') >>> c.put(PvString('Very Big String')) >>> print c.get() uri:ev4:nt/2012/pwd:NTScalar string value Very Big String c = Channel('intArray01') >>> print c.get() structure int[] value [] >>> print array structure int[] value [1,2,3,4,5] >>> c.put(array) >>> print c.get() structure int[] value [1,2,3,4,5] EPICS v4 Group Meeting November 19,

RPC Client Class  Client for RPC service  Start v4 test RPC service from $EPICS4_DIR/pvAccessCPP/bin/linux-x86_64/ $./rpcServiceExample # in terminal 2  RPC test channel is “sum”: >>> rpc = RpcClient('sum') >>> request = PvObject({'a' : STRING, 'b' : STRING}) >>> request.set({'a' : '11', 'b' : '22' }) >>> print request structure string a 11 string b 22 >>> response = rpc.invoke(request) >>> print response structure double c 33 EPICS v4 Group Meeting November 19,

RPC Server Class  Allows creating PVA services in python  In terminal 1 $ python # in terminal 2 >>> from pvaccess import * >>> srv = RpcServer() >>> def echo(x):# x is instance of PvObject... print 'Got object: ', x... return x# service must return instance of PvObject >>> srv.registerService('echo', echo) >>> srv.listen()  In terminal 1 >>> rpc = RpcClient('echo') >>> response = rpc.invoke(request) >>> print response structure string a 11 string b 22 EPICS v4 Group Meeting November 19,

RPC Client/Server Example  In terminal 2 $ python >>> from pvaccess import * >>> srv = RpcServer() >>> def sum(x):... a = x.getInt('a')... b = x.getInt('b')... return PvInt(a+b) >>> srv.registerService('sum', sum) >>> srv.listen()  In terminal 1 >>> rpc = RpcClient('sum') >>> request = PvObject({'a' : INT, 'b' : INT}) >>> request.set({'a' : 11, 'b' : 22}) >>> print request structure int a 11 int b 22 >>> response = rpc.invoke(request) >>> print response structure int value 33 EPICS v4 Group Meeting November 19,

RPC Client/Server Example  In terminal 2 >>> from pvaccess import * >>> srv = RpcServer() >>> def hash(x):... import hashlib... md5 = hashlib.md5()... md5.update(str(x))... h = md5.hexdigest()... dict = x.getStructureDict()... dict['hash'] = STRING... response = PvObject(dict)... response.setString('hash', h)... return response >>> srv.registerService('hash', hash) >>> srv.listen()  In terminal 1 >>> rpc = RpcClient('hash') >>> request = PvString('abcd') >>> print rpc.invoke(request) structure string hash 0a380e7375d8c3f68d1bbe068141d6ce string value EPICS v4 Group Meeting November 19,

Exception Handling  At the moment all exceptions are mapped into UserWarning >>> c = Channel('notthere') >>> c.get() Traceback (most recent call last): File " ", line 1, in UserWarning: Channel notthere timed out  Plan: decent exception hierarchy EPICS v4 Group Meeting November 19,

Implementation Details/Issues  Current functionality implemented in under 5K lines of code  Actual python pvaccess module ( pvaccess.cpp ) so far has less than 350 lines  Lots of work went into defining C++ API that would be easy to wrap using boost.python  Fair amount of python PVA C++ code is now duplicated from utilities like pvget and pvput  Common code (e.g., various default requester impl classes, parsing utilities, etc.) could be extracted into high level PVA C++ API that would be easier to use and more attractive for an average user (RPC Service/Client C++ classes are an excellent example )  All PVA command line/test utilities could be built on top such API (e.g., src/pvaccess/testClient.cpp retrieves PV from a given channel in about 20 lines of code)  Promotes code reusability, easier maintenance, etc. EPICS v4 Group Meeting November 19,

Future Work  Complete python PVA API functionality (e.g., channel monitor)  Build/packaging  More exception classes  More work on usability:  Additional Object constructors  Python operators (especially for scalar types)  Python docs  Test suite  … EPICS v4 Group Meeting November 19,