Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Warning

Introduced changes should work in parallel with existing API (unless it proves impossible)

'Old' methods and classes will be marked as deprecated  

...


 DBEntry

Class structure:

Class keeps information about one, particular  database entry (eg. pulse-file, HDC container, SQL-database, etc etc)

Gliffy Diagram
macroId7cda32ff-7be2-4e5f-95c5-271e0f75b931
nameClass structure siagram
pagePin34


  • db_entryDBEntry class represents data accessible through Access Layer 
  • hdc_entryHDCEntry , sql_entrySQLEntry  are examples of classes that represents IMAS data entry accessible via other mechanisms than AL (if they will be implemented in future)
  • imas_entryIMASEntry a parent class for all ??_entryall XXXEntry classes. It will be implemented in future if any other mechanism of accessing data than AL will be used. Could be empty...  

...

  • backend_id - MDSPLUS_BACKEND, MEMORY_BACKEND, ASCII_BACKEND - mandatory -   
  • db name - eg. test   - mandatory 
  • shot - mandatory
  • run - mandatory
  • user name - eg. g2bpalak  -  optional - if None → $USER  optional  (if None  → $USER)
  • data version - e.g. 3 - optional - currently not used,  we should keep it as it will point us to a proper dir in imasdb structure, when we develop versions 4,5, etc  - if None → 3None → $IMAS_VERSION 
Code Block
languagepy
titledb_entry constructor
def __init__(self, backend_id, db_name, shot, run, user_name = None, data_version = 3)
	if userNameuser_name is None:
		user_name = $USER


Additional "URI-based" constructor will be added in future...

...

Code Block
languagepy
titledb_entry create/open/close
def create(self, options = None)
def open(self, options = None)
def close(self, options = None)

options - additional options (possibly backend specific)

DBEntry methods for IDS storing /reading

Get IDS

...

Code Block
languagepy
titleIDS GET
def get(self, idsName, occurrence = 0) # idsName (e.g. 'equilibrium') ENUM ?
	wallObj = initialize_ids_obj('wall') 
	wallObj.put(self(db_entry))
	return wallObj

Put IDS

...

Code Block
languagepy
titleIDS PUT
def put(self, ids, occurrence = 0)

...

Code Block
languagepy
titleIDS PUT
def put_slice(self, ids, occurrence = 0)

GetSlice IDS

...

Code Block
languagepy
titleIDS GET
def get_slice(self, ids_name, time_requested, interpolation_method, occurrence=0): # idsName (e.g. 'equilibrium')
	return ids

Any other method is needed to ba added to

...

DBEntry class?

def delete(self, ids_name, occurrence=0):

...

def get_ids(cls, ids_name):

IDS class

To be backward compatible or not to be backward compatible, that is the question!
Warning
titleBackward compatibility

Backward compatibility, understood as possibility of using 'old' and 'new' approach at the same time is :

(plus) Can be achieved without big effort, as content of IDS class will not change (a lot)

(plus) All 'old' scripts will work - no modifications needed →  users are happy (smile)

(minus) Currently all methods use context kept in IDS that was a reason of many problems. New API is designed to overcome this issue. Keeping compatibility means that methods still have to be able to use context stored in IDS that is error prone.

(minus) All unwanted, messy methods operating on context stored (setCtx, etc)  must be kept 


Compatibility can be also ensured by introducing new names of methods - putSlice  vs put_slice 

...

Code Block
def get_max_occurrences(cls):

def read_time_mode(self, ctx):

def read_time(self, ctx):

IDS storing / reading

db_entryDBEntry  is used to provide explicitly context to methods. This parameter should be mandatory, but is optional to keep backward compatibility....


Code Block
def put(self, occurrence=0, db_entry=None):

def get(self, occurrence=0, db_entry=None):

def putSlice(self, occurrence=0, db_entry=None):

def getSlice(self, time_requested, interpolation_method, occurrence=0, db_entry=None):

...

PUTGET


Code Block
languagepy
dbEntrydb_entry = imas.db_entryDBEntry(imasdef.MDSPLUS_BACKEND, db_name, 2222, 2222)
dbEntrydb_entry.create()  
    
ids = pf_active()
# Mandatory property
ids.ids_properties.homogeneous_time = 2

dbEntrydb_entry.put(ids)

dbEntrydb_entry.close()



Code Block
languagepy
dbEntrydb_entry = imas.db_entryDBEntry(imasdef.MDSPLUS_BACKEND, db_name, 2222, 2222)
dbEntrydb_entry.open()  





ids = dbEntrydb_entry.get('pf_active')

dbEntrydb_entry.close()


Storing/reading data via ids methods

PUTGET


Code Block
languagepy
dbEntrydb_entry = imas.db_entryDBEntry(imasdef.MDSPLUS_BACKEND, db_name, 3333, 3333)
dbEntrydb_entry.create()  
    
ids = pf_active()
ids.ids_properties.homogeneous_time = 2

ids.put(db_entry = dbEntrydb_entry)
dbEntrydb_entry.close()



Code Block
languagepy
dbEntrydb_entry = imas.db_entryDBEntry(imasdef.MDSPLUS_BACKEND, db_name, 3333, 3333)
dbEntrydb_entry.create()  

ids = pf_active()


ids.get(db_entry = dbEntrydb_entry)
dbEntrydb_entry.close()



Importing IDS classes

...

TO DO / Open points

IDS superclass

"Ids" will be a natural name for superclass but "ids" defined in ids.py already exists (the class that contains all IDSes as its attributes).

Will using "Ids" and "ids" be confusing ( "I" vs "i") ? "Ids" superclass will be defined for internal purposes only....IdsBase

IDS names

Code Block
ids = dbEntrydb_entry.get('pf_active')

To avoid any mistakes, db_entry.get method argument describing IDS should not be a string (ida name - 'equilibrium', 'wall' etc) but a constant value.

It can be implemented using enum or class attribute

Enum

class IDSNamesIDSName(enum):  #any better name?

     EQUILIBRIUM = 'equilibrium'

     WALL = 'wall' 

etc etc

Code Block
from ids_names import IDSName

ids = dbEntrydb_entry.get(IDSNamesIDSName.WALL)

...


Warning

It is not enough to call IDSName.WALL  to get string value of enumerator. Because of Python enumerator implementation, one has to call IDSName.WALL.value to get 'wall' string.


Given IDS class attribute

e.g. Wall.__name__

Code Block
ids = dbEntrydb_entry.get(Wall.__name__)