-
Updated code according to Mark and Tim's comments
#!/usr/bin/env python3 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator from AthenaConfiguration.ComponentFactory import CompFactory def RenameParticleAuxDynBranchesCfg(): """Configure renaming of HLTNav_RepackedFeatures_ParticleAuxDyn branches.""" acc = ComponentAccumulator() # Get the AddressRemappingSvc from the ComponentFactory AddressRemappingSvc = CompFactory.AddressRemappingSvc("AddressRemappingSvc") AddressRemappingSvc.TypeKeyRenameMaps += [ '%s#%s->%s' % ("xAOD::ParticleContainer", "HLTNav_RepackedFeatures_Particle", "HLTNav_RepackedFeatures_ParticleNew"), '%s#%s->%s' % ("xAOD::ParticleAuxContainer", "HLTNav_RepackedFeatures_ParticleAux.", "HLTNav_RepackedFeatures_ParticleNewAux."), ] # Add the AddressRemappingSvc to the accumulator acc.addService(AddressRemappingSvc) # Add the ProxyProviderSvc with the AddressRemappingSvc as a provider ProxyProviderSvc = CompFactory.ProxyProviderSvc(ProviderNames=["AddressRemappingSvc"]) acc.addService(ProxyProviderSvc) return acc if __name__ == '__main__': # Import the common flags/services from AthenaConfiguration.AllConfigFlags import initConfigFlags from AthenaConfiguration.MainServicesConfig import MainServicesCfg # Set the necessary configuration flags flags = initConfigFlags() flags.Exec.EventPrintoutInterval = 1000 flags.Debug.DumpEvtStore = True # Enable detailed event store output for debugging parser = flags.getArgumentParser() parser.add_argument('-o', '--output', default='myDAOD.pool.root', type=str) args = flags.fillFromArgs(parser=parser) # Now figure out what stream type we're trying to merge stream = flags.Input.ProcessingTags[0].removeprefix('Stream') if flags.Input.ProcessingTags else None if not stream: raise RuntimeError('Could NOT determine the stream type!') # Set the DAOD related flags flags.addFlag(f'Output.{stream}FileName', args.output) flags.addFlag(f'Output.doWrite{stream}', True) flags.Output.doWriteDAOD = True # Lock the flags flags.lock() # Set up the configuration and add the relevant services cfg = MainServicesCfg(flags) # Merge the renaming configuration before input reading cfg.merge(RenameParticleAuxDynBranchesCfg()) # Input reading from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg cfg.merge(PoolReadCfg(flags)) items_to_write = [ "xAOD::ParticleContainer#HLTNav_RepackedFeatures_ParticleNew", "xAOD::ParticleAuxContainer#HLTNav_RepackedFeatures_ParticleNewAux." ] # Configure the output stream with the renamed ItemList from OutputStreamAthenaPool.OutputStreamConfig import OutputStreamCfg, outputStreamName cfg.merge(OutputStreamCfg(flags, stream, ItemList=items_to_write, takeItemsFromInput=False, extendProvenanceRecord=False)) Stream = cfg.getEventAlgo(outputStreamName(stream)) Stream.ForceRead = True # Add in-file MetaData from xAODMetaDataCnv.InfileMetaDataConfig import SetupMetaDataForStreamCfg from AthenaConfiguration.Enums import MetadataCategory cfg.merge(SetupMetaDataForStreamCfg(flags, stream, createMetadata=[MetadataCategory.IOVMetaData])) # Now run the job and exit accordingly sc = cfg.run() import sys sys.exit(not sc.isSuccess())
Edited by Yuriy Volkotrub -
A draft of the code, which doesn't work as expected
checkFile.py output.test.renamed.pool.root | grep HLTNav 1265.399 kb 207.090 kb 0.003 kb 0.000 63871 (B) HLTNav_RepackedFeatures_ParticleNew
#!/usr/bin/env python3 # Adapted script for renaming using AddressRemappingSvc, focusing on DAOD_PHYSLITE structure from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator from AthenaConfiguration.ComponentFactory import CompFactory def RenameParticleAuxDynBranchesCfg(): """Configure renaming of HLTNav_RepackedFeatures_ParticleAuxDyn branches.""" acc = ComponentAccumulator() # Get the AddressRemappingSvc from the ComponentFactory AddressRemappingSvc = CompFactory.AddressRemappingSvc("AddressRemappingSvc") # Define the renaming rules for the container and its auxiliary container AddressRemappingSvc.TypeKeyRenameMaps += [ '%s#%s->%s' % ("xAOD::ParticleContainer", "HLTNav_RepackedFeatures_Particle", "HLTNav_RepackedFeatures_ParticleNew"), '%s#%s->%s' % ("xAOD::ParticleAuxContainer", "HLTNav_RepackedFeatures_ParticleAux.", "HLTNav_RepackedFeatures_ParticleNewAux.") ] # Add the AddressRemappingSvc to the accumulator acc.addService(AddressRemappingSvc) # Add the ProxyProviderSvc with the AddressRemappingSvc as a provider ProxyProviderSvc = CompFactory.ProxyProviderSvc(ProviderNames=["AddressRemappingSvc"]) acc.addService(ProxyProviderSvc) return acc if __name__ == '__main__': # Import the common flags/services from AthenaConfiguration.AllConfigFlags import initConfigFlags from AthenaConfiguration.MainServicesConfig import MainServicesCfg # Set the necessary configuration flags flags = initConfigFlags() flags.Exec.EventPrintoutInterval = 1000 flags.Debug.DumpEvtStore = True # Enable detailed event store output for debugging parser = flags.getArgumentParser() parser.add_argument('-o', '--output', default='myDAOD.pool.root', type=str) args = flags.fillFromArgs(parser=parser) # Set the stream directly to DAOD_PHYSLITE stream = "DAOD_PHYSLITE" # Set the DAOD related flags flags.addFlag(f'Output.{stream}FileName', args.output) flags.addFlag(f'Output.doWrite{stream}', True) flags.Output.doWriteDAOD = True # Lock the flags flags.lock() # Set up the configuration and add the relevant services cfg = MainServicesCfg(flags) # Merge the renaming configuration before input reading cfg.merge(RenameParticleAuxDynBranchesCfg()) # Input reading from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg cfg.merge(PoolReadCfg(flags)) # Define the renamed containers for DAOD_PHYSLITE, including only renamed keys items_to_write = [ "xAOD::ParticleContainer#HLTNav_RepackedFeatures_ParticleNew", "xAOD::ParticleAuxContainer#HLTNav_RepackedFeatures_ParticleNewAux." ] # Configure the output stream with the renamed ItemList from OutputStreamAthenaPool.OutputStreamConfig import OutputStreamCfg, outputStreamName cfg.merge(OutputStreamCfg(flags, stream, ItemList=items_to_write, takeItemsFromInput=False, extendProvenanceRecord=False)) Stream = cfg.getEventAlgo(outputStreamName(stream)) Stream.ForceRead = True # Add in-file MetaData from xAODMetaDataCnv.InfileMetaDataConfig import SetupMetaDataForStreamCfg from AthenaConfiguration.Enums import MetadataCategory cfg.merge(SetupMetaDataForStreamCfg(flags, stream, createMetadata=[MetadataCategory.IOVMetaData])) # Now run the job and exit accordingly sc = cfg.run() import sys sys.exit(not sc.isSuccess())
Edited by Yuriy Volkotrub -
It seems that the code works
#!/usr/bin/env python3 # Script for renaming HLTNav_RepackedFeatures_Particle and its aux branches in a DAOD_PHYSLITE file from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator from AthenaConfiguration.ComponentFactory import CompFactory def RenameParticleAuxDynBranchesCfg(): """Configure renaming of HLTNav_RepackedFeatures_Particle and its auxiliary store.""" acc = ComponentAccumulator() # Get the AddressRemappingSvc from the ComponentFactory AddressRemappingSvc = CompFactory.AddressRemappingSvc("AddressRemappingSvc") # Define renaming rules for the container and each specific auxiliary branch AddressRemappingSvc.TypeKeyRenameMaps += [ # Rename the main Particle container '%s#%s->%s' % ("xAOD::ParticleContainer", "HLTNav_RepackedFeatures_Particle", "HLTNav_RepackedFeatures_ParticleNew"), # Rename the auxiliary container as a whole '%s#%s->%s' % ("xAOD::AuxContainerBase", "HLTNav_RepackedFeatures_ParticleAux.", "HLTNav_RepackedFeatures_ParticleNewAux."), # Explicit renaming for each dynamic attribute '%s#%s->%s' % ("xAOD::AuxContainerBase", "HLTNav_RepackedFeatures_ParticleAuxDyn.px", "HLTNav_RepackedFeatures_ParticleAuxNewDyn.px"), '%s#%s->%s' % ("xAOD::AuxContainerBase", "HLTNav_RepackedFeatures_ParticleAuxDyn.py", "HLTNav_RepackedFeatures_ParticleAuxNewDyn.py"), '%s#%s->%s' % ("xAOD::AuxContainerBase", "HLTNav_RepackedFeatures_ParticleAuxDyn.pz", "HLTNav_RepackedFeatures_ParticleAuxNewDyn.pz"), '%s#%s->%s' % ("xAOD::AuxContainerBase", "HLTNav_RepackedFeatures_ParticleAuxDyn.e", "HLTNav_RepackedFeatures_ParticleAuxNewDyn.e") ] # Add the AddressRemappingSvc to the accumulator acc.addService(AddressRemappingSvc) # Add the ProxyProviderSvc with the AddressRemappingSvc as a provider ProxyProviderSvc = CompFactory.ProxyProviderSvc(ProviderNames=["AddressRemappingSvc"]) acc.addService(ProxyProviderSvc) return acc if __name__ == '__main__': # Import the common flags/services from AthenaConfiguration.AllConfigFlags import initConfigFlags from AthenaConfiguration.MainServicesConfig import MainServicesCfg # Set the necessary configuration flags flags = initConfigFlags() flags.Exec.EventPrintoutInterval = 1000 flags.Debug.DumpEvtStore = True # Enable detailed event store output for debugging parser = flags.getArgumentParser() parser.add_argument('-o', '--output', default='output.test.renamed.pool.root', type=str) args = flags.fillFromArgs(parser=parser) # Set the stream directly to DAOD_PHYSLITE stream = "DAOD_PHYSLITE" # Set the DAOD-related flags flags.addFlag(f'Output.{stream}FileName', args.output) flags.addFlag(f'Output.doWrite{stream}', True) flags.Output.doWriteDAOD = True # Lock the flags flags.lock() # Set up the configuration and add the relevant services cfg = MainServicesCfg(flags) # Merge the renaming configuration before input reading cfg.merge(RenameParticleAuxDynBranchesCfg()) # Input reading from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg cfg.merge(PoolReadCfg(flags)) # Define the renamed containers for DAOD_PHYSLITE, including specific dynamic attributes explicitly items_to_write = [ "xAOD::ParticleContainer#HLTNav_RepackedFeatures_ParticleNew", "xAOD::AuxContainerBase#HLTNav_RepackedFeatures_ParticleNewAux.", "xAOD::AuxContainerBase#HLTNav_RepackedFeatures_ParticleAuxNewDyn.px", "xAOD::AuxContainerBase#HLTNav_RepackedFeatures_ParticleAuxNewDyn.py", "xAOD::AuxContainerBase#HLTNav_RepackedFeatures_ParticleAuxNewDyn.pz", "xAOD::AuxContainerBase#HLTNav_RepackedFeatures_ParticleAuxNewDyn.e" ] # Configure the output stream with the renamed ItemList from OutputStreamAthenaPool.OutputStreamConfig import OutputStreamCfg, outputStreamName cfg.merge(OutputStreamCfg(flags, stream, ItemList=items_to_write, takeItemsFromInput=False, extendProvenanceRecord=False)) Stream = cfg.getEventAlgo(outputStreamName(stream)) Stream.ForceRead = True # Add in-file MetaData from xAODMetaDataCnv.InfileMetaDataConfig import SetupMetaDataForStreamCfg from AthenaConfiguration.Enums import MetadataCategory cfg.merge(SetupMetaDataForStreamCfg(flags, stream, createMetadata=[MetadataCategory.IOVMetaData])) # Now run the job and exit accordingly sc = cfg.run() import sys sys.exit(not sc.isSuccess())
-
Final code
#!/usr/bin/env python3 # Script for renaming HLTNav_RepackedFeatures_Particle and its aux branches in a DAOD_PHYSLITE file from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator from AthenaConfiguration.ComponentFactory import CompFactory def RenameParticleAuxDynBranchesCfg(): """Configure renaming of HLTNav_RepackedFeatures_Particle and its auxiliary store.""" acc = ComponentAccumulator() # Get the AddressRemappingSvc from the ComponentFactory AddressRemappingSvc = CompFactory.AddressRemappingSvc("AddressRemappingSvc") # Define renaming rules for the container and each specific auxiliary branch AddressRemappingSvc.TypeKeyRenameMaps += [ # Rename the main Particle container '%s#%s->%s' % ("xAOD::ParticleContainer", "HLTNav_RepackedFeatures_Particle", "HLTNav_RepackedFeatures_ParticleNew"), # Rename the auxiliary container as a whole '%s#%s->%s' % ("xAOD::AuxContainerBase", "HLTNav_RepackedFeatures_ParticleAux.", "HLTNav_RepackedFeatures_ParticleNewAux."), # Explicit renaming for each dynamic attribute '%s#%s->%s' % ("xAOD::AuxContainerBase", "HLTNav_RepackedFeatures_ParticleAuxDyn.px", "HLTNav_RepackedFeatures_ParticleAuxNewDyn.px"), '%s#%s->%s' % ("xAOD::AuxContainerBase", "HLTNav_RepackedFeatures_ParticleAuxDyn.py", "HLTNav_RepackedFeatures_ParticleAuxNewDyn.py"), '%s#%s->%s' % ("xAOD::AuxContainerBase", "HLTNav_RepackedFeatures_ParticleAuxDyn.pz", "HLTNav_RepackedFeatures_ParticleAuxNewDyn.pz"), '%s#%s->%s' % ("xAOD::AuxContainerBase", "HLTNav_RepackedFeatures_ParticleAuxDyn.e", "HLTNav_RepackedFeatures_ParticleAuxNewDyn.e") ] # Add the AddressRemappingSvc to the accumulator acc.addService(AddressRemappingSvc) # Add the ProxyProviderSvc with the AddressRemappingSvc as a provider ProxyProviderSvc = CompFactory.ProxyProviderSvc(ProviderNames=["AddressRemappingSvc"]) acc.addService(ProxyProviderSvc) return acc if __name__ == '__main__': # Import the common flags/services from AthenaConfiguration.AllConfigFlags import initConfigFlags from AthenaConfiguration.MainServicesConfig import MainServicesCfg # Set the necessary configuration flags flags = initConfigFlags() flags.Exec.EventPrintoutInterval = 1000 flags.Debug.DumpEvtStore = True # Enable detailed event store output for debugging parser = flags.getArgumentParser() parser.add_argument('-o', '--output', default='output.test.renamed.pool.root', type=str) args = flags.fillFromArgs(parser=parser) # Set the stream directly to DAOD_PHYSLITE stream = "DAOD_PHYSLITE" # Set the DAOD-related flags flags.addFlag(f'Output.{stream}FileName', args.output) flags.addFlag(f'Output.doWrite{stream}', True) flags.Output.doWriteDAOD = True # Lock the flags flags.lock() # Set up the configuration and add the relevant services cfg = MainServicesCfg(flags) # Merge the renaming configuration before input reading cfg.merge(RenameParticleAuxDynBranchesCfg()) # Input reading from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg cfg.merge(PoolReadCfg(flags)) # Define the renamed containers for DAOD_PHYSLITE, including specific dynamic attributes explicitly items_to_write = [ "xAOD::ParticleContainer#HLTNav_RepackedFeatures_ParticleNew", "xAOD::AuxContainerBase#HLTNav_RepackedFeatures_ParticleNewAux.", "xAOD::AuxContainerBase#HLTNav_RepackedFeatures_ParticleNewAuxDyn.px", "xAOD::AuxContainerBase#HLTNav_RepackedFeatures_ParticleNewAuxDyn.py", "xAOD::AuxContainerBase#HLTNav_RepackedFeatures_ParticleNewAuxDyn.pz", "xAOD::AuxContainerBase#HLTNav_RepackedFeatures_ParticleNewAuxDyn.e" ] # Configure the output stream with the renamed ItemList from OutputStreamAthenaPool.OutputStreamConfig import OutputStreamCfg, outputStreamName cfg.merge(OutputStreamCfg(flags, stream, ItemList=items_to_write, takeItemsFromInput=False, extendProvenanceRecord=False)) Stream = cfg.getEventAlgo(outputStreamName(stream)) Stream.ForceRead = True # Add in-file MetaData from xAODMetaDataCnv.InfileMetaDataConfig import SetupMetaDataForStreamCfg from AthenaConfiguration.Enums import MetadataCategory cfg.merge(SetupMetaDataForStreamCfg(flags, stream, createMetadata=[MetadataCategory.IOVMetaData])) # Now run the job and exit accordingly sc = cfg.run() import sys sys.exit(not sc.isSuccess())
-
Focus on renaming the HLTNav_RepackedFeatures_Particle container only during the reading phase. Next, the script should work (preparation is ongoing) with an algorithm that will copy the compressed data to the same collection in the output.
#!/usr/bin/env python3 # Script for renaming HLTNav_RepackedFeatures_Particle and its aux branches in a DAOD_PHYSLITE file # Renaming only applies during reading, with no modifications to the output container names from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator from AthenaConfiguration.ComponentFactory import CompFactory def RenameParticleAuxDynBranchesCfg(): """Configure renaming of HLTNav_RepackedFeatures_Particle and its auxiliary store for reading only.""" acc = ComponentAccumulator() # Set up AddressRemappingSvc for renaming only during input reading AddressRemappingSvc = CompFactory.AddressRemappingSvc("AddressRemappingSvc") AddressRemappingSvc.TypeKeyRenameMaps += [ 'xAOD::ParticleContainer#HLTNav_RepackedFeatures_Particle->HLTNav_RepackedFeatures_ParticleNew', 'xAOD::AuxContainerBase#HLTNav_RepackedFeatures_ParticleAux.->HLTNav_RepackedFeatures_ParticleNewAux.' ] acc.addService(AddressRemappingSvc) # Add ProxyProviderSvc with AddressRemappingSvc as a provider ProxyProviderSvc = CompFactory.ProxyProviderSvc(ProviderNames=["AddressRemappingSvc"]) acc.addService(ProxyProviderSvc) return acc if __name__ == '__main__': from AthenaConfiguration.AllConfigFlags import initConfigFlags from AthenaConfiguration.MainServicesConfig import MainServicesCfg # Initialize configuration flags flags = initConfigFlags() flags.Exec.EventPrintoutInterval = 1000 flags.Debug.DumpEvtStore = True # Enable detailed event store output for debugging parser = flags.getArgumentParser() parser.add_argument('-o', '--output', default='output.test.renamed.pool.root', type=str) args = flags.fillFromArgs(parser=parser) # Define the stream as DAOD_PHYSLITE stream = "DAOD_PHYSLITE" # Set DAOD-related output flags flags.addFlag(f'Output.{stream}FileName', args.output) flags.addFlag(f'Output.doWrite{stream}', True) flags.Output.doWriteDAOD = True # Lock the flags to prevent modifications flags.lock() # Set up main configuration and add renaming services for reading cfg = MainServicesCfg(flags) cfg.merge(RenameParticleAuxDynBranchesCfg()) # Configure input reading from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg cfg.merge(PoolReadCfg(flags)) # Configure the output stream to use the original container names and include all input items items_to_write = [ "xAOD::ParticleContainer#HLTNav_RepackedFeatures_Particle", "xAOD::AuxContainerBase#HLTNav_RepackedFeatures_ParticleAux." ] from OutputStreamAthenaPool.OutputStreamConfig import OutputStreamCfg, outputStreamName cfg.merge(OutputStreamCfg(flags, stream, ItemList=items_to_write, takeItemsFromInput=True, extendProvenanceRecord=False)) Stream = cfg.getEventAlgo(outputStreamName(stream)) Stream.ForceRead = True # Add metadata for the output file from xAODMetaDataCnv.InfileMetaDataConfig import SetupMetaDataForStreamCfg from AthenaConfiguration.Enums import MetadataCategory cfg.merge(SetupMetaDataForStreamCfg(flags, stream, createMetadata=[MetadataCategory.IOVMetaData])) # Run the job sc = cfg.run() import sys sys.exit(not sc.isSuccess())
Please register or sign in to comment