/usr/lib/python2.7/dist-packages/sardana/macroserver/scan/recorder/datarecorder.py is in python-sardana 1.2.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | #!/usr/bin/env python
##############################################################################
##
## This file is part of Sardana
##
## http://www.tango-controls.org/static/sardana/latest/doc/html/index.html
##
## Copyright 2011 CELLS / ALBA Synchrotron, Bellaterra, Spain
##
## Sardana is free software: you can redistribute it and/or modify
## it under the terms of the GNU Lesser General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## Sardana is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU Lesser General Public License for more details.
##
## You should have received a copy of the GNU Lesser General Public License
## along with Sardana. If not, see <http://www.gnu.org/licenses/>.
##
##############################################################################
"""This is the macro server scan data recorder module"""
__all__ = ["DataFormats", "SaveModes", "RecorderStatus", "DataHandler",
"DataRecorder", "DumbRecorder"]
__docformat__ = 'restructuredtext'
import time
from taurus.core.util import Enumeration, Logger
DataFormats = Enumeration('DataFormats', ('Spec', 'CSV', 'XLS', 'w5', 'w4', 'wx', 'fio'))
SaveModes = Enumeration('SaveModes', ('Record', 'Block'))
RecorderStatus = Enumeration('RecorderStatus', ('Idle', 'Active', 'Disable'))
class DataHandler:
""" The data handler is the data recording center of a system. It contains
one or several recorders. All data transit through the handler, then
given to recorders for final saving """
def __init__(self):
self.recorders = []
def addRecorder(self, recorder):
if recorder is not None:
self.recorders.append( recorder )
def startRecordList(self, recordlist ):
for recorder in self.recorders:
if recorder.savemode is SaveModes.Record:
recorder.startRecordList( recordlist )
def endRecordList(self, recordlist):
for recorder in self.recorders:
if recorder.savemode is SaveModes.Record:
recorder.endRecordList( recordlist )
else:
recorder.writeRecordList( recordlist )
def addRecord(self, recordlist, record):
for recorder in self.recorders:
if recorder.savemode is SaveModes.Record:
recorder.writeRecord( record )
else: # blockSave
pass
def addCustomData(self, value, name, **kwargs):
'''Write data other than a record.
:param value: The value to be written
:param name: An identification for this value
Optional keyword arguments can be passed with information that some
recorders may need in order to record this value. For example: the NeXus
recorder will make use of "nxpath" info if available to place the value
where it belongs in the nexus hierarchy. Check the `addCustomData`
method of each recorder to see what they use/require.
'''
for recorder in self.recorders:
recorder.addCustomData(value, name, **kwargs )
#
# Recorders
#
class DataRecorder(Logger):
""" Generic class for data recorder. Does nothing"""
def __init__(self, **pars):
name = self.__class__.__name__
self.call__init__(Logger, name)
self.recordlist = None
self.status = RecorderStatus.Idle
self.savemode = SaveModes.Record
def getStatus(self):
return self.status
def disable(self):
self.status = RecorderStatus.Disable
def enable(self):
self.status = RecorderStatus.Idle
def startRecordList(self, recordlist):
is_idle = self.status is RecorderStatus.Idle
if is_idle:
self.recordlist = recordlist
self._startRecordList(recordlist)
if is_idle:
return 0
else:
return -1
def _startRecordList(self, recordlist):
pass
def endRecordList(self, recordlist):
self._endRecordList(recordlist)
self.status = RecorderStatus.Idle
self.recordlist = None
def _endRecordList(self, recordlist):
pass
def writeRecordList(self, recordlist):
""" Only in BLOCK_MODE. Will write whole RecordList """
self._startRecordList( recordlist )
for record in recordlist.records:
self.writeRecord(record)
self._endRecordList( recordlist )
def writeRecord(self, record):
self._writeRecord( record )
def _writeRecord( self, record ):
pass
def setSaveMode( self, mode ):
self.savemode = mode
def addCustomData(self, value, name, **kwargs):
self._addCustomData(value, name, **kwargs)
def _addCustomData(self, value, name, **kwargs):
pass
class DumbRecorder(DataRecorder):
def _startRecordList(self, recordlist):
print "Starting new recording"
print "# Title : ", recordlist.getEnvironValue('title')
env = recordlist.getEnviron()
for envky in env.keys():
if envky != 'title' and envky != 'labels':
print "# %8s : %s " % (envky,str(env[envky]))
print "# Started: ", time.ctime( env['starttime'] )
print "# L: ",
print " ".join( env['labels'] )
def _writeRecord(self, record):
print record.data
def _endRecordList(self, recordlist):
print "Ending recording"
env = recordlist.getEnviron()
print "Recording ended at: ", time.ctime( env['endtime'] )
|