Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring idea #118

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
423 changes: 135 additions & 288 deletions calibrationSuite/basicSuiteScript.py

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions calibrationSuite/detectorInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
## the terms contained in the LICENSE.txt file.
##############################################################################
class DetectorInfo:
def __init__(self, detType, detSubtype=None):
def __init__(self, detType, detSubtype="1d"):
# declare all detector-specific info vars here in case any setup_X functions don't,
# and use -1 so caller knows things are not setup (non-0 to avoid error on divide.
self.nModules = -1
Expand Down Expand Up @@ -88,7 +88,7 @@ def setup_epixM(self, version=0):
self.seedCut = 2
self.neighborCut = 0.25 ## ditto

def setup_rixsCCD(self, mode="1d", version=0):
def setup_rixsCCD(self, mode, version=0):
print("rixsCCD mode:", mode)
self.nTestPixelsPerBank = 36
self.nBanks = 16
Expand Down
118 changes: 13 additions & 105 deletions calibrationSuite/psana1Base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,69 +7,34 @@
## may be copied, modified, propagated, or distributed except according to
## the terms contained in the LICENSE.txt file.
##############################################################################
# from psana import *
import importlib
"""
This class contains a setup function and some utility functions that work only for psana1 based analysis.
To make the library use this class execute 'export foo=psana1'.
"""

import logging
import os
import sys

import psana

from calibrationSuite.argumentParser import ArgumentParser
from calibrationSuite.psanaCommon import PsanaCommon

logger = logging.getLogger(__name__)


class PsanaBase(object):
class PsanaBase(PsanaCommon):
def __init__(self, analysisType="scan"):
super().__init__()

commandUsed = sys.executable + " " + " ".join(sys.argv)
logger.info("Ran with cmd: " + commandUsed)

self.psanaType = 1
print("in psana1Base")
logger.info("in psana1Base")
self.gainModes = {"FH": 0, "FM": 1, "FL": 2, "AHL-H": 3, "AML-M": 4, "AHL-L": 5, "AML-L": 6}
self.ePix10k_cameraTypes = {1: "Epix10ka", 4: "Epix10kaQuad", 16: "Epix10ka2M"}
self.g0cut = 1 << 14
self.gainBitsMask = self.g0cut - 1

self.args = ArgumentParser().parse_args()
logger.info("parsed cmdline args: " + str(self.args))

# if the SUITE_CONFIG env var is set use that, otherwise if the cmd line arg is set use that
# if neither are set, use the default 'suiteConfig.py' file
defaultConfigFileName = "suiteConfig.py"
secondaryConfigFileName = defaultConfigFileName if self.args.configFile is None else self.args.configFile
# secondaryConfigFileName is returned if env var not set
configFileName = os.environ.get("SUITE_CONFIG", secondaryConfigFileName)
config = self.importConfigFile(configFileName)
if config is None:
print("\ncould not find or read config file: " + configFileName)
print("please set SUITE_CONFIG env-var or use the '-cf' cmd-line arg to specify a valid config file")
print("exiting...")
sys.exit(1)
self.experimentHash = config.experimentHash
knownTypes = ["epixhr", "epixM", "rixsCCD"]
if self.experimentHash["detectorType"] not in knownTypes:
print("type %s not in known types" % (self.experimentHash["detectorType"]), knownTypes)
return -1

## self.setupPsana()

def importConfigFile(self, file_path):
if not os.path.exists(file_path):
print(f"The file '{file_path}' does not exist")
return None
spec = importlib.util.spec_from_file_location("config", file_path)
config_module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(config_module)
return config_module

def get_ds(self, run=None):
if run is None:
run = self.run
return psana.DataSource("exp=%s:run=%d:smd" % (self.exp, run))

def setupPsana(self):
logger.info("have built basic script class, exp %s run %d" % (self.exp, self.run))

Expand All @@ -91,16 +56,10 @@ def setupPsana(self):
except Exception:
self.controlData = None

def getFivePedestalRunInfo(self):
## could do load_txt but would require full path so
if self.det is None:
self.setupPsana()

evt = self.getEvt(self.fivePedestalRun)
self.fpGains = self.det.gain(evt)
self.fpPedestals = self.det.pedestals(evt)
self.fpStatus = self.det.status(evt) ## does this work?
self.fpRMS = self.det.rms(evt) ## does this work?
def get_ds(self, run=None):
if run is None:
run = self.run
return psana.DataSource("exp=%s:run=%d:smd" % (self.exp, run))

def getEvt(self, run=None):
oldDs = self.ds
Expand All @@ -114,35 +73,6 @@ def getEvt(self, run=None):
self.ds = oldDs
return evt

def getEvtFromRunsTooSmartForMyOwnGood(self):
for r in self.runRange:
self.run = r
self.ds = self.get_ds()
try:
evt = next(self.ds.events())
yield evt
except Exception:
continue

def getEvtFromRuns(self):
try: ## can't get yield to work
evt = next(self.ds.events())
return evt
except StopIteration:
i = self.runRange.index(self.run)
try:
self.run = self.runRange[i + 1]
print("switching to run %d" % (self.run))
logger.info("switching to run %d" % (self.run))
self.ds = self.get_ds(self.run)
except Exception:
print("have run out of new runs")
logger.exception("have run out of new runs")
return None
##print("get event from new run")
evt = next(self.ds.events())
return evt

def getFlux(self, evt):
try:
fluxes = self.wave8.get(evt).peakA()
Expand All @@ -165,15 +95,6 @@ def getFlux(self, evt):
return None
return f

def get_evrs(self):
if self.config is None:
self.get_config()

self.evrs = []
for key in list(self.config.keys()):
if key.type() == psana.EvrData.ConfigV7:
self.evrs.append(key.src())

def isKicked(self, evt):
try:
evr = evt.get(psana.EvrData.DataV4, self.evrs[0])
Expand All @@ -195,9 +116,6 @@ def isKicked(self, evt):
pass
return kicked

def get_config(self):
self.config = self.ds.env().configStore()

def getStepGen(self):
return self.ds.steps()

Expand All @@ -217,13 +135,3 @@ def getCalibData(self, evt):

def getImage(self, evt, data=None):
return self.raw.image(evt, data)


"""
if __name__ == "__main__":
bSS = BasicSuiteScript()
print("have built a BasicSuiteScript")
bSS.setupPsana()
evt = bSS.getEvt()
print(dir(evt))
"""
Loading