diff --git a/tests/cis_tests/util/migration/util_migrate_state_indexes.py b/tests/cis_tests/util/migration/util_migrate_state_indexes.py index be5eb506a..3b72090f3 100644 --- a/tests/cis_tests/util/migration/util_migrate_state_indexes.py +++ b/tests/cis_tests/util/migration/util_migrate_state_indexes.py @@ -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): @@ -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)