ATLAS Offline Software
test_pythinning.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import os
4 from AthenaCommon import ChapPy
5 
6 from future import standard_library
7 standard_library.install_aliases()
8 import subprocess
9 
10 
11 EVTMAX = 5
12 
13 
15 def workDir( fileName ):
16  if 'ATN_WORK_AREA' in os.environ:
17  workArea = os.environ['ATN_WORK_AREA']
18  else:
19  workArea = "tmp-pythinning"
20  pass
21  if not os.path.exists(workArea):
22  os.makedirs(workArea)
23  return os.path.join( workArea, fileName )
24 
25 
26 def doValidation( validationName, refFileName, chkFileName, chkFilter ):
27  print ("## Validation of [%s]" % validationName)
28  print ("## ref: %s" % refFileName)
29  print ("## chk: %s" % chkFileName)
30  print ("## filter: [%s]" % chkFilter)
31  sc, out = subprocess.getstatusoutput( "cat %s | %s | diff -u %s -" % \
32  ( chkFileName, chkFilter,
33  refFileName ) )
34  if sc == 0 and len(out) == 0: print ("==> Validation [OK]")
35  else: print ("==> Validation [ERROR]\n",
36  "*"*80,out,"*"*80)
37  return sc, out
38 
39 
40 def installRefFiles( fileNames ):
41  for refFile in fileNames:
42  for fileName in [ refFile, workDir(refFile) ]:
43  if os.path.exists(fileName):
44  os.remove(fileName)
45  sc,out = subprocess.getstatusoutput( "get_files %s" % refFile )
46  if sc != 0:
47  print ("## ERROR: could not retrieve [%s]" % refFile)
48  print ("## reason:\n",out)
49  continue
50  if os.path.exists(refFile) and \
51  os.path.exists(workDir(refFile)) and \
52  os.path.samefile( refFile, workDir(refFile) ):
53  print (" -%s" % workDir(refFile))
54  continue
55  sc,out = subprocess.getstatusoutput( "mv %s %s" % ( refFile,
56  workDir(refFile) ) )
57  if sc != 0:
58  print ("## ERROR: could not install [%s] into [%s]" %
59  ( refFile, workDir(refFile) ))
60  print ("## reason:\n",out)
61  continue
62  else:
63  print (" -%s" % workDir(refFile))
64  return
65 
66 
67 print ("#"*80)
68 print ("## testing Thinning exercize...")
69 print ("## installing reference files...")
70 installRefFiles( [ "AthExThinning_makeData.ref",
71  "pyWriteThinnedData.ref",
72  "ReadThinnedData.ref",
73  "ReadNonThinnedData.ref",
74  ] )
75 
76 
77 print ("\n")
78 print ("#"*80)
79 print ("## Preparing input data...")
80 jobOptions = [
81  ChapPy.JobOptionsCmd( "OUTPUT=\"%s\"" % workDir("my.pydata.tothin.pool") ),
82  ChapPy.JobOptions( "AthExThinning/AthExThinning_makeData.py" ),
83  ]
84 
85 athena = ChapPy.Athena( jobOptions = jobOptions,
86  logFile = workDir( "my.pydata.tothin.pool.log" ),
87  checkLeak = False )
88 athena.EvtMax = EVTMAX
89 athena.run()
90 
91 
92 print ("\n")
93 print ("#"*80)
94 sc,out = doValidation( "Input Data",
95  workDir("AthExThinning_makeData.ref"),
96  workDir("my.pydata.tothin.pool.log"),
97  "grep '^CreateData' | grep INFO " )
98 if sc != 0:
99  raise SystemExit("ERROR")
100 
101 
102 print ("\n")
103 print ("#"*80)
104 print ("## Testing [writing thinned data]...")
105 jobOptions = [
106  ChapPy.JobOptionsCmd( "INPUT=[\"%s\"]" % workDir("my.pydata.tothin.pool") ),
107  ChapPy.JobOptionsCmd( "OUTPUT=\"%s\"" % workDir("pythinned.data.pool") ),
108  ChapPy.JobOptionsCmd( "ALGMODE=\"py\"" ),
109  ChapPy.JobOptions( "AthExThinning/WriteThinnedData_jobOptions.py" ),
110  ]
111 
112 athena = ChapPy.Athena( jobOptions = jobOptions,
113  logFile = workDir("pythinned.data.pool.log"),
114  checkLeak = False )
115 athena.EvtMax = -1
116 athena.run()
117 
118 
119 print ("\n")
120 print ("#"*80)
121 sc,out = doValidation( "PyWriteThinnedData",
122  workDir("pyWriteThinnedData.ref"),
123  workDir("pythinned.data.pool.log"),
124  "grep \"^Py:WriteThinnedData \"" )
125 if sc != 0:
126  raise SystemExit("ERROR")
127 
128 
129 print ("\n")
130 print ("#"*80)
131 print ("## Testing [reading thinned data]...")
132 jobOptions = [
133  ChapPy.JobOptionsCmd( "INPUT=[\"%s\"]" % workDir("pythinned.data.pool") ),
134  ChapPy.JobOptionsCmd( "OUTPUT=\"%s\"" % workDir("reaccessed.pythinned.data.pool") ),
135  ChapPy.JobOptions( "AthExThinning/ReadThinnedData_jobOptions.py" ),
136  ]
137 
138 athena = ChapPy.Athena( jobOptions = jobOptions,
139  logFile = workDir("reaccessed.pythinned.data.pool.log"),
140  checkLeak = False )
141 athena.EvtMax = -1
142 athena.run()
143 
144 
145 print ("\n")
146 print ("#"*80)
147 sc,out = doValidation( "ReadThinnedData",
148  workDir("ReadThinnedData.ref"),
149  workDir("reaccessed.pythinned.data.pool.log"),
150  "grep \"^ReadThinnedData \" | grep -v \"Property update for OutputLevel\" | grep -v \"input handles\" | grep -v \"output handles\" | grep -v \"Data Deps for\"" )
151 if sc != 0:
152  raise SystemExit("ERROR")
153 
154 
155 
156 print ("\n")
157 print ("#"*80)
158 print ("## Testing [reading non-thinned data]...")
159 jobOptions = [
160  ChapPy.JobOptionsCmd( "INPUT=[\"%s\"]" % workDir("non.pythinned.data.pool") ),
161  ChapPy.JobOptionsCmd( "OUTPUT=\"%s\"" % workDir("reaccessed.non.pythinned.data.pool") ),
162  ChapPy.JobOptions( "AthExThinning/ReadNonThinnedData_jobOptions.py" ),
163  ]
164 
165 athena = ChapPy.Athena( jobOptions = jobOptions,
166  logFile = workDir("reaccessed.non.pythinned.data.pool.log"),
167  checkLeak = False )
168 athena.EvtMax = -1
169 athena.run()
170 
171 
172 print ("\n")
173 print ("#"*80)
174 sc,out = doValidation( "ReadNonThinnedData",
175  workDir("ReadNonThinnedData.ref"),
176  workDir("reaccessed.non.pythinned.data.pool.log"),
177  "grep \"^Py:ReadNonThinnedData \"" )
178 if sc != 0:
179  raise SystemExit("ERROR")
180 
181 print ("")
182 print ("## [All tests completed]")
183 print ("## Bye.")
184 print ("#"*80)
test_pythinning.installRefFiles
def installRefFiles(fileNames)
Definition: test_pythinning.py:40
test_pythinning.doValidation
def doValidation(validationName, refFileName, chkFileName, chkFilter)
Definition: test_pythinning.py:26
test_pythinning.workDir
def workDir(fileName)
Definition: test_pythinning.py:15