forked from kmcdermo/TkRelVal
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstart.py
More file actions
179 lines (145 loc) · 7.93 KB
/
start.py
File metadata and controls
179 lines (145 loc) · 7.93 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
# coding=utf-8
import sys
import os
from configparser import ConfigParser
import argparse
import numpy as np
import getpass
from collisions.lumiCalc import *
from common.utils import *
def new_html_line(html_file,release,newline,val):
# with file_lock:
with open(html_file, "r") as file:
lines = file.readlines()
## look for the range of line i can watch, depending on the val value
## in fact, alca validation are in the first part of the html file, while release validations are the second part
## i want the two columns to be almast independent, so i can add the new line in the right place
start = len(lines)
end = len(lines)
if val == "AlCa":
for i, line in enumerate(lines):
if line.strip().startswith("<div class=\"right-column\">"):
start = i
if line.strip().startswith("</div>"):
end = i
## qui mi devo fermare al primo </div> che trovo, perche' e' quello che chiude la prima colonna
break
elif val == "Release":
for i, line in enumerate(lines):
if line.strip().startswith("<div class=\"left-column\">"):
start = i
if line.strip().startswith("</div>"):
end = i
## qui invece se mi fermo al primo, non trovo lo start.. vado avanti, niente break!!
if start == len(lines):
print("ERROR:: start not found in the hmlt file! Something went wrong")
sys.exit(1)
## i dont want to add new lines if they are already there
selected_lines = [line.strip() for i, line in enumerate(lines) if i >= start and i < end]
if newline not in selected_lines:
found_chapter = False
last_index = 0
for i, line in enumerate(lines):
if start < i < end:
if line.strip().startswith("<OL>{}".format(release)):
found_chapter = True
if line.strip() == "</UL>":
if found_chapter == True:
lines.insert(i, " {}\n".format(newline))
break
else:
last_index = i
if last_index != 0 and found_chapter == False:
lines.insert(last_index, " </UL>\n")
lines.insert(last_index, " {}\n".format(newline))
lines.insert(last_index, " <UL>\n")
lines.insert(last_index, " <OL>{}\n".format(release))
lines.insert(last_index, " <BR>\n")
lines.insert(last_index, " <BR>\n")
lines.insert(last_index, " <BR>\n")
lines.insert(last_index, " </OL>\n")
lines.insert(last_index, " </UL>\n")
if last_index == 0:
print("ERROR:: last </UL> not found in the hmlt file! Something went wrong")
sys.exit(1)
with open(html_file, "w") as file:
file.write("".join(lines))
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Command line parser for starting the tracking validation repo')
parser.add_argument('--refFile', dest='referenceFile', help='old release version', required = True)
parser.add_argument('--targetFile', dest='targetFile', help='new release version', required = True)
parser.add_argument('--refLabel', dest='referenceLabel', help='label name for the reference file. It will appear on graphs and in the folder name', required = False)
parser.add_argument('--targetLabel', dest='targetLabel', help='label name for the target file. It will appear on graphs and in the folder name', required = False)
parser.add_argument('--lumi', dest='lumi', help='lumi in ', required = False)
parser.add_argument('--FullPlots', dest='FullPlots', help='command to produce ALL the plots', default = False, action = 'store_true', required = False)
# parser.add_argument('--v', dest='verbose', help='Optional prints with retrieved infos', default = True, action = 'store_false', required = False)
args = parser.parse_args()
user = getpass.getuser()
oldFileName = args.referenceFile
newFileName = args.targetFile
oldFile = oldFileName.split("/")[-1]
newFile = newFileName.split("/")[-1]
print(oldFile)
## find the run number
oldRun = findRun(oldFile)
newRun = findRun(newFile)
if newRun != oldRun or newRun is None or oldRun is None:
print("ERROR:: FOUND ERROR IN RUN NUMBER. THERY ARE NOT EQUAL!")
# exit()
## find the era
oldEra = findEra(oldFile)
newEra = findEra(newFile)
def is_valid_era(era):
return bool(re.fullmatch(r"20(22|23|24)[B-F]", era))
if not (is_valid_era(oldEra) and is_valid_era(newEra)):
print("WARNING:: ERA NOT FOUND!")
newEra = "X"
oldEra = "X"
if newEra != oldEra:
print("WARNING:: FOUND ERROR IN ERA. THEY ARE NOT EQUAL!")
## find the sample name
oldSample = findSample(oldFile)
newSample = findSample(newFile)
if newSample != oldSample or newSample is None or oldSample is None:
print("ERROR:: FOUND ERROR IN SAMPLE NAME. THERY ARE NOT THE SAME!")
# exit()
## find the "release" name
oldRelease = findRelease(oldFile)
newRelease = findRelease(newFile)
## find the label name, only if it is not given as input. If it is given, it will be used
## if args.referenceLabel is None and/or args.targetLabel is None they are hendled as input, so everything is fine
print(("OLD RELEASE: {}".format(oldRelease)))
print(("NEW RELEASE: {}".format(newRelease)))
oldLabelName, newLabelName = findLabel(oldRelease, newRelease, oldRun, args.referenceLabel, args.targetLabel)
folderName = make_folder_name(oldRun, oldSample, oldRelease, oldLabelName, newRelease, newLabelName)
# Before executing the macro, which takes quite much time, I update the index.html so that i can view the plots!
# Now I search for the first "</UL>" word and insert an HREF to see the new folder in the webpage! search by line number and then insert a line
# Not the smartest way, need to work on this one day
htmlFile="/eos/project/c/cmsweb/www/tracking/validation/DATA/index.html"
chap = oldRelease.split("_")[0] + " " + oldRelease.split("_")[1]+"_"+oldRelease.split("_")[2]+"_X"
newstring = "<LI><A HREF=\""+folderName+"/index.html\">"+folderName+","+oldEra+"</A></LI>"
## check if afs is abulla (user) or magdy
## in the first case, pass "Release" as a parameter, in the second case, pass "AlCa"
## this is used to tore validtions on the left or right side of the page
current_path = os.getcwd()
if "abulla" not in current_path or user not in current_path :
new_html_line(htmlFile, chap, newstring, "AlCa")
else:
new_html_line(htmlFile, chap, newstring, "Release")
## now i need to check if the lumi is the same. If it is not, i need to print a warning and use the old one
oldLumi = str(round(float(LumiCalc(oldFileName)),2))
print("sto qui")
newLumi = str(round(float(LumiCalc(newFileName)),2))
print("sto qua")
if oldLumi != newLumi:
print(("WARNING:: FOUND DIFFERENT LUMINOSITY VALUES: "+oldLumi+" vs "+newLumi))
print(("WARNING:: USING THE OLD LUMINOSITY VALUE: "+oldLumi))
# FROM THIS POINT I SHOULD TRANSLATE THE .SH FILE..
# I do not have time at this moment, but i will one day.
# for now, i just use the sh
import subprocess
os.chdir(f'/afs/cern.ch/user/a/{user}/CMSSW_14_0_0/src/TkRelVal/collisions')
if args.FullPlots == True:
rc = subprocess.call(["./makeValidationPlots.sh", oldRun,oldFileName,oldLabelName,newFileName,newLabelName,folderName,oldEra,oldLumi,newLumi,"true"])
else:
rc = subprocess.call(["./makeValidationPlots.sh", oldRun,oldFileName,oldLabelName,newFileName,newLabelName,folderName,oldEra,oldLumi,newLumi])