Page History
...
Code Block | ||
---|---|---|
| ||
from psana import DataSource
import numpy as np
import os
# OPTIONAL callback with "gathered" small data from all cores.
# usually used for creating realtime plots when analyzing from
# DAQ shared memory. Called back on each SRV node.
def my_smalldata(data_dict):
print(data_dict)
# sets the number of h5 files to write. 1 is sufficient for 120Hz operation
# optional: only needed if you are saving h5.
os.environ['PS_SRV_NODES']='1'
ds = DataSource(exp='tmoc00118', run=222, dir='/cds/data/psdm/prj/public01/xtc', max_events=10)
# batch_size is optional. specifies how often the dictionary of small
# user data is gathered
smd = ds.smalldata(filename='mysmallh5.h5', batch_size=5, callbacks=[my_smalldata])
for run in ds.runs():
opal = run.Detector('tmo_opal1')
ebeam = run.Detector('ebeam')
runsum = 0
for evt in run.events():
img = opal.raw.image(evt)
photonEnergy = ebeam.raw.ebeamPhotonEnergy(evt)
# important: always check for missing data
if img is None or photonEnergy is None: continue
evtsum = np.sum(img)
# pass either dictionary or kwargs
smd.event(evt, evtsum=evtsum, photonEnergy=photonEnergy)
runsum += evtsum # beware of datatypes when summing: can overflow
# optional summary data for whole run
if smd.summary:
smd.sum(runsum) # sum across all mpi cores
# pass either dictionary or kwargs
smd.save_summary({'sum_over_run' : runsum}, summary_int=1)
smd.done() |
...
Overview
Content Tools