-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextractDataModel.py
executable file
·321 lines (267 loc) · 8.39 KB
/
extractDataModel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
#!/usr/bin/python3.6
import os
import sys
import ALICEO2includeFile as O2IF
import ALICEO2codeFile as O2CF
import xml.etree.ElementTree as ET
# -----------------------------------------------------------------------------
# mainDataModel
#
# .............................................................................
def mainDataModel(DMs, initCard, todo=0):
# O2dir and main header file
O2dir = initCard.find('O2general/mainDir/O2local')
if O2dir == None:
return None
O2dir = O2dir.text.strip()
mainProducer = initCard.find('O2general/producer')
if mainProducer == None:
mainProducer = "AO2D files"
else:
mainProducer = mainProducer.text.strip()
# find DataModel of type='Main'
dm = None
for subDM in DMs:
ptype = subDM.attrib['type']
if ptype == 'Main':
dmname = subDM.attrib['name']
fileName = subDM.find('headerFiles/fileName')
if fileName != None:
fileName = O2dir+'/'+fileName.text.strip()
if todo == 1:
print(" name: ", fileName)
dm = O2IF.datamodel(mainProducer, ["", "", mainProducer, ptype, dmname], fileName, initCard)
dm.setCategories(subDM)
break
return dm
# -----------------------------------------------------------------------------
# updateDataModel
#
# .............................................................................
def updateDataModel(O2Physicsdir, dm, subDM, todo=0):
ptype = subDM.attrib['type']
dmname = subDM.attrib['name']
hfMainDir = subDM.find('headerFiles/mainDir')
if hfMainDir == None:
hfMainDir = ""
else:
hfMainDir = hfMainDir.text.strip()
hfMainDir = O2Physicsdir+"/"+hfMainDir
hftmps = subDM.find('headerFiles/fileName')
if hftmps == None:
hftmps = "*.h"
else:
hftmps = hftmps.text.strip()
inclfiles = list()
sname = ""
for hftmp in hftmps.split(','):
sname = sname+" "+hfMainDir+"/"+hftmp.strip()
stream = os.popen("ls -1 2> null"+sname)
inclfiles.extend(stream.readlines())
# loop over these header files and join the related datamodels
# with the dm
for infile in inclfiles:
if todo == 1:
print(" ", infile.rstrip())
# extract datamodel name
path = infile.split('/')[:-1]
cfile = infile.split('/')[-1]
CErelation = [path, cfile, "", ptype, dmname]
dmnew = O2IF.datamodel(cfile.split(".")[0], CErelation, infile.rstrip())
dm.join(dmnew)
return True
# -----------------------------------------------------------------------------
# addCERelations
#
# .............................................................................
def addCERelations(O2Physicsdir, cerelations, subDM, todo=0):
ptype = subDM.attrib['type']
dmname = subDM.attrib['name']
cmMainDir = subDM.find('CMLfiles/mainDir')
if cmMainDir == None:
cmMainDir = ""
else:
cmMainDir = cmMainDir.text.strip()
cmMainDir = O2Physicsdir+"/"+cmMainDir
cmtmps = subDM.find('CMLfiles/fileName')
if cmtmps == None:
cmtmps = "CMakeLists.txt"
else:
cmtmps = cmtmps.text.strip()
cmakefiles = list()
sname = ""
for cmtmp in cmtmps.split(','):
sname = sname+" "+cmMainDir+"/"+cmtmp.strip()
if todo == 1:
print(" ", sname)
stream = os.popen("ls -1 2> null "+sname)
cmakefiles.extend(stream.readlines())
for cfile in cmakefiles:
cfile = cfile.rstrip("\n")
cerelations.addRelations(cfile, ptype, dmname)
return True
# -----------------------------------------------------------------------------
# setProducers
#
# .............................................................................
def setProducers(O2Physicsdir, cerelations, dm, subDM, todo=0):
codeMainDir = subDM.find('codeFiles/mainDir')
if codeMainDir == None:
codeMainDir = ""
else:
codeMainDir = codeMainDir.text.strip()
codeMainDir = O2Physicsdir+"/"+codeMainDir
codetmps = subDM.find('codeFiles/fileName')
if codetmps == None:
codetmps = "*.cxx"
else:
codetmps = codetmps.text.strip()
codefiles = list()
sname = ""
for codetmp in codetmps.split(','):
sname = sname+" "+codeMainDir+"/"+codetmp.strip()
stream = os.popen("grep -l Produces "+sname)
cfiles = stream.readlines()
codefiles.extend(cfiles)
if todo == 1:
for cfile in cfiles:
print(" ", cfile.rstrip("\n"))
# loop over these code files and find out which tables they produce
# update the data model accordingly using setProducer
for codefile in codefiles:
codefile = codefile.rstrip("\n")
CErelation = cerelations.getExecutable(codefile)
codeFile = O2CF.codeFile(codefile)
for tableName in codeFile.tableNames:
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# ATTENTION
# Here it is assumed that all tables are in namespace o2::aod
# and is explicitely set so here
#
tableName = "o2::aod::"+tableName.split("::")[-1]
#
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
dm.setProducer(CErelation, tableName)
return True
# -----------------------------------------------------------------------------
# main
#
# .............................................................................
def main(initCard, todo=0):
# DataModel definitions
DMs = initCard.find('DataModels')
if DMs == None:
return
# =============================================== main header file ============
if todo == 1:
print("Main header file:")
dm = mainDataModel(DMs, initCard, todo)
if dm == None:
return
# =============================================== other header files ==========
# now get additional header files with table/column declarations
# the directories to consider
# O2Physicsdir
O2Physicsdir = initCard.find('O2general/mainDir/O2Physicslocal')
if O2Physicsdir == None:
return
O2Physicsdir = O2Physicsdir.text.strip()
if todo == 1:
print()
print("Other header files:")
# join Helper data models
if todo == 1:
print()
print(" Helpers:")
isOK = False
for subDM in DMs:
if subDM.attrib['type'] == 'Helper':
isOK = updateDataModel(O2Physicsdir, dm, subDM, todo)
break
if not isOK:
return
# join PWG data models
if todo == 1:
print()
print(" PWGs:")
for subDM in DMs:
if subDM.attrib['type'] == 'PWG':
isOK = isOK & updateDataModel(O2Physicsdir, dm, subDM, todo)
if not isOK:
return
# synchronize the entire datamodel
dm.synchronize()
# =============================================== CMakeLists.txt ==============
# analyze CMakeLists.txt and extract code - executable relations defined
# with o2_add_dpl_workflow
if todo == 1:
print()
print("CMakeLists:")
cerelations = O2IF.CERelations(initCard)
# add CERelations for Helper tasks
if todo == 1:
print()
print(" Helpers:")
isOK = False
for subDM in DMs:
if subDM.attrib['type'] == 'Helper':
isOK = addCERelations(O2Physicsdir, cerelations, subDM, todo)
break
if not isOK:
return
# add CERelations for PWG tasks
if todo == 1:
print()
print(" PWGs:")
for subDM in DMs:
if subDM.attrib['type'] == 'PWG':
isOK = isOK & addCERelations(O2Physicsdir, cerelations, subDM, todo)
if not isOK:
return
# =============================================== code files ==================
# get a list of producer code files (*.cxx)
if todo == 1:
print()
print("Code files:")
# add Helper code files
if todo == 1:
print()
print(" Helpers:")
isOK = False
for subDM in DMs:
if subDM.attrib['type'] == 'Helper':
isOK = setProducers(O2Physicsdir, cerelations, dm, subDM, todo)
break
if not isOK:
return
# add PWG code files
if todo == 1:
print()
print(" PWGs:")
for subDM in DMs:
if subDM.attrib['type'] == 'PWG':
isOK = isOK & setProducers(O2Physicsdir, cerelations, dm, subDM, todo)
if not isOK:
return
# =============================================== print out ===================
# print the data model
if todo == 1:
for rel in cerelations.relations:
for r in rel:
print(r)
print("")
if todo == 2:
dm.print()
if todo == 3:
dm.printHTML()
# -----------------------------------------------------------------------------
if __name__ == "__main__":
initCard = ET.parse("inputCard.xml")
# which action
todo = initCard.find('action')
if todo == None:
todo = 1
else:
todo = int(todo.text)
main(initCard, todo)
# -----------------------------------------------------------------------------