Add-on by F. Blanco: code to manage leading particle and cuts with respect to that
[u/mrichter/AliRoot.git] / test / Violation.cmake
CommitLineData
eee962e6 1cmake_minimum_required(VERSION 2.8)
2
3if(COMMAND CMAKE_POLICY)
4 if(POLICY CMP0009)
5 cmake_policy(SET CMP0009 NEW)
6 endif(POLICY CMP0009)
7endif(COMMAND CMAKE_POLICY)
8
9#Run Checkaliroot to get latest violations
10execute_process(COMMAND make -k check-all
11 WORKING_DIRECTORY $ENV{ALICE_INSTALL}
12 OUTPUT_FILE CheckAliroot.log )
13
14find_program(svn_command svn)
15
16#Function to count no of lines in a file equivalent to wc -l
17function (wcl _nLinesVar fileName)
18 file(READ ${fileName} fileData)
19 if(fileData)
20 if(WIN32)
21 string(REGEX MATCHALL "\r\n" nLines ${fileData})
22 else()
23 string(REGEX MATCHALL "[\r\n]" nLines ${fileData})
24 endif(WIN32)
25 list(LENGTH nLines nLines)
26 set(${_nLinesVar} ${nLines} PARENT_SCOPE)
27 else()
28 set(${_nLinesVar} -1 PARENT_SCOPE)
29 endif()
30endfunction()
31
32file(GLOB_RECURSE violExc "$ENV{ALICE_ROOT}/*THerwig6.viol"
33 "$ENV{ALICE_ROOT}/*AliRawReaderDateV3.viol"
34 "$ENV{ALICE_ROOT}/*dateStream.viol"
35 "$ENV{ALICE_ROOT}/TTherminator/*.viol"
36 "$ENV{ALICE_ROOT}/*esdAna.viol"
37 "$ENV{ALICE_ROOT}/*TIsajet*.viol"
38 "$ENV{ALICE_ROOT}/*RecAna.viol"
39 "$ENV{ALICE_ROOT}/*LHAPDFWrap.viol"
40 "$ENV{ALICE_ROOT}/RAW/check/event.viol"
41 "$ENV{ALICE_ROOT}/THerwig/check/HCommon.viol"
42 "$ENV{ALICE_ROOT}/*HBTprocCOMMON.viol"
43 "$ENV{ALICE_ROOT}/*EPOScommon.viol"
44 "$ENV{ALICE_ROOT}/*DPMcommon.viol"
45 "$ENV{ALICE_ROOT}/*Hcommon.viol"
46 "$ENV{ALICE_ROOT}/*TPHICcommon.viol"
47 "$ENV{ALICE_ROOT}/JETAN/check/fastjet/*.viol"
48 "$ENV{ALICE_ROOT}/HLT/check/JET/fastjet/*.viol"
49 "$ENV{ALICE_ROOT}/PYTHIA8/*.viol"
50 "$ENV{ALICE_ROOT}/TEvtGen/*.viol"
51 "$ENV{ALICE_ROOT}/LHAPDF/*.viol"
52 "$ENV{ALICE_ROOT}/*HydCommon.viol"
53 "$ENV{ALICE_ROOT}/*AliHLTDataBuffer.viol")
54file(GLOB_RECURSE violFiles "$ENV{ALICE_ROOT}/*.viol")
55list(REMOVE_ITEM violFiles ${violExc})
56
57#Total list of files
58list(LENGTH violFiles totf)
59#Total no of lines
60set(totl 0)
61#Count the number Violations per file and sort
62foreach( violFile ${violFiles} )
63 file(READ ${violFile} fileData)
64 math(EXPR violLen "0")
65 if(fileData)
66 string(REGEX MATCHALL "violated:" violList ${fileData})
67 list(LENGTH violList violLen)
68 endif(fileData)
69 math(EXPR totl "${totl} + ${violLen}")
70 math(EXPR violLen "999999 - ${violLen}")
71 list(APPEND violCount "${violLen}:${violFile}")
72endforeach( violFile )
73list(SORT violCount)
74list(LENGTH violCount max)
75if(max GREATER 10)
76 set(max 10)
77endif(max GREATER 10)
78message("==============================Overall Violations==============================\n")
79message("COUNT : VIOLATION FILE NAME\n------------------------------------------------------------------------------")
80#Print out top 10 violations
81foreach(i RANGE ${max})
82 list(GET violCount ${i} line)
83 string(LENGTH ${line} lineLen)
84 math(EXPR lineLen "${lineLen}-7")
85 string(SUBSTRING ${line} 0 6 count)
86 string(SUBSTRING ${line} 7 ${lineLen} lineLen)
87
88 string(REPLACE "check/" "" args ${lineLen})
89 string(REPLACE "viol" "*" args ${args})
90 file(GLOB args "${args}")
91 foreach(arg ${args})
92 list(APPEND argList "${arg}")
93 endforeach(arg)
94
95 string(REPLACE "$ENV{ALICE_ROOT}/" "" module ${lineLen})
96 math(EXPR count "999999 - ${count}")
97 string(LENGTH ${count} digit)
98 if(${digit} EQUAL 1)
99 set(space " ")
100 elseif(${digit} EQUAL 2)
101 set(space " ")
102 elseif(${digit} EQUAL 3)
103 set(space " ")
104 endif(${digit} EQUAL 1)
105 message("${space}${count} : ${module}")
106
107endforeach(i)
108
109set(tot 0)
110set (anlys "${anlys}\n\n==============================Detailed Analysis==============================\n")
111#Blaming people
112set (anlys "${anlys}+--| AliRoot\n")
113foreach( blameFile ${argList} )
114 string(REPLACE "$ENV{ALICE_ROOT}/" "" mainFile ${blameFile})
115 set(anlys "${anlys} |\n")
116 execute_process(COMMAND "${svn_command}" "blame" "${blameFile}"
117 WORKING_DIRECTORY "$ENV{ALICE_ROOT}"
118 OUTPUT_FILE tmpViols
119 OUTPUT_VARIABLE tmpVio)
120 wcl(fileLen "$ENV{ALICE_ROOT}/tmpViols")
121 set(anlys "${anlys} |--| ${mainFile} |-- ${fileLen} lines\n")
122 set(nameList "")
123 file(STRINGS "$ENV{ALICE_ROOT}/tmpViols" violData)
124 # file(READ "tmpViols" violData)
125 # string(REGEX REPLACE "\n" ";" "violData" "${violData}")
126 foreach(violLine ${violData})
127 string(REGEX MATCH "[0-9]+[ ]+[a-zA-Z0-9]+" "name" "${violLine}")
128 string(REGEX REPLACE "^[0-9]+[ ]+" "" "name" "${name}")
129 list(APPEND nameList ${name})
130 list(APPEND fullViolList ${name})
131 endforeach(violLine)
132 list(LENGTH violData tot)
133 set (userList ${nameList})
134 set(finale "")
135 if(userList)
136 list(REMOVE_DUPLICATES userList)
137 endif(userList)
138 foreach(name ${userList})
139 string(REGEX MATCHALL "${name}" "nameCount" "${nameList}")
140 list(LENGTH nameCount nameCount)
141 math(EXPR num "(${nameCount}*100)/${tot}")
142 math(EXPR dec "((10000*${nameCount}/${tot}-100*${num}+5))")
143 if( ${dec} GREATER 99 )
144 set(dec 0)
145 math(EXPR num "${num}+1")
146 endif(${dec} GREATER 99)
147 math(EXPR dec "${dec}/10")
148 math(EXPR pcnt "99999 - ${num}${dec}")
149 string(LENGTH ${num} digit)
150 if(digit EQUAL 1)
151 set(space " ")
152 elseif(digit EQUAL 2)
153 set(space " ")
154 endif(digit EQUAL 1)
155 list(APPEND finale "${pcnt}-${space}${num}.${dec}% | ${name} |-- ${nameCount} lines")
156 endforeach(name)
157 list(SORT finale)
158 foreach(record ${finale})
159 string(LENGTH ${record} recLen)
160 math(EXPR recLen "${recLen}-6")
161 string(SUBSTRING ${record} 6 ${recLen} record)
162 set(anlys "${anlys} +--|${record}\n")
163 endforeach(record)
164endforeach( blameFile)
165
166list(LENGTH fullViolList tot)
167set(nameList ${fullViolList})
168set(finale "")
169#Sorting Names
170if(nameList)
171 list(REMOVE_DUPLICATES nameList)
172endif(nameList)
173foreach(name ${nameList})
174 string(REGEX MATCHALL "${name}" "nameCount" "${fullViolList}")
175 list(LENGTH nameCount nameCount)
176 math(EXPR num "(${nameCount}*100)/${tot}")
177 math(EXPR dec "((10000*${nameCount}/${tot}-100*${num}+5))")
178 if( ${dec} GREATER 99 )
179 set(dec 0)
180 math(EXPR num "${num}+1")
181 endif(${dec} GREATER 99)
182 math(EXPR dec "${dec}/10")
183 math(EXPR pcnt "99999 - ${num}${dec}")
184 string(LENGTH ${num} digit)
185 if(digit EQUAL 1)
186 set(space " ")
187 elseif(digit EQUAL 2)
188 set(space " ")
189 endif(digit EQUAL 1)
190 list(APPEND finale "${pcnt}-${space}${num}.${dec}% | ${name}")
191endforeach(name)
192
193#Print Code Percentages
194list(SORT finale)
195message("\n\n==============================Overall Percentages==============================\n")
196foreach(record ${finale})
197 string(LENGTH ${record} recLen)
198 math(EXPR recLen "${recLen}-6")
199 string(SUBSTRING ${record} 6 ${recLen} record)
200 message("${record}")
201endforeach(record)
202
203#Print Detailed Analysis
204message("${anlys}")