]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGPP/QA/scripts/runQA.sh
some minor fixes
[u/mrichter/AliRoot.git] / PWGPP / QA / scripts / runQA.sh
CommitLineData
f7707400 1#!/bin/bash
2main()
3{
0c9bef99 4 if [[ -z $1 ]]; then
0adcf494 5 echo "Usage: "
6 echo " ${0##*/} option=value [option=value]"
161409c5 7 echo " at least inputList should be specified, or configFile containing it:"
8 echo " ${0##*/} inputList=file.list"
0adcf494 9 echo " options override config file (if any), e.g.:"
10 echo " ${0##*/} configFile=runQA.config inputList=file.list outputDirectory=%det"
2c46f154 11 return 1
93e1d132 12 fi
0c9bef99 13
c8973bf8 14 if ! parseConfig "$@"; then
0adcf494 15 ${0}
16 return 1
17 fi
0c9bef99 18
2c46f154 19 [[ -z $ALICE_ROOT ]] && echo "ALICE_ROOT not defined" && return 1
93e1d132 20
21 ocdbregex='raw://'
2c46f154 22 if [[ ${ocdbStorage} =~ ${ocdbregex} ]]; then
823d0979 23 alien-token-init ${alienUserName}
5ed6085c 24 #this is a hack! alien-token init seems not enough
25 #but the gclient_env script messes up the LD_LIBRARY_PATH
26 while read x; do
27 eval ${x};
28 done < <(grep -v "LD_LIBRARY_PATH" /tmp/gclient_env_${UID})
2c46f154 29 fi
0c9bef99 30
c8973bf8 31 updateQA "$@"
f7707400 32}
33
0c9bef99 34updateQA()
f7707400 35{
36 umask 0002
c8973bf8 37 parseConfig "$@"
0adcf494 38
39 #be paranoid and make some full paths
0adcf494 40 [[ ! -f ${inputList} ]] && echo "no input list: ${inputList}" && return 1
7f49f812 41 inputList=$(get_realpath ${inputList})
0adcf494 42 mkdir -p ${workingDirectory}
7f49f812 43 workingDirectory=$(workingDirectory=${workingDirectory%/}; cd ${workingDirectory%/*}; echo "${PWD}/${workingDirectory##*/}")
0adcf494 44 if [[ ! -d ${workingDirectory} ]]; then
45 echo "working dir $workingDirectory does not exist and cannot be created"
46 return 1
47 fi
48 cd ${workingDirectory}
49
50 echo JOB config:
51 echo inputList=$inputList
52 echo outputDirectory=$outputDirectory
53 echo
f7707400 54
142113c1 55 dateString=$(date +%Y-%m-%d-%H-%M-%S-%N)
93e1d132 56 echo "Start time QA process: $dateString"
57
9cc5d265 58 #logging
59 mkdir -p $logDirectory
2c46f154 60 [[ ! -d $logDirectory ]] && echo "no log dir $logDirectory" && return 1
93e1d132 61 logFile="$logDirectory/${0##*/}.${dateString}.log"
9cc5d265 62 touch ${logFile}
2c46f154 63 [[ ! -f ${logFile} ]] && echo "cannot write logfile $logfile" && return 1
93e1d132 64 echo "logFile = $logFile"
9cc5d265 65
66 #check lock
67 lockFile=${logDirectory}/runQA.lock
bf4e7ceb 68 [[ -f ${lockFile} ]] && echo "lock ${lockFile} exists!" | tee ${logFile} && return 1
9cc5d265 69 touch ${lockFile}
bf4e7ceb 70 [[ ! -f ${lockFile} ]] && echo "cannot lock $lockFile" | tee ${logFile} && return 1
9cc5d265 71
bf4e7ceb 72 exec &>${logFile}
73
0c9bef99 74 ################################################################
75 #ze detector loop
f7707400 76 for detectorScript in $ALICE_ROOT/PWGPP/QA/detectorQAscripts/*; do
3db1b975 77 echo
78 echo "##############################################"
244ec455 79 echo $(date)
bf4e7ceb 80 unset planB
81 [[ ! ${detectorScript} =~ .*\.sh$ ]] && continue
f7707400 82 detector=${detectorScript%.sh}
83 detector=${detector##*/}
2c46f154 84
85 #skip if excluded
c1386fec 86 if [[ "${excludeDetectors}" =~ ${detector} ]]; then
87 echo "${detector} is excluded in config, skipping..."
88 continue
89 fi
2c46f154 90
161409c5 91 #if includeDetectors set, only process thoe detectors specified there
92 if [[ -n ${includeDetectors} && ! "${includeDetectors}" =~ ${detector} ]]; then
93 echo "${detector} not included in includeDetectors, skipping..."
94 continue
95 fi
96
2c46f154 97 logSummary=${logDirectory}/summary-${detector}-${dateString}.log
f7707400 98 outputDir=$(substituteDetectorName ${detector} ${outputDirectory})
bf4e7ceb 99 tmpDetectorRunDir=${workingDirectory}/tmpQAtmpRunDir${detector}-${dateString}
8e7a87c1 100 if ! mkdir -p ${tmpDetectorRunDir}; then
101 echo "cannot create the temp dir $tmpDetectorRunDir"
9cc5d265 102 continue
103 fi
8e7a87c1 104 cd ${tmpDetectorRunDir}
9cc5d265 105
8e7a87c1 106 tmpPrefix=${tmpDetectorRunDir}/${outputDir}
93e1d132 107 echo "running QA for ${detector}"
108 echo " outputDir=$outputDir"
109 echo " tmpPrefix=$tmpPrefix"
f7707400 110
61fa85ce 111 #unset the detector functions from previous iterations (detectors)
f7707400 112 unset -f runLevelQA
113 unset -f periodLevelQA
645f513c 114 unset -f runLevelHighPtTreeQA
115 unset -f periodLevelHighPtTreeQA
f7707400 116 source ${detectorScript}
117
118 #################################################################
119 #produce the QA and trending tree for each file (run)
2a6472ef 120 unset arrOfTouchedProductions
121 declare -A arrOfTouchedProductions
f7707400 122 while read qaFile; do
2c46f154 123 echo
244ec455 124 echo $(date)
3db1b975 125
126 #first check if input file exists
127 [[ ! -f ${qaFile%\#*} ]] && echo "file ${qaFile%\#*} not accessible" && continue
2c46f154 128
0adcf494 129 if ! guessRunData ${qaFile}; then
130 echo "could not guess run data from ${qaFile}"
131 continue
132 fi
f7707400 133
2a6472ef 134 tmpProductionDir=${tmpPrefix}/${dataType}/${year}/${period}/${pass}
2a6472ef 135 tmpRunDir=${tmpProductionDir}/000${runNumber}
136 mkdir -p ${tmpRunDir}
137 cd ${tmpRunDir}
f7707400 138
645f513c 139 #by default we expect to have everything in the same archive
140 highPtTree=${qaFile}
141
142 #maybe the input is not an archive, but a file
3db1b975 143 [[ "${qaFile}" =~ QAresults.root$ ]] && highPtTree=""
144 [[ "${qaFile}" =~ FilterEvents_Trees.root$ ]] && qaFile=""
f7707400 145
645f513c 146 #it is possible we get the highPt trees from somewhere else
147 #search the list of high pt trees for the proper run number
148 if [[ -n ${inputListHighPtTrees} ]]; then
645f513c 149 highPtTree=$(egrep -m1 ${runNumber} ${inputListHighPtTrees})
f8619ac0 150 echo "loaded the highPtTree ${highPtTree} from external file ${inputListHighPtTrees}"
645f513c 151 fi
152
153 echo qaFile=$qaFile
154 echo highPtTree=$highPtTree
c8973bf8 155 echo ocdbStorage=${ocdbStorage}
156 echo
645f513c 157
158 #what if we have a zip archive?
159 if [[ "$qaFile" =~ .*.zip$ ]]; then
160 if unzip -l ${qaFile} | egrep "QAresults.root" &>/dev/null; then
161 qaFile="${qaFile}#QAresults.root"
162 else
163 qaFile=""
164 fi
165 fi
166 if [[ "$highPtTree" =~ .*.zip$ ]]; then
167 if unzip -l ${highPtTree} | egrep "FilterEvents_Trees.root" &>/dev/null; then
168 highPtTree="${highPtTree}#FilterEvents_Trees.root"
169 else
170 highPtTree=""
171 fi
de540baf 172 fi
645f513c 173
174 if [[ -n ${qaFile} && $(type -t runLevelQA) =~ "function" ]]; then
175 echo running ${detector} runLevelQA for run ${runNumber} from ${qaFile}
176 runLevelQA "${qaFile}" &> runLevelQA.log
177 #perform some default actions:
178 #if trending.root not created, create a default one
179 if [[ ! -f trending.root ]]; then
3db1b975 180 aliroot -b -q -l "$ALICE_ROOT/PWGPP/macros/simpleTrending.C(\"${qaFile}\",${runNumber},\"${detector}\",\"trending.root\",\"trending\",\"recreate\")" 2>&1 | tee -a runLevelQA.log
181 fi
182 if [[ -f trending.root ]]; then
183 arrOfTouchedProductions[${tmpProductionDir}]=1
184 else
185 echo "trending.root not created"
645f513c 186 fi
645f513c 187 fi
188 #expert QA based on high pt trees
189 if [[ -n ${highPtTree} && $(type -t runLevelHighPtTreeQA) =~ "function" ]]; then
190 echo running ${detector} runLevelHighPtTreeQA for run ${runNumber} from ${highPtTree}
191 runLevelHighPtTreeQA "${highPtTree}" &> runLevelHighPtTreeQA.log
192 arrOfTouchedProductions[${tmpProductionDir}]=1
193 fi
194
8e7a87c1 195 cd ${tmpDetectorRunDir}
f7707400 196
197 done < ${inputList}
198
199 #################################################################
200 #cache which productions were (re)done
93e1d132 201 echo "list of processed productions:"
2a6472ef 202 echo " ${!arrOfTouchedProductions[@]}"
93e1d132 203 echo
2a6472ef 204
f7707400 205 #################################################################
bf4e7ceb 206 #(re)do the merging/trending
2a6472ef 207 for tmpProductionDir in ${!arrOfTouchedProductions[@]}; do
bf4e7ceb 208 cd ${tmpProductionDir}
2c46f154 209 echo
210 echo "running period level stuff in ${tmpProductionDir}"
244ec455 211 echo $(date)
f7707400 212
f7707400 213 productionDir=${outputDir}/${tmpProductionDir#${tmpPrefix}}
bf4e7ceb 214 echo productionDir=${outputDir}/${tmpProductionDir#${tmpPrefix}}
2c46f154 215
f7707400 216 mkdir -p ${productionDir}
9cc5d265 217 if [[ ! -d ${productionDir} ]]; then
93e1d132 218 echo "cannot make productionDir $productionDir" && continue
9cc5d265 219 fi
f7707400 220
bf4e7ceb 221 #move runs to final destination
222 for dir in ${tmpProductionDir}/000*; do
223 echo
93e1d132 224 oldRunDir=${outputDir}/${dir#${tmpPrefix}}
0adcf494 225 if ! guessRunData "${dir}/dummyName"; then
226 echo "could not guess run data from ${dir}"
227 continue
228 fi
2c46f154 229
230 #before moving - VALIDATE!!!
bf4e7ceb 231 if ! validate ${dir}; then
232 continue
233 fi
2c46f154 234
1aa30209 235 #moving a dir is an atomic operation, no locking necessary
93e1d132 236 if [[ -d ${oldRunDir} ]]; then
50864a2d 237 echo "removing old ${oldRunDir}"
93e1d132 238 rm -rf ${oldRunDir}
239 fi
2c46f154 240 echo "moving new ${runNumber} to ${productionDir}"
93e1d132 241 mv -f ${dir} ${productionDir}
242 done
033dacdc 243
3db1b975 244 #go to a temp dir to do the period level stuff in a completely clean dir
bf4e7ceb 245 tmpPeriodLevelQAdir="${tmpProductionDir}/periodLevelQA"
246 echo
247 echo tmpPeriodLevelQAdir="${tmpProductionDir}/periodLevelQA"
248 if ! mkdir -p ${tmpPeriodLevelQAdir}; then continue; fi
249 cd ${tmpPeriodLevelQAdir}
250
251 #link the final list of per-run dirs here, just the dirs
252 #to have a clean working directory
253 unset linkedStuff
254 declare -a linkedStuff
255 for x in ${productionDir}/000*; do [[ -d $x ]] && ln -s $x && linkedStuff+=(${x##*/}); done
bf4e7ceb 256
8e7a87c1 257 #merge trending files if any
258 if /bin/ls 000*/trending.root &>/dev/null; then
259 hadd trending.root 000*/trending.root &> periodLevelQA.log
645f513c 260 fi
261
bf4e7ceb 262 #run the period level trending/QA
645f513c 263 if [[ -f "trending.root" && $(type -t periodLevelQA) =~ "function" ]]; then
264 echo running ${detector} periodLevelQA for production ${period}/${pass}
8e7a87c1 265 periodLevelQA trending.root &>> periodLevelQA.log
645f513c 266 else
267 echo "WARNING: not running ${detector} periodLevelQA for production ${period}/${pass}, no trending.root"
8e7a87c1 268 fi
269
2c46f154 270 if ! validate ${PWD}; then continue; fi
2c46f154 271
bf4e7ceb 272 #here we are validated so move the produced QA to the final place
273 #clean up linked stuff first
274 [[ -n ${linkedStuff[@]} ]] && rm ${linkedStuff[@]}
1aa30209 275 periodLevelLock=${productionDir}/runQA.lock
276 if [[ ! -f ${periodLevelLock} ]]; then
277 #some of the output could be a directory, so handle that
278 #TODO: maybe use rsync?
279 #lock to avoid conflicts:
280 echo "${HOSTNAME} ${dateString}" > ${periodLevelLock}
281 for x in ${tmpPeriodLevelQAdir}/*; do
282 if [[ -d ${x} ]]; then
283 echo "removing ${productionDir}/${x##*/}"
284 rm -rf ${productionDir}/${x##*/}
285 echo "moving ${x} to ${productionDir}"
286 mv ${x} ${productionDir}
287 fi
288 if [[ -f ${x} ]]; then
289 echo "moving ${x} to ${productionDir}"
290 mv -f ${x} ${productionDir}
291 fi
292 done
293 rm -f ${periodLevelLock}
294 #remove the temp dir
295 rm -rf ${tmpPeriodLevelQAdir}
296 else
56af0297 297 echo "ERROR: cannot move to destination" >> ${logSummary}
298 echo "production dir ${productionDir} locked!" >> ${logSummary}
299 echo "check and maybe manually do:" >> ${logSummary}
300 echo " rm ${periodLevelLock}" >> ${logSummary}
301 echo " rsync -av ${tmpPeriodLevelQAdir}/ ${productionDir}/" >> ${logSummary}
c38409ba 302 planB=1
1aa30209 303 fi
bf4e7ceb 304
f7707400 305 done
306
9cc5d265 307 cd ${workingDirectory}
2c46f154 308
309 if [[ -z ${planB} ]]; then
9a5f8a19 310 echo
8e7a87c1 311 echo removing ${tmpDetectorRunDir}
312 rm -rf ${tmpDetectorRunDir}
2c46f154 313 else
314 executePlanB
315 fi
3db1b975 316 done #end of detector loop
f7707400 317
9cc5d265 318 #remove lock
319 rm -f ${lockFile}
f7707400 320}
321
2c46f154 322executePlanB()
323{
324 #in case of emergency
325 if [[ -n ${MAILTO} ]]; then
326 echo
327 echo "trouble detected, sending email to ${MAILTO}"
328
5c7749f0 329 grep BAD ${logSummary} | mail -s "qa in need of assistance" ${MAILTO}
2c46f154 330 fi
331}
332
333validate()
334{
335 summarizeLogs ${1} >> ${logSummary}
336 logStatus=$?
337 if [[ ${logStatus} -ne 0 ]]; then
338 echo "WARNING not validated: ${1}"
339 planB=1
340 return 1
341 fi
342 return 0
343}
344
345summarizeLogs()
346{
347 local dir=$1
2a6472ef 348 [[ ! -d ${dir} ]] && dir=${PWD}
2c46f154 349
350 #print a summary of logs
351 logFiles=(
352 "*.log"
353 "stdout"
354 "stderr"
355 )
356
357 #check logs
358 local logstatus=0
359 for log in ${dir}/${logFiles[*]}; do
360 finallog=${PWD%/}/${log}
361 [[ ! -f ${log} ]] && continue
362 errorSummary=$(validateLog ${log})
363 validationStatus=$?
364 [[ validationStatus -ne 0 ]] && logstatus=1
365 if [[ ${validationStatus} -eq 0 ]]; then
366 #in pretend mode randomly report an error in rec.log some cases
367 if [[ -n ${pretend} && "${log}" == "rec.log" ]]; then
368 [[ $(( ${RANDOM}%2 )) -ge 1 ]] && echo "${finallog} BAD random error" || echo "${finallog} OK"
369 else
370 echo "${finallog} OK"
371 fi
372 elif [[ ${validationStatus} -eq 1 ]]; then
373 echo "${finallog} BAD ${errorSummary}"
374 elif [[ ${validationStatus} -eq 2 ]]; then
375 echo "${finallog} OK MWAH ${errorSummary}"
376 fi
377 done
378
379 #report core files
380 while read x; do
381 echo ${x}
382 chmod 644 ${x}
383 gdb --batch --quiet -ex "bt" -ex "quit" aliroot ${x} > stacktrace_${x//\//_}.log
384 done < <(/bin/ls ${PWD}/*/core 2>/dev/null; /bin/ls ${PWD}/core 2>/dev/null)
385
386 return ${logstatus}
387}
388
389validateLog()
390{
391 log=${1}
392 errorConditions=(
393 'There was a crash'
394 'floating'
395 'error while loading shared libraries'
396 'std::bad_alloc'
397 's_err_syswatch_'
398 'Thread [0-9]* (Thread'
399 'AliFatal'
400 'core dumped'
401 '\.C.*error:.*\.h: No such file'
402 'segmentation'
645f513c 403 'Interpreter error recovered'
2c46f154 404 )
405
406 warningConditions=(
407 'This is serious'
408 )
409
410 local logstatus=0
411 local errorSummary=""
412 local warningSummary=""
413
414 for ((i=0; i<${#errorConditions[@]};i++)); do
415 local tmp=$(grep -m1 -e "${errorConditions[${i}]}" ${log})
416 [[ -n ${tmp} ]] && tmp+=" : "
417 errorSummary+=${tmp}
418 done
419
420 for ((i=0; i<${#warningConditions[@]};i++)); do
421 local tmp=$(grep -m1 -e "${warningConditions[${i}]}" ${log})
422 [[ -n ${tmp} ]] && tmp+=" : "
423 warningSummary+=${tmp}
424 done
425
426 if [[ -n ${errorSummary} ]]; then
427 echo "${errorSummary}"
428 return 1
429 fi
430
431 if [[ -n ${warningSummary} ]]; then
432 echo "${warningSummary}"
433 return 2
434 fi
435
436 return 0
437}
438
f7707400 439parseConfig()
440{
d56eeaab 441 args=("$@")
442
0adcf494 443 #config file
444 configFile=""
445 #where to search for qa files
446 inputList=file.list
447 #working directory
448 workingDirectory="${PWD}"
449 #where to place the final qa plots
450 #outputDirectory="/afs/cern.ch/work/a/aliqa%det/www/"
451 outputDirectory="${workingDirectory}/%DET"
452 #filter out detector option
453 excludeDetectors="EXAMPLE"
454 #logs
455 logDirectory=${workingDirectory}/logs
0adcf494 456 #OCDB storage
b001e589 457 ocdbStorage="raw://"
0adcf494 458 #email to
459 #MAILTO="fbellini@cern.ch"
460
461 #first, check if the config file is configured
462 #is yes - source it so that other options can override it
463 #if any
d56eeaab 464 for opt in "${args[@]}"; do
0adcf494 465 if [[ ${opt} =~ configFile=.* ]]; then
466 eval "${opt}"
7f49f812 467 [[ ! -f ${configFile} ]] && echo "configFile ${configFile} not found, exiting..." && return 1
d56eeaab 468 echo "using config file: ${configFile}"
0adcf494 469 source "${configFile}"
470 break
471 fi
472 done
f7707400 473
474 #then, parse the options as they override the options from file
d56eeaab 475 for opt in "${args[@]}"; do
476 if [[ ! "${opt}" =~ .*=.* ]]; then
0adcf494 477 echo "badly formatted option ${var}, should be: option=value, stopping..."
478 return 1
479 fi
d56eeaab 480 local var="${opt%%=*}"
481 local value="${opt#*=}"
c8973bf8 482 echo "${var}=${value}"
d56eeaab 483 export ${var}="${value}"
f7707400 484 done
485}
486
487guessRunData()
488{
489 #guess the period from the path, pick the rightmost one
490 period=""
491 runNumber=""
492 year=""
493 pass=""
494 legoTrainRunNumber=""
495 dataType=""
496
497 local shortRunNumber=""
c8973bf8 498 oldIFS=${IFS}
f7707400 499 local IFS="/"
500 declare -a path=( $1 )
c8973bf8 501 IFS="${oldIFS}"
f7707400 502 local dirDepth=$(( ${#path[*]}-1 ))
503 i=0
504 for ((x=${dirDepth};x>=0;x--)); do
505
506 [[ $((x-1)) -ge 0 ]] && local fieldPrev=${path[$((x-1))]}
507 local field=${path[${x}]}
508 local fieldNext=${path[$((x+1))]}
509
510 [[ ${field} =~ ^[0-9]*$ && ${fieldNext} =~ (.*\.zip$|.*\.root$) ]] && legoTrainRunNumber=${field}
511 [[ -n ${legoTrainRunNumber} && -z ${pass} ]] && pass=${fieldPrev}
512 [[ ${field} =~ ^LHC[0-9][0-9][a-z].*$ ]] && period=${field%_*}
513 [[ ${field} =~ ^000[0-9][0-9][0-9][0-9][0-9][0-9]$ ]] && runNumber=${field#000}
514 [[ ${field} =~ ^[0-9][0-9][0-9][0-9][0-9][0-9]$ ]] && shortRunNumber=${field}
515 [[ ${field} =~ ^20[0-9][0-9]$ ]] && year=${field}
516 [[ ${field} =~ ^(^sim$|^data$) ]] && dataType=${field}
517 (( i++ ))
518 done
519 [[ -z ${legoTrainRunNumber} ]] && pass=${path[$((dirDepth-1))]}
520 [[ "${dataType}" =~ ^sim$ ]] && pass="passMC" && runNumber=${shortRunNumber}
84ed81b2 521 [[ -n ${legoTrainRunNumber} ]] && pass+="_lego${legoTrainRunNumber}"
0c9bef99 522
c8973bf8 523 #modify the OCDB: set the year
524 ocdbStorage=$(setYear ${year} ${ocdbStorage})
525
2a6472ef 526 #if [[ -z ${dataType} || -z ${year} || -z ${period} || -z ${runNumber}} || -z ${pass} ]];
c8973bf8 527 if [[ -z ${runNumber}} ]]
0c9bef99 528 then
529 #error condition
530 return 1
531 else
532 #ALL OK
533 return 0
534 fi
f7707400 535}
536
537substituteDetectorName()
538{
539 local det=$1
540 local dir=$2
541 [[ ${dir} =~ \%det ]] && det=${det,,} && echo ${dir/\%det/${det}}
542 [[ ${dir} =~ \%DET ]] && det=${det} && echo ${dir/\%DET/${det}}
543}
544
7f49f812 545get_realpath()
546{
547 if [[ -f "$1" ]]
548 then
549 # file *must* exist
550 if cd "$(echo "${1%/*}")" &>/dev/null
551 then
552 # file *may* not be local
553 # exception is ./file.ext
554 # try 'cd .; cd -;' *works!*
555 local tmppwd="$PWD"
556 cd - &>/dev/null
557 else
558 # file *must* be local
559 local tmppwd="$PWD"
560 fi
561 else
562 # file *cannot* exist
563 return 1 # failure
564 fi
565 # reassemble realpath
566 echo "$tmppwd"/"${1##*/}"
567 return 0 # success
568}
569
c8973bf8 570setYear()
571{
572 #set the year
573 # ${1} - year to be set
574 # ${2} - where to set the year
575 local year1=$(guessYear ${1})
576 local year2=$(guessYear ${2})
577 local path=${2}
578 [[ ${year1} -ne ${year2} && -n ${year2} && -n ${year1} ]] && path=${2/\/${year2}\//\/${year1}\/}
579 echo ${path}
580 return 0
581}
582
583guessYear()
584{
585 #guess the year from the path, pick the rightmost one
586 local IFS="/"
587 declare -a pathArray=( ${1} )
588 local field
589 local year
590 for field in ${pathArray[@]}; do
591 [[ ${field} =~ ^20[0-9][0-9]$ ]] && year=${field}
592 done
593 echo ${year}
594 return 0
595}
596
597main "$@"