43def PoolWriteCfg(flags):
44 """Return ComponentAccumulator configured to Write POOL files"""
45
46
47 from AthenaCommon.Logging import logging
48 logger = logging.getLogger( 'PoolWriteCfg' )
49
50 PoolAttributes = []
51
52 PoolAttributes += ["DEFAULT_SPLITLEVEL ='0'"]
53
54
55 PoolAttributes += ["STREAM_MEMBER_WISE = '1'"]
56
57
58 PoolAttributes += [f"DEFAULT_CONTAINER_TYPE = '{ROOT.pool.DbType.getType(flags.Output.DefaultContainerType).type()}'"]
59
60
61 PoolAttributes += ["DEFAULT_BUFFERSIZE = '32000'"]
62
63
64 PoolAttributes += ["ContainerName = 'TTree=POOLContainerForm(DataHeaderForm)'; CONTAINER_SPLITLEVEL = '0'"]
65 PoolAttributes += ["TREE_BRANCH_OFFSETTAB_LEN ='100'"]
66
67 oneDHForm = flags.Output.OneDataHeaderForm
68
69
70 from AthenaPoolCnvSvc import PoolAttributeHelper as pah
71
72
73
74 defaults = {
75 "EVNT" : [2, 1, 500, 0, 0],
76 "EVNT_TR" : [2, 1, 1, 0, 0],
77 "HITS" : [2, 1, 10, 0, 0],
78 "RDO" : [2, 1, 10, 0, 0],
79 "ESD" : [2, 1, 10, 0, 0],
80 "AOD" : [2, 1, 100, 0, 0],
81 "DAOD_PHYSVAL" : [5, 5, 100, 0, 1],
82 "DAOD_PHYS" : [5, 5, 500, 0, 1],
83 "DAOD_PHYSLITE" : [5, 5, 500, 1, 1],
84 "DAOD_TRUTH3" : [5, 5, 500, 1, 1],
85 "D2AOD_PHYSLITE" : [5, 5, 500, 1, 1],
86 }
87
88
89
90 rntupleCompression = {
91 "DAOD_PHYS" : [5, 9],
92 "DAOD_PHYSLITE" : [5, 9],
93 }
94
95
96 OutputMetadataContainers = []
97
98
99 fileFlushSetting = {}
100 maxAutoFlush = -1
101 for stream in _getStreamsFromFlags(flags):
102
103
104 fileName = getattr(flags.Output, f"{stream}FileName")
105
106
107 compAlg, compLvl, autoFlush, splitLvl, dynSplitLvl = 2, 1, 10, 0, 0
108 if stream in defaults:
109 compAlg, compLvl, autoFlush, splitLvl, dynSplitLvl = defaults[stream]
110 elif "DAOD" in stream:
111 compAlg, compLvl, autoFlush, splitLvl, dynSplitLvl = 5, 5, 100, 0, 1
112 elif "D2AOD" in stream:
113 compAlg, compLvl, autoFlush, splitLvl, dynSplitLvl = 5, 5, 500, 1, 1
114 if "RNTUPLE" in flags.Output.DefaultContainerType and stream in rntupleCompression:
115 compAlg, compLvl = rntupleCompression[stream]
116
117
118
119
120
121
122
123
124 isTemporaryStream = fileName.endswith('_000') or fileName.startswith('tmp.') or stream in flags.Output.TemporaryStreams
125 tempFileCompressionSetting = (5,1)
126 if isTemporaryStream:
127
128
129
130 from AthenaConfiguration.Enums import LHCPeriod
131 if "RDO" in stream and flags.hasCategory("GeoModel") and flags.GeoModel.Run < LHCPeriod.Run3:
132 tempFileCompressionSetting = (1,1)
133 logger.info(f"Stream {stream} is marked as temporary, overwriting the compression settings to {tempFileCompressionSetting}")
134 compAlg, compLvl = tempFileCompressionSetting if isTemporaryStream else (compAlg, compLvl)
135
136
137 autoFlush = _overrideTreeAutoFlush(logger, flags, stream, autoFlush)
138
139
140 logger.debug(f"{fileName=} {stream=} {compAlg=} {compLvl=} {autoFlush=} {splitLvl=} {dynSplitLvl=}")
141
142
143 outputCollection = "POOLContainer"
144 poolContainerPrefix = "CollectionTree"
145
146
147
148 isAugmentation = flags.hasFlag(f"Output.{stream}ParentStream")
149 if not isAugmentation:
150
151 PoolAttributes += [ pah.setFileCompAlg( fileName, compAlg ) ]
152 PoolAttributes += [ pah.setFileCompLvl( fileName, compLvl ) ]
153
154
155 if "AOD" in stream:
156 PoolAttributes += [ pah.setMaxBufferSize( fileName, "131072" ) ]
157 PoolAttributes += [ pah.setMinBufferEntries( fileName, "10" ) ]
158 else:
159
160
161 PoolAttributes += [ f"DatabaseName = '{fileName}'; INDEX_MASTER = 'POOLContainer(DataHeader)'" ]
162
163
164 outputCollection += f"_{stream}"
165 poolContainerPrefix += f"_{stream}"
166 OutputMetadataContainers += [f"MetaData_{stream}"]
167
168
169 PoolAttributes += [ pah.setTreeAutoFlush( fileName, poolContainerPrefix, autoFlush ) ]
170 PoolAttributes += [ pah.setTreeAutoFlush( fileName, outputCollection, autoFlush ) ]
171 PoolAttributes += [ pah.setTreeAutoFlush( fileName, "POOLContainerForm", autoFlush ) ]
172 PoolAttributes += [ pah.setTreeMaxSize( fileName, "*", "1099511627776L" ) ]
173 if flags.MP.UseSharedWriter and flags.MP.UseParallelCompression:
174 fileFlushSetting[fileName] = ( flags.MP.SharedWriter.FileFlushSetting.get(fileName, autoFlush) )
175 logger.info(f"Setting auto write for {fileName} to {fileFlushSetting[fileName]} events")
176
177
178 PoolAttributes += [ pah.setContainerSplitLevel( fileName, poolContainerPrefix, splitLvl ) ]
179 PoolAttributes += [ pah.setContainerSplitLevel( fileName, "Aux.", splitLvl ) ]
180 PoolAttributes += [ pah.setContainerSplitLevel( fileName, "Dyn.", dynSplitLvl ) ]
181
182
183
184
185 if "EVNT" in stream or "RDO" in stream:
186 PoolAttributes += [ f"DatabaseName = '{fileName}'; FILEFORWARD_COMPATIBILITY = '1'" ]
187
188 oneDHForm = False
189
190
191 maxAutoFlush =
max(maxAutoFlush, autoFlush)
192
193
194
195 useParallelCompression = flags.MP.UseSharedWriter and flags.MP.UseParallelCompression
196 if useParallelCompression:
197
198 requestedEvents = flags.Exec.MaxEvents
199 availableEvents = flags.Input.FileNentries - flags.Exec.SkipEvents
200 totalEntries = availableEvents
if requestedEvents == -1
else min( availableEvents, requestedEvents )
201 if ( totalEntries > 0 ) and ( maxAutoFlush > 0 ) and ( maxAutoFlush * flags.Concurrency.NumProcs > totalEntries ):
202 logger.info( "Not enough events to process, disabling parallel compression for SharedWriter!" )
203 logger.info( f"Processing {totalEntries} events in {flags.Concurrency.NumProcs} workers "
204 f"and a maximum (across all outputs) AutoFlush of {maxAutoFlush}")
205 useParallelCompression = False
206
207 if flags.MP.UseSharedReader or flags.MP.UseSharedWriter:
208 from AthenaPoolCnvSvc.PoolCommonConfig import AthenaPoolSharedIOCnvSvcCfg
209 return AthenaPoolSharedIOCnvSvcCfg(flags,
210 PoolAttributes=PoolAttributes,
211 ParallelCompression=useParallelCompression,
212 OutputMetadataContainers=OutputMetadataContainers,
213 OneDataHeaderForm=oneDHForm,
214 FileFlushSetting=fileFlushSetting,
215 PoolContainerNamingScheme=("Canonical" if "RNTUPLE" in flags.Output.DefaultContainerType else "Historical"))
216 else:
217 from AthenaPoolCnvSvc.PoolCommonConfig import AthenaPoolCnvSvcCfg
218 return AthenaPoolCnvSvcCfg(flags,
219 PoolAttributes=PoolAttributes,
220 OneDataHeaderForm=oneDHForm,
221 PoolContainerNamingScheme=("Canonical" if "RNTUPLE" in flags.Output.DefaultContainerType else "Historical"))