95 def moveOutputFiles(self):
96 from pathlib import Path
97 import shutil
98 self.logger.info("Moving the analysis root file and the hist file to the top level.")
99 workDir = Path(self.args.work_dir) if self.args.work_dir else Path('workDir')
100 rootfileSymlink = (workDir / 'data-ANALYSIS' / f'{self.outputName}.root')
101 rootfilePath = rootfileSymlink.resolve()
102 histfileSymlink = (workDir / f'hist-{self.outputName}.root')
103 histfilePath = histfileSymlink.resolve()
104 currentDir = Path.cwd()
105
106 if rootfilePath.exists():
107 self.logger.info(f"Moving {rootfilePath} to {currentDir / f'{self.outputName}.root'}")
108 if rootfileSymlink.is_symlink():
109 rootfileSymlink.unlink()
110 shutil.move(str(rootfilePath), str(currentDir / f"{self.outputName}.root"))
111 else:
112 self.logger.warning(f"Root file {rootfilePath} does not exist or merging is enabled, skipping move.")
113
114 if histfilePath.exists():
115 self.logger.info(f"Moving {histfilePath} to {currentDir / f'hist-{self.outputName}.root'}")
116 if histfileSymlink.is_symlink():
117 histfileSymlink.unlink()
118 shutil.move(str(histfilePath), str(currentDir / f"hist-{self.outputName}.root"))
119 else:
120 self.logger.warning(f"Histogram file {histfilePath} does not exist or merging, skipping move.")
121
122
123 for streamDir in sorted(workDir.glob('data-*')):
124 stream = streamDir.name.removeprefix('data-')
125 if stream == 'ANALYSIS':
126 continue
127 streamSymlink = streamDir / f'{self.outputName}.root'
128 streamPath = streamSymlink.resolve()
129 target = currentDir / f"{self.outputName}_{stream.removeprefix('ANALYSIS_')}.root"
130 if streamPath.exists():
131 self.logger.info(f"Moving {streamPath} to {target}")
132 if streamSymlink.is_symlink():
133 streamSymlink.unlink()
134 shutil.move(str(streamPath), str(target))
135 else:
136 self.logger.warning(f"Root file {streamPath} does not exist, skipping move.")
137
138 newHistFile = currentDir / f"hist-{self.outputName}.root"
139
140 if self.args.merge_output_files and newHistFile.exists():
141 self.logger.info(f"renaming the hist-{self.outputName}.root to {self.outputName}.root")
142 newHistFile.rename(currentDir / f"{self.outputName}.root")
143