ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
InnerDetector
InDetConditions
TRT_ConditionsAlgs
share
CompareStatusIO.py
Go to the documentation of this file.
1
import
os,sys,argparse
2
3
parser = argparse.ArgumentParser(description=
"%prog [options]"
, formatter_class=argparse.ArgumentDefaultsHelpFormatter)
4
parser.add_argument(
"-doStatus"
, dest=
'doStatus'
, action=
'store_true'
, default=
False
, help=
"compare Status tag"
)
5
parser.add_argument(
"-doStatusHT"
, dest=
'doHT'
, action=
'store_true'
, default=
False
, help=
"compare StatusHT tag"
)
6
parser.add_argument(
"-doStatusPermanent"
, dest=
'doPermanent'
, action=
'store_true'
, default=
False
, help=
"compare StatusPermanent tag"
)
7
parser.add_argument(
"-inFile"
, dest=
'IFile'
, default=
None
, help=
"hand-made file (input to txt2db_template.py) to compare to output"
)
8
parser.add_argument(
"-outFile"
, dest=
'OFile'
, default=
None
, help=
"file dumped from db2txt_template.py to compare to input"
)
9
args = parser.parse_args()
10
11
IFileIn= args.IFile
12
OFileIn= args.OFile
13
14
ITxt=open(IFileIn).readlines()
15
OTxt=open(OFileIn).readlines()
16
17
Inewtokens=[]
18
Onewtokens=[]
19
20
def
main
():
21
isPermanent=
False
22
isHT=
False
23
isStatus=
False
24
25
if
not
(args.doStatus
or
args.doPermanent
or
args.doHT):
26
print
"please specify doStatus, doPermanent, and/or doHT"
27
return
28
29
# figure out type we are comparing
30
for
line
in
OTxt:
31
if
"permanent Status"
in
line:
32
isPermanent=
True
33
if
"HT Status"
in
line:
34
isHT=
True
35
if
"Status"
in
line
and
not
(
"permanent"
in
line
or
"HT"
in
line):
36
isStatus=
True
37
if
(args.doPermanent
and
not
isPermanent)
or
(args.doHT
and
not
isHT)
or
(args.doStatus
and
not
isStatus):
38
print
"check your inputs, they don't have the requested Status type"
39
return
40
41
# loop through input
42
# FIXME: assuming the input only has one conditions type (HT or Permanent but not both)
43
for
line
in
ITxt:
44
line=line.replace(
" "
,
" "
)
45
line=line[0].
replace
(
" "
,
""
)+line[1:]
# remove leading spaces
46
line=line[:-1]+line[-1].
replace
(
" "
,
""
)
# remove trailing spaces
47
tokens=line.split(
" "
)
48
if
len(tokens)<6:
49
if
not
"Status:"
in
tokens:
50
print
"length not satisfied: "
,tokens
51
continue
52
Inewtokens.append(line.split(
"\n"
)[0])
53
54
# loop through output to match input formatting
55
seenStart=
False
56
seenEnd=
False
57
for
line
in
OTxt:
58
line=line.replace(
" "
,
" "
)
59
line=line[0].
replace
(
" "
,
""
)+line[1:]
# remove leading spaces
60
if
isPermanent
or
isStatus:
61
line=line.replace(
"257"
,
"1"
)
# different formatting of "bad" straws
62
line=line[:-1]+line[-1].
replace
(
" "
,
""
)
# remove trailing spaces
63
if
(isHT
or
isStatus)
and
"2"
in
line.split(
" "
)[-1].
split
(
"\n"
)[0]:
64
# ignore lines that end in 2 because they're Xe in StatusHT and alive in Status
65
continue
66
tokens=line.split(
" "
)
67
if
args.doPermanent:
68
if
(
not
seenEnd)
and
"permanent"
in
tokens:
69
seenStart=
True
70
elif
seenStart
and
"Status:"
in
tokens:
71
seenEnd=
True
72
elif
args.doHT:
73
if
(
not
seenEnd)
and
"HT"
in
tokens:
74
seenStart=
True
75
elif
seenStart
and
"Status:"
in
tokens:
76
seenEnd=
True
77
elif
args.doStatus:
78
if
(
not
seenEnd)
and
"Status:"
in
tokens
and
not
(
"HT"
in
tokens
or
"permanent"
in
tokens):
79
seenStart=
True
80
elif
seenStart
and
(
"HT"
in
tokens
or
"permanent"
in
tokens):
81
seenEnd=
True
82
if
seenStart
and
not
seenEnd:
83
if
len(tokens)<6 :
84
if
not
"Status:"
in
tokens:
85
print
"length not satisfied: "
,tokens
86
continue
87
Onewtokens.append(tokens[0]+
" "
\
88
+tokens[2]+
" "
\
89
+tokens[4]+
" "
\
90
+tokens[3]+
" "
\
91
+tokens[1]+
" "
\
92
+tokens[5].
split
(
"\n"
)[0] \
93
)
94
95
print
set
(Inewtokens) ^
set
(Onewtokens)
# checking symmetric difference
96
97
if
__name__==
'__main__'
:
98
main
()
set
STL class.
replace
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition
hcg.cxx:312
split
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition
hcg.cxx:179
CompareStatusIO.main
main()
Definition
CompareStatusIO.py:20
Generated on
for ATLAS Offline Software by
1.17.0