Versions Compared

Key

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

...

Code Block
languagepy
from psana import DataSource
import numpy as np
# called back on each SRV node, for every smd.event() call below
def test_callback(data_dict):
    # called back for every event
    print(data_dict)

ds = DataSource(exp='xpptut13', run=1, dir='.tmp', filter=lambda x : True, batch_size=2))
# batch_size here specifies how often the dictionary of information
# is sent to the SRV nodes
smd = ds.smalldata(filename='my.h5', batch_size=5, callbacks=[test_callback])
run = next(ds.runs())
# necessary (instead of "None") since some ranks may not receive events
# and the smd.sum() below could fail
arrsum = None
 np.zeros((2), dtype=np.int)
for i,evt in enumerate(run.events()):
    myones = np.ones(2, dtype=np.int_like(arrsum)
    smd.event(evt, myfloat=2.0, arrint=myones)
    if arrsum is None:
        arrsum = myones
    else:
        arrsum += myones

if smd.summary:
    # add up array across "big data" cores and save to h5
    smd.sum(arrsum) # assumes that all cores have received events
    smd.save_summary({'summary_array' : arrsum}, summary_int=1)
smd.done()

...