Access to Scan Data from a post-acq Hook

Here is an example of how to access scan data from the post-acq hook:

#!/usr/bin/env python
# file name: /home/pXXuser/sardanaMacros/hookedScan.py 

"""the demo for a hooked scan"""

__all__ = ["hookedScan"]

import PyTango
from sardana.macroserver.macro import *
from sardana.macroserver.macro import macro

class hookedScan(Macro):
    """An example on how to attach hooks to the various hook points of a scan."""
    
    param_def = [
       ['motor',      Type.Motor,   None, 'Motor to move'],
       ['start_pos',  Type.Float,   None, 'Scan start position'],
       ['final_pos',  Type.Float,   None, 'Scan final position'],
       ['nr_interv',  Type.Integer, None, 'Number of scan intervals'],
       ['integ_time', Type.Float,   None, 'Integration time']
    ]
    def hook_post_acq(self):
        self.info("--- post-acq hook")
        lst = self.ascan.data.records
        if len(lst) == 0:
            return
        for k in list( lst[-1].data.keys()):
            self.output( " %s -> %s " % (k, str( lst[-1].data[k])))
    
    def run(self, motor, start_pos, final_pos, nr_interv, integ_time):
        ascan, pars = self.createMacro( "ascan", motor, start_pos, final_pos, nr_interv, integ_time)
        self.ascan = ascan

        ascan.hooks = [(self.hook_post_acq, ["post-acq"])]

        self.runMacro(ascan)

The corresponding Spock output:

p09/door/haso107d1.01 [65]: %hookedScan exp_dmy01 0 10 2 0.1
Operation will be saved in /home/kracht/temp/tst_[ScanId].fio (fio)
Scan #92 started at Tue May 26 11:19:15 2015. It will take at least 0:00:02.243056
Moving to start positions...
 #Pt No   exp_dmy01   d1_t01   sig_gen      dt   
--- post-acq hook
   0          0        0.1     0.865465  0.865937
--- post-acq hook
 haso107d1:10000/expchan/vc_sig_gen/1 -> 0.865465447158 
 haso107d1:10000/expchan/dgg2_d1_01/1 -> 0.1 
 exp_dmy01 -> 0.0 
 point_nb -> 0 
 timestamp -> 0.865936994553 
   1          5        0.1     0.295375  1.60491 
--- post-acq hook
 haso107d1:10000/expchan/vc_sig_gen/1 -> 0.2953754684 
 haso107d1:10000/expchan/dgg2_d1_01/1 -> 0.1 
 exp_dmy01 -> 5.0 
 point_nb -> 1 
 timestamp -> 1.60490703583 
   2          10       0.1     0.0936115   2.4303 
Operation saved in /home/kracht/temp/tst_00092.fio (fio)
Scan #92 ended at Tue May 26 11:19:17 2015, taking 0:00:02.696336.Dead time 88.9% (motion dead time 73.4%)