Skip to content
Open
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
20 changes: 17 additions & 3 deletions tests/cis_tests/util/migration/util_migrate_state_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,16 @@ def findIndexDirs(root: Path) -> list[Path]:
if confirm != 'y':
print("Exiting without making any changes.")
exit(0)


def migrateInstrumentState(jDict: dict, indexEntry: IndexEntry, runNumber):
jDict["instrumentState"]["instrumentConfig"]["indexEntry"] = indexEntry.model_dump()
# migrate detectorState
if "detectorState" in jDict["instrumentState"]:
_, detectorState = lds.generateStateId(runNumber)
jDict["instrumentState"]["detectorState"] = detectorState.model_dump()

return jDict

def stageMigrationIndexDir(indexDir: Path):

Expand Down Expand Up @@ -91,13 +100,18 @@ def stageMigrationIndexDir(indexDir: Path):
# add the indexEntry to the dict
jDict["indexEntry"] = entry.model_dump()

# Update NESTED indexedObjects
# if the file is a "record" we also need to update its "calculationParameters" to match the version of the indexEntry
if "calculationParameters" in jDict:
# this is the historic snapinstprm for a given run, which is included in the calibration parameters
# as "instrumentState"
snapInstPrmEntry = instParamIndexer.latestApplicableEntry(jDict["runNumber"])
jDict["calculationParameters"]["indexEntry"] = entry.model_dump()
jDict["calculationParameters"]["instrumentState"]["instrumentConfig"]["indexEntry"] = instParamIndexer.latestApplicableEntry(jDict["runNumber"]).model_dump()
jDict["calculationParameters"] = migrateInstrumentState(jDict["calculationParameters"], snapInstPrmEntry, jDict["runNumber"])
if "instrumentState" in jDict:
jDict["instrumentState"]["instrumentConfig"]["indexEntry"] = instParamIndexer.latestApplicableEntry(jDict["seedRun"]).model_dump()

snapInstPrmEntry = instParamIndexer.latestApplicableEntry(jDict["seedRun"])
jDict = migrateInstrumentState(jDict, snapInstPrmEntry, jDict["seedRun"])

# write the dict back to the json file
# find common root of stageDir and jsonFile
stagedJsonFile = stageDir / jsonFile.relative_to(calibrationRoot)
Expand Down