forked from mcoquet642/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextractDataModel.py
More file actions
executable file
·197 lines (165 loc) · 5.49 KB
/
extractDataModel.py
File metadata and controls
executable file
·197 lines (165 loc) · 5.49 KB
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
#!/usr/bin/env python3
import os
import sys
import ALICEO2dataModel as DM
import xml.etree.ElementTree as ET
# -----------------------------------------------------------------------------
# main
#
# .............................................................................
def main(initCard):
# which action
todo = initCard.find('action')
if todo == None:
todo = 1
else:
todo = int(todo.text)
# O2dir and main header file
O2dir = initCard.find('O2general/mainDir/O2local')
if O2dir == None:
return
O2dir = O2dir.text.strip()
DMH = initCard.find('O2general/DataModelHeader')
if DMH == None:
return
fileName = O2dir+"/"+DMH.text.strip()
mainProducer = initCard.find('O2general/producer')
if mainProducer == None:
mainProducer = "AO2D files"
else:
mainProducer = mainProducer.text.strip()
# =============================================== main header file ============
# read the file and create AO2D datamodel
if todo == 1:
print("Main header file: ", fileName)
dm = DM.datamodel(mainProducer, ["", "", mainProducer], fileName, initCard)
# now get additional header files with table/column declarations
# the directories to consider
if todo == 1:
print()
print("Other header files")
# =============================================== other header files ==========
# O2Physicsdir
O2Physicsdir = initCard.find('O2general/mainDir/O2Physicslocal')
if O2Physicsdir == None:
return
O2Physicsdir = O2Physicsdir.text.strip()
hfMainDir = initCard.find('headerFiles/mainDir')
if hfMainDir == None:
hfMainDir = ""
else:
hfMainDir = hfMainDir.text.strip()
hfMainDir = O2Physicsdir+"/"+hfMainDir
hfSubDirs = initCard.find('headerFiles/subDirs')
if hfSubDirs == None:
hfSubDirs = ['']
else:
hfSubDirs = hfSubDirs.text.strip().split(",")
hftmp = initCard.find('headerFiles/fileName')
if hftmp == None:
hftmp = "*.h"
else:
hftmp = hftmp.text.strip()
inclfiles = list()
for hfSubDir in hfSubDirs:
sname = hfMainDir+"/"+hfSubDir.strip()+"/"+hftmp
stream = os.popen("ls -1 "+sname)
inclfiles.extend(stream.readlines())
# loop over these header files and join the related datamodels
# with the AO2D datamodel
for infile in sorted(inclfiles):
# extract datamodel name
path = infile.split('/')[:-1]
cfile = infile.split('/')[-1]
CErelation = [path, cfile, ""]
if todo == 1:
print(" ", infile.rstrip())
dmnew = DM.datamodel(cfile.split(".")[0], CErelation, infile.rstrip())
dm.join(dmnew)
# =============================================== CMakeLists.txt ==============
# analyze CMakeLists.txt and extract code - executable relations defined
# with o2_add_dpl_workflow
# the directories to consider
if todo == 1:
print()
print("CMakeLists.txt")
cmMainDir = initCard.find('CMLfiles/mainDir')
if cmMainDir == None:
cmMainDir = ""
else:
cmMainDir = cmMainDir.text.strip()
cmMainDir = O2Physicsdir+"/"+cmMainDir
cmSubDirs = initCard.find('CMLfiles/subDirs')
if cmSubDirs == None:
cmSubDirs = [""]
else:
cmSubDirs = cmSubDirs.text.strip().split(",")
cmtmp = initCard.find('CMLfiles/fileName')
if cmtmp == None:
cmtmp = "*"
else:
cmtmp = cmtmp.text.strip()
cmakefiles = list()
for cmSubDir in cmSubDirs:
sname = cmMainDir+"/"+cmSubDir.strip()+"/"+cmtmp
if todo == 1:
print(" ", sname)
stream = os.popen("ls -1 "+sname)
cmakefiles.extend(stream.readlines())
cerelations = DM.CERelations(initCard)
for cfile in sorted(cmakefiles):
cfile = cfile.rstrip("\n")
cerelations.addRelations(cfile)
# =============================================== code files ==================
# get a list of producer code files (*.cxx)
# the directories to consider
if todo == 1:
print()
print("Code files")
codeMainDir = initCard.find('codeFiles/mainDir')
if codeMainDir == None:
codeMainDir = ""
else:
codeMainDir = codeMainDir.text.strip()
codeMainDir = O2Physicsdir+"/"+codeMainDir
codeSubDirs = initCard.find('codeFiles/subDirs')
if codeSubDirs == None:
codeSubDirs = [""]
else:
codeSubDirs = codeSubDirs.text.strip().split(",")
codetmp = initCard.find('codeFiles/fileName')
if codetmp == None:
codetmp = "*"
else:
codetmp = codetmp.text.strip()
codefiles = list()
for codeSubDir in codeSubDirs:
sname = codeMainDir+"/"+codeSubDir.strip()+"/"+codetmp
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 an 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)
stream = os.popen("grep Produces "+codefile)
prods = stream.readlines()
for prod in prods:
prod = prod.rstrip("\n").strip()
tableName = DM.fullDataModelName("o2::aod", prod.split("<")[-1].split(">")[0])
dm.setProducer(CErelation, tableName)
# =============================================== print out ===================
# print the data model
if todo == 2:
dm.print()
if todo == 3:
dm.printHTML()
# -----------------------------------------------------------------------------
if __name__ == "__main__":
initCard = ET.parse("inputCard.xml")
main(initCard)
# -----------------------------------------------------------------------------