ATLAS Offline Software
Loading...
Searching...
No Matches
LArMerge_trf.py
Go to the documentation of this file.
1#!/usr/bin/env python
2
3# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
4
5
6
23
24import sys, os, pickle, pprint, subprocess
25
26
27
28# Utility function
29
30def getFileMap(fname, dsname, nevts=0, guid='') :
31 if os.path.isfile(fname) :
32 dataMap = { 'lfn': fname,
33 'dataset' : dsname,
34 'events' : nevts
35 }
36 if guid :
37 dataMap['GUID'] = guid
38 else :
39 dataMap = {}
40 return dataMap
41
42
43
44
45def larMerge(dataMap) :
46
47 print ("\n##################################################################")
48 print ( "## ATLAS Tier0 LAr CAF file Merging ##")
49 print ( "##################################################################\n")
50
51 print ("\nFull Tier-0 run options:\n")
52 pprint.pprint(dataMap)
53
54 inputList = []
55 inputDSName = None
56
57 for val in dataMap['inputLArFiles'] :
58 inputList.append(val.split('#')[1])
59 if not inputDSName :
60 inputDSName = val.split('#')[0]
61
62 print ("\ninputLArFiles list:\n")
63 pprint.pprint(inputList)
64
65 # output file
66 outputDSName = dataMap['outputLArFile'].split('#')[0]
67 outputFile = dataMap['outputLArFile'].split('#')[1]
68
69 print ('\nOutput file name:', outputFile)
70
71 retcode = 0
72 acronym = 'OK'
73
74 outFiles = []
75 inFiles = []
76 nEvents=0
77
78 cmdline=["LArSamplesMerge.exe"]
79 for fileName in inputList:
80 if os.access(fileName,os.R_OK):
81 cmdline.append(fileName)
82 else:
83 print ('ERROR : could not open file', fileName)
84 retcode = 74001
85 acronym = 'TRF_LAR_FILE_INPUT_ERROR'
86 break
87 pass
88
89 if (retcode==0):
90 writepath=os.path.split(outputFile)[0]
91 if writepath=="":
92 writepath="./"
93 if (os.access(writepath,os.W_OK)):
94 cmdline.append(outputFile)
95 else:
96 print ("ERROR, not allowed to write to oututfile", outputFile)
97 retcode = 74002
98 acronym = 'TRF_LAR_MERGE_ERROR'
99 pass
100 pass
101
102 if (retcode==0):
103
104 logfile=open("log.LArMerge","w")
105
106 try:
107 subprocess.check_call(cmdline,stdout=logfile,stderr=subprocess.STDOUT)
108 except Exception as e:
109 print ("ERROR exectution of subprocess failed")
110 print (e)
111 acronym = 'TRF_LAR_MERGE_ERROR'
112 pass
113
114 logfile.close()
115 logfile=open("log.LArMerge","r")
116
117 for line in logfile:
118 print (line, end='')
119 if line.startswith("Open file "):
120 linetok=line.split(" ")
121 inFiles.append(getFileMap(linetok[2], None, nevts=int(linetok[4])))
122 pass
123 if line.startswith("Wrote output file "):
124 linetok=line.split(" ")
125 nEvents=int(linetok[5])
126 outFiles=[getFileMap(linetok[3], outputDSName, nevts=nEvents),]
127 pass
128
129 logfile.close()
130
131
132
133 # assemble job report map, pickle it
134 outMap = { 'prodsys': { 'trfCode': retcode,
135 'trfAcronym': acronym,
136 'jobOutputs': outFiles,
137 'jobInputs': inFiles,
138 'nevents': nEvents,
139 }
140 }
141 f = open('jobReport.gpickle', 'wb')
142 pickle.dump(outMap, f)
143 f.close()
144
145 print ("\n##################################################################")
146 print ( "## End of job.")
147 print ( "##################################################################\n")
148
149 print (outMap)
150
151
154
155if __name__ == "__main__":
156
157 if len(sys.argv) == 2 and sys.argv[1].startswith('--argdict=') :
158 picklefile = sys.argv[1][len('--argdict='):]
159 # extract parameters from pickle file
160 print ("Using pickled file ", picklefile, " for input parameters")
161 f = open(picklefile, 'rb')
162 dataMap = pickle.load(f)
163 f.close()
164 larMerge(dataMap)
165 elif len(sys.argv) == 3 and sys.argv[1].startswith('--inputFiles=') and sys.argv[2].startswith('--outputFile=') :
166 inputFiles = sys.argv[1][13:].split(',')
167 outputFile = sys.argv[2][13:]
168 dataMap = {}
169 dataMap['inputLArFiles'] = inputFiles
170 dataMap['outputLArFile'] = outputFile
171 larMerge(dataMap)
172 else :
173 print ("Input format wrong --- either have: ")
174 print (" --argdict=<pickled-dictionary containing input info> ")
175 print (" with key/value pairs: ")
176 print (" or (old way): ")
177 print (" --inputFiles=file1,file2,...,fileN --outputFile=file")
178 exit(1)
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:177
larMerge(dataMap)
getFileMap(fname, dsname, nevts=0, guid='')