Skip to content

Commit

Permalink
uses hit indices for faster reprocessing
Browse files Browse the repository at this point in the history
  • Loading branch information
dermen committed Mar 13, 2024
1 parent 78147cc commit 99971ad
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/dxtbx/format/FormatXTC.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import functools
import sys
import time
from itertools import groupby

import numpy as np
import serialtbx.detector.xtc
Expand Down Expand Up @@ -32,6 +33,9 @@
psana = None

locator_str = """
hits_file = None
.type = str
.help = path to a file where each line is an index in the XTC stream of a crystal hit
experiment = None
.type = str
.help = Experiment identifier, e.g. mfxo1916
Expand Down Expand Up @@ -147,6 +151,7 @@ def __init__(self, image_file, **kwargs):

self._ds = FormatXTC._get_datasource(image_file, self.params)
self._evr = None
self._load_hit_indices()
self.populate_events()

self._cached_psana_detectors = {}
Expand All @@ -162,6 +167,17 @@ def __init__(self, image_file, **kwargs):
else:
self._spectrum_pedestal = None

def _load_hit_indices(self):
self._hit_inds = None
if self.params.hits_file is not None:
assert self.params.mode == "idx"
hits = np.loadtxt(self.params.hits_file, int)
hits = list(map(tuple, hits))
key = lambda x: x[0]
gb = groupby(sorted(hits, key=key), key=key)
# dictionary where key is run number, and vals are indices of hits
self._hit_inds = {r:[ind for _,ind in group] for r,group in gb}

@staticmethod
def understand(image_file):
"""Extracts the datasource and detector_address from the image_file and then feeds it to PSANA
Expand Down Expand Up @@ -231,6 +247,11 @@ def populate_events(self):
if self.params.mode == "idx":
for run in self._psana_runs.values():
times = run.times()
if self._hit_inds is not None and run.run() in self._hit_inds:
temp = []
for i_hit in self._hit_inds[run.run()]:
temp.append( times[i_hit] )
times = tuple(temp)
if (
self.params.filter.required_present_codes
or self.params.filter.required_absent_codes
Expand Down

0 comments on commit 99971ad

Please sign in to comment.