|
3 | 3 | # alias fluka2root-dir="parallel 'cd {} && fluka2root *.inp' ::: *" |
4 | 4 |
|
5 | 5 | import sys, re, os, argparse |
6 | | -import glob |
| 6 | +import glob, fnmatch |
7 | 7 | from tempfile import NamedTemporaryFile |
8 | 8 | from shutil import which |
9 | 9 |
|
@@ -84,6 +84,8 @@ def __init__(self, args): |
84 | 84 | print("output ROOT file:", self.root) |
85 | 85 |
|
86 | 86 | def Clean(self): |
| 87 | + if self.verbose: |
| 88 | + print("Cleaning tmp files...") |
87 | 89 | v = "-v" if self.verbose else "" |
88 | 90 | for f in self.inp: |
89 | 91 | n = "[0-9][0-9][0-9]" |
@@ -114,11 +116,13 @@ def getROOTFileName(self): |
114 | 116 | return os.path.basename(root) |
115 | 117 |
|
116 | 118 | def checkInputFiles(self): |
117 | | - """Does some checks of the input files |
| 119 | + """Do some checks of the input files |
118 | 120 |
|
119 | 121 | - check if all input files exist |
120 | 122 | - check whether input follows the standard Fluka format (free format is not supported) |
121 | 123 | """ |
| 124 | + if self.verbose: |
| 125 | + print("Checking input files...") |
122 | 126 |
|
123 | 127 | for f in self.inp: |
124 | 128 | if not os.path.isfile(f): |
@@ -182,6 +186,9 @@ def getOpenedUnits(self): |
182 | 186 | def assignUnits(self): |
183 | 187 | """Assigns units to estimators |
184 | 188 | """ |
| 189 | + if self.verbose: |
| 190 | + print("Assigning units to estimators...") |
| 191 | + |
185 | 192 | self.opened = self.getOpenedUnits() |
186 | 193 | if len(self.opened): |
187 | 194 | sys.exit("Opened units not yet supported") |
@@ -220,18 +227,24 @@ def assignUnits(self): |
220 | 227 | def assignFileNames(self): |
221 | 228 | """Assign file names to units |
222 | 229 | """ |
| 230 | + if self.verbose: |
| 231 | + print("Assigning file names to units...") |
| 232 | + |
| 233 | + all_files = glob.glob("*[0-9][0-9][0-9]_fort.*") |
| 234 | + |
223 | 235 | for e in self.estimators: |
224 | 236 | for u in e.units: |
225 | 237 | for inp in self.inp: |
226 | | - for f in glob.glob("%s[0-9][0-9][0-9]_fort.%d" % (os.path.splitext(inp)[0], abs(u))): |
227 | | - if f not in e.units[u]: # TODO: this can be done smarter |
| 238 | + pattern = "%s[0-9][0-9][0-9]_fort.%d" % (os.path.splitext(inp)[0], abs(u)) |
| 239 | + for f in fnmatch.filter(all_files, pattern): |
| 240 | + if f not in e.units[u]: # TODO: why do we need this check? |
228 | 241 | e.addFile(u,f) |
229 | 242 |
|
230 | 243 | def Merge(self): |
231 | 244 | """ Merge all data with standard FLUKA tools |
232 | 245 | """ |
233 | 246 | if self.verbose: |
234 | | - print("Merging...") |
| 247 | + print("Merging data files...") |
235 | 248 |
|
236 | 249 | tmpfiles=[] |
237 | 250 | for e in self.estimators: |
@@ -279,7 +292,7 @@ def Convert(self): |
279 | 292 | """Convert merged files into ROOT |
280 | 293 | """ |
281 | 294 | if self.verbose: |
282 | | - print("Converting...") |
| 295 | + print("Converting to ROOT...") |
283 | 296 |
|
284 | 297 | v = "-v" if self.verbose else "" |
285 | 298 |
|
|
0 commit comments