Changeset 9585 for trunk


Ignore:
Timestamp:
06/11/10 17:36:11 (15 years ago)
Author:
Daniela Dorner
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/Changelog

    r9584 r9585  
    1818
    1919                                                 -*-*- END OF LINE -*-*-
     20
     21 2010/06/11 Daniela Dorner
     22
     23   * datacenter/scripts/sourcefile:
     24     - changed functions and queries to new db layout
     25     - added functions to get values from steps.rc
     26     - new function for part of query which is identical for the
     27       functions getstatus() and gettodo()
     28     - removed $reset (was only needed for MerppUpdate)
     29     - improved and added comments
     30
     31   * datacenter/scripts/jobmanager:
     32     - implemented changes for new db layout
     33     - fix in function nextscript(): wrong variable was used
     34
     35   * datacenter/scripts/runcorsika:
     36     - implemented changes for new db layout
     37     - merged uncommitted changes of Thomas Bretz
     38     - Observatory values and atmosphere now read from DB
     39     - implemented new seeds
     40     - removed $reused
     41     - wavelength range now read from DB
     42
     43   * datacenter/scripts/setup.wue.fact.mc:
     44     - added (setup for fact mc production)
     45
     46
    2047
    2148 2010/06/11 Stefan Ruegamer
  • trunk/MagicSoft/Mars/datacenter/scripts/jobmanager

    r9539 r9585  
    3737function nextscript()
    3838{
    39    echo `date +%F\ %T`" sleeping \$$1 = $sleeptime seconds... " >> $jmscriptlog 2>&1
     39   echo `date +%F\ %T`" sleeping \$$1 = $2 seconds... " >> $jmscriptlog 2>&1
    4040   sleep $2
    4141   echo "" >> $jmscriptlog 2>&1
     
    8888
    8989      # check if there's something to do
    90       column=${scriptscolname[$i]}
     90      step=${scriptscolname[$i]}
    9191      getstepinfo
    9292      if [ "$noderestricted" = "yes" ]
     
    126126     
    127127      # check number of processes to be done
    128       echo `date +%F\ %T`" Database: $numproc ${scripts[$i]} still to be done (incl. idle jobs) [DB/table/column $db/$table/$column]" >> $jmscriptlog 2>&1
     128      echo `date +%F\ %T`" Database: $numproc ${scripts[$i]} still to be done (incl. idle jobs) [DB/step $db/$step]" >> $jmscriptlog 2>&1
    129129      if [ "$numproc" = "0" ]
    130130      then
  • trunk/MagicSoft/Mars/datacenter/scripts/runcorsika

    r9355 r9585  
    1818#
    1919#
    20 #   Author(s): Daniela Dorner  05/2007 <mailto:dorner@astro.uni-wuerzburg.de>
    21 #
    22 #   Copyright: MAGIC Software Development, 2000-2008
     20#   Author(s): Daniela Dorner  05/2007 <mailto:daniela.dorner@unige.ch>
     21#
     22#   Copyright: MAGIC Software Development, 2000-2010
    2323#
    2424#
     
    3131printprocesslog "INFO starting $0"
    3232program=corsika
    33 column=fCorsikaFileAvail
     33step=Corsika
    3434
    3535set -C
     
    4141{
    4242   # Run number
    43    echo "RUNNR "$corsikarunno
     43   echo "RUNNR "$file
    4444   # Starting event number
    4545   echo "EVTNR 1"
     
    6060   echo "FIXCHI "$startalt
    6161   # Observation level, magnetic field, atmosphere
    62    echo "OBSLEV 2200.E2"
     62   echo "OBSLEV "$obslev".E2"
    6363   # From www.noaa.gov/geomagmodels roughly for January 2009. (was 29.5 and 23.0)
    6464   # MAGNET BX BZ (BX is the horizontal component (muT) to the x-direction of
    6565   # the detector, BZ is the vertical component (muT) downwards)
    66    echo "MAGNET 30.3 24.1"
     66   echo "MAGNET "$magnet
    6767   # Rotation angle between array x-direction and magnetic north direction
    6868   # positive if array x-direction points to the west
    69    echo "ARRANG -7.0"
     69   echo "ARRANG "$magnetrot
    7070   # Atmosphere (model, true/false for atmospheric refraction of cer-photons)
    7171   # Atmosphere read from atmprof11.dat
    7272   # My current understanding is that only refraction (bending of light
    7373   # but no absorption of photons is taken into account) setting T.
    74    echo "ATMOSPHERE 11 T"
     74   echo "ATMOSPHERE "$atm" T"
     75
     76   # Current boundaries in reflector program
     77   # echo "ATMLAY 400000 1000000 4000000 10000000"
     78
     79   # Boundaries as determined by CORSIKA
     80   # Until we can read the result from the corsika fit we fix the
     81   # values which come out of the fit. This is not ideal but forces
     82   # things to be consistent. Be careful is using a different model -
     83   # the fit might not be ideal.
     84   echo "ATMLAY 775000 1650000 5000000 10500000"
     85
    7586   # Other parameters
    7687   echo "RADNKG 200.E2"
     
    8293   # Enable muon multiple scattering
    8394   echo "MUMULT T"
    84    # Cherenkov telescope options
    85    echo "CWAVLG 290. 600."
    86    echo "CSCAT "$reuse" 0. "$impactmax
     95   # Wavelength range (was originally 600)
     96   echo "CWAVLG "$wavelengths
     97   # MMCS
     98   echo "CSCAT 1 0. "$impactmax
     99   # CORSIKA
     100   # echo "CSCAT "$reuse" "$impactmax" 0."
    87101   echo "CERSIZ 1."
     102   # Write Cherenkov photons to cer-file
    88103   echo "CERFIL T"
     104   # Number of telescopes
    89105   echo "CERTEL 1"
    90    echo " 0. 0. 0. 0. 0. "$diameter" 1700."
     106   # MMCS
     107   echo " 0. 0. 0. 0. 0. "$diameter" "$diameter
     108   # CORSIKA (x, y, z, r)
     109   # echo "TELESCOPE 0. 0. 0. "$diameter
     110   # This keyword has no relevance but allows to store the
     111   # maximum simulated impact parameter. The "magic" is that
     112   # ceres interpretes the third and fourth argument as
     113   # maximum simulated impact if they are identical and
     114   # the other four arguments are 1
     115   # echo "CERARY 1 1 "$diameter" "$diameter" 1 1"
    91116   # How the longitudinal shower development is sampled
    92117   # echo "LONGI T 10. T F"
     
    103128   # Output path
    104129   echo "DIRECT "$outpath
    105    # User and host (for convinience)
     130   # DIRECT /dev/null
     131   # TELFIL filename
     132   # TELFIL | gzip
     133   # TELESCOPE X Y Z R
     134   # User and host (for convenience)
    106135   echo "USER "`whoami`
    107136   echo "HOST "`hostname`
     
    114143gettodo "1"
    115144run=${primaries[0]}
    116 # get corsika runno
    117 query="SELECT fCorsikaRunNumber FROM MCRunData where fMCRunNumber="$run
    118 # to be changed later again, when additional tables are available
    119 #corsikarunno=`sendquery`
    120 corsikarunno=$run
     145file=${primaries[1]}
    121146
    122147# lock sequ
    123 lockfile=$lockpath/lock-$table-$column-$corsikarunno.txt
     148lockfile=$lockpath/lock-$step-$run.$file.txt
    124149checklock
    125150
    126 printprocesslog "INFO starting $program for run $run"
     151printprocesslog "INFO starting $program for run $run and file $file"
    127152
    128153setstatus "start"
    129154
    130 printprocesslog "INFO run $program for run $run "
    131 printprocesslog "INFO create input card... "
     155printprocesslog "INFO run $program for run $run  and file $file"
     156printprocesslog "INFO create input card for run $run  and file $file"
    132157
    133158# get values for inputcard
    134 query="SELECT fParticleTypeKEY FROM MCCorsikaRunData where fCorsikaRunNumber="$corsikarunno
     159query="SELECT fParticleTypeKEY FROM CorsikaInfo WHERE fRunNumber=$run AND fFileNumber=$file"
    135160primparticle=`sendquery`
    136 query="SELECT fEnergyMin, fEnergyMax FROM MCCorsikaRunData where fCorsikaRunNumber="$corsikarunno
     161query="SELECT fEnergyMin, fEnergyMax FROM CorsikaInfo WHERE fRunNumber=$run AND fFileNumber=$file"
    137162erange=`sendquery`
    138 query="SELECT fNumEvents FROM MCCorsikaRunData where fCorsikaRunNumber="$corsikarunno
     163query="SELECT fNumEvents FROM CorsikaInfo WHERE fRunNumber=$run AND fFileNumber=$file"
    139164numevts=`sendquery`
    140 query="SELECT fEnergySlope FROM MCCorsikaRunData where fCorsikaRunNumber="$corsikarunno
     165query="SELECT fEnergySlope FROM CorsikaInfo WHERE fRunNumber=$run AND fFileNumber=$file"
    141166slope=`sendquery`
    142 query="SELECT fZenithDistanceMin, fZenithDistanceMax FROM MCCorsikaRunData where fCorsikaRunNumber="$corsikarunno
     167query="SELECT fZenithDistanceMin, fZenithDistanceMax FROM CorsikaInfo WHERE fRunNumber=$run AND fFileNumber=$file"
    143168zdrange=`sendquery`
    144169# Change from the MARS definition (Az=90 -> East) to Corsika (Az=90 -> West)
    145 query="SELECT 180-fAzimuthMin, 180-fAzimuthMax FROM MCCorsikaRunData where fCorsikaRunNumber="$corsikarunno
     170query="SELECT 180-fAzimuthMin, 180-fAzimuthMax FROM CorsikaInfo WHERE fRunNumber=$run AND fFileNumber=$file"
    146171azrange=`sendquery`
    147 query="SELECT DATE_FORMAT(fRunStart, '%Y/%m/%d') FROM MCCorsikaRunData where fCorsikaRunNumber="$corsikarunno
    148 date=`sendquery`
    149 outpath=$mcpath"/"$program"/"$date
    150 query="SELECT fCorsikaSeed FROM MCCorsikaRunData where fCorsikaRunNumber="$corsikarunno
     172query="SELECT fCorsikaSeed1 FROM CorsikaInfo WHERE fRunNumber=$run AND fFileNumber=$file"
    151173seed1=`sendquery`
    152 query="SELECT fCorsikaSeed+1 FROM MCCorsikaRunData where fCorsikaRunNumber="$corsikarunno
     174query="SELECT fCorsikaSeed2 FROM CorsikaInfo WHERE fRunNumber=$run AND fFileNumber=$file"
    153175seed2=`sendquery`
    154 query="SELECT fCorsikaSeed+2 FROM MCCorsikaRunData where fCorsikaRunNumber="$corsikarunno
     176query="SELECT fCorsikaSeed3 FROM CorsikaInfo WHERE fRunNumber=$run AND fFileNumber=$file"
    155177seed3=`sendquery`
    156 query="SELECT fImpactMax FROM MCCorsikaRunData where fCorsikaRunNumber="$corsikarunno
     178query="SELECT fImpactMax FROM CorsikaInfo WHERE fRunNumber=$run AND fFileNumber=$file"
    157179impactmax=`sendquery`
    158 query="SELECT fViewConeMax FROM MCCorsikaRunData where fCorsikaRunNumber="$corsikarunno
     180query="SELECT fViewConeMax FROM CorsikaInfo WHERE fRunNumber=$run AND fFileNumber=$file"
    159181viewconemax=`sendquery`
    160 query="SELECT fNumReUseShower FROM MCCorsikaRunData where fCorsikaRunNumber="$corsikarunno
    161 reuse=`sendquery`
    162 query="SELECT fStartingAltitude FROM MCCorsikaRunData where fCorsikaRunNumber="$corsikarunno
     182query="SELECT fStartingAltitude FROM CorsikaInfo WHERE fRunNumber=$run AND fFileNumber=$file"
    163183startalt=`sendquery`
    164 query="SELECT fMirrorDiameter FROM MCCorsikaRunData where fCorsikaRunNumber="$corsikarunno
     184query="SELECT fMirrorDiameter FROM CorsikaInfo WHERE fRunNumber=$run AND fFileNumber=$file"
    165185diameter=`sendquery`
    166 
    167 logfile=$outpath/$program"-"`printf %06d $corsikarunno`".log"
     186query="SELECT fAtmosphericModelKEY FROM CorsikaInfo WHERE fRunNumber=$run AND fFileNumber=$file"
     187atm=`sendquery`
     188query="SELECT fObsLevel FROM CorsikaInfo LEFT JOIN Observatory USING(fObservatoryKEY) WHERE fRunNumber=$run AND fFileNumber=$file"
     189obslev=`sendquery`
     190query="SELECT fMagnetBX, fMagnetBZ FROM CorsikaInfo LEFT JOIN Observatory USING(fObservatoryKEY) WHERE fRunNumber=$run AND fFileNumber=$file"
     191magnet=`sendquery`
     192query="SELECT fMagnetRotation FROM CorsikaInfo LEFT JOIN Observatory USING(fObservatoryKEY) WHERE fRunNumber=$run AND fFileNumber=$file"
     193magnetrot=`sendquery`
     194query="SELECT fWavelengthMin, fWavelengthMax FROM CorsikaInfo WHERE fRunNumber=$run AND fFileNumber=$file"
     195wavelengths=`sendquery`
     196
     197outpath=$mcpath"/"$program"/"`printf %08d $run | cut -c 0-4`/`printf %08d $run | cut -c 5-8`
    168198makedir $outpath
     199logfile=$outpath/cer000`printf %06d $file | cut -c 4-6`".log"
    169200
    170201cd $corsikapath
    171202
    172 echo "INPUTCARD:" >| $logfile 2>&1
    173 printinputcard >> $logfile 2>&1
    174 echo "" >> $logfile 2>&1
    175 echo "" >> $logfile 2>&1
    176 printinputcard | ./cc6501p-linux >> $logfile 2>&1
    177 
    178 rm -f $outpath/dat`printf %06d $corsikarunno`
     203printinputcard | ./cc6501p-linux >| $logfile 2>&1
    179204
    180205check1=$?
    181 
    182206case $check1 in
    183    0)   printprocesslog "INFO $program finished successfully for corsika run number $corsikarunno (check1=$check1)"
     207   0)   printprocesslog "INFO $program finished successfully for run $run file $file (check1=$check1)"
    184208        ;;
    185    *)   printprocesslog "ERROR $program failed for corsika run number $corsikarunno (check1=$check1)"
     209   *)   printprocesslog "ERROR $program failed for run $run file $file (check1=$check1)"
    186210        com=$Fcorsika
    187211        check=$check1
     
    189213esac
    190214
     215# removing empty datnnnnnn file
     216rm -f $outpath/dat`printf %06d $file`
     217
    191218setstatus "stop"
    192219
  • trunk/MagicSoft/Mars/datacenter/scripts/sourcefile

    r9543 r9585  
    2020#   Author(s): Daniela Dorner  05/2005 <mailto:dorner@astro.uni-wuerzburg.de>
    2121#
    22 #   Copyright: MAGIC Software Development, 2000-2007
     22#   Copyright: MAGIC Software Development, 2000-2010
    2323#
    2424#
     
    209209}
    210210
    211 function resetstatusvalues()
    212 {
    213    statustime=NULL
    214    starttime=NULL
    215    returncode=NULL
    216    programid=NULL
    217    failedtime=NULL
    218 }
    219 
     211# print the current status values
    220212function printstatusvalues()
    221213{
    222214   echo "the current values are:"
    223    echo " statustime=$statustime"
    224215   echo " starttime=$starttime"
     216   echo " stoptime=$stoptime"
    225217   echo " returncode=$returncode"
    226    echo " programid=$programid"
    227    echo " failedtime=$failedtime"
    228218   echo "-- check: -$check-"
    229219   echo ""
    230220}
    231221
    232 # function evaluating the statusvalues
    233 function evalstatus()
    234 {
    235    case $@ in
    236       start)   printprocesslog "INFO setstatus start"
    237                starttime="Now()"
    238                ;;
    239        stop)   case $check in
    240                   ok)  printprocesslog "INFO setstatus stop - ok"
    241                        statustime="Now()"
    242                        ;;
    243                   no)  printprocesslog "INFO setstatus stop - nothing new"
    244                        check="ok"
    245                        ;;
    246                    *)  printprocesslog "INFO setstatus stop - failed"
    247                        starttime=noreset
    248                        if [ "$check" == "" ]
    249                        then
    250                           returncode=1
    251                        else
    252                           returncode=$check
    253                        fi
    254                        programid=$com
    255                        failedtime="Now()"
    256                        check="ok"
    257                        ;;
    258                esac
    259                ;;
    260           *)   printprocesslog "ERROR function evalstatus got wrong variable"
    261                finish
    262                ;;
    263    esac
    264 }
    265 
     222# get the db-setup from the sql.rc
    266223function getdbsetup()
    267224{
     
    277234}
    278235
     236# function to get the needed information from the dependencies-file steps.rc
    279237function getstepinfo()
    280238{
    281239   getdbsetup
    282    table=`grep "$column:" $steps | sed -e "s/[.]$column://" -e 's/#//' -e 's/ //g'`
    283    coltab=`grep "$column:" $steps | sed -e 's/://' -e 's/#//' -e 's/ //g'`
    284    needs=`grep "$coltab[.]Needs:" $steps | sed -e "s/$coltab[.]Needs://"`
    285    noderestricted=`grep "$coltab[.]NodeRestricted:" $steps | sed -e "s/$coltab[.]NodeRestricted://" -e 's/ //g'`
    286    influences=`grep "$coltab[.]Influences:" $steps | sed -e "s/$coltab[.]Influences://"`
    287    prims=( `grep "$table[.]Primary:" $steps | sed -e "s/$table[.]Primary://"` )
    288 #   echo " column $column - table $table - coltab $coltab"
     240   needs=`grep "$step[.]Needs:" $steps | sed -e "s/$step[.]Needs://"`
     241   noderestricted=`grep "$step[.]NodeRestricted:" $steps | sed -e "s/$step[.]NodeRestricted://" -e 's/ //g'`
     242   prims=( `grep "$step[.]Primaries:" $steps | sed -e "s/$step[.]Primaries://"` )
    289243#   echo " needs: $needs"
    290 #   echo " influences: $influences"
    291244#   echo " noderestricted: $noderestricted"
    292245#   echo " prims: ${prims[@]}"
    293246}
    294247
     248# function to get the primaries of a step from the dependencies-file steps.rc
     249function getprimary()
     250{
     251   getdbsetup
     252   grep $@"[.]Primaries:" $steps | sed -e "s/$@[.]Primaries://"
     253}
     254
     255# function to get the join of a step from the dependencies-file steps.rc
     256function getjoin()
     257{
     258   getdbsetup
     259   grep $@"[.]Join:" $steps | sed -e "s/$@[.]Join://"
     260}
     261
     262# function to create the middle part of a query
     263#  which is identical for the functions getstatus() and gettodo()
     264function middlepartofquery()
     265{
     266   # add from which table the information is queried
     267   query=$query" FROM "$step"Status "
     268   # add the joins to the tables in which the status of the preceding steps is stored
     269   for need in $needs
     270   do
     271      needprims=( `getprimary $need` )
     272      if [ "`echo ${needprims[@]}`" == "`echo ${prims[@]}`" ]
     273      then
     274         query=$query" LEFT JOIN "$need"Status USING (${prims[@]}) "
     275      fi
     276   done
     277   # add condition
     278   query=$query" WHERE "
     279   # add condition for the status of the peceding steps
     280   counter=0
     281   for need in $needs
     282   do
     283      if [ $counter -gt 0 ]
     284      then
     285         query=$query" AND "
     286      fi
     287      needprims=( `getprimary $need` )
     288      # in case the primaries of the tables agree
     289      #   only the condition is given
     290      # for tables with differing primaries a special query
     291      #   is needed
     292      if [ "`echo ${needprims[@]}`" == "`echo ${prims[@]}`" ]
     293      then
     294         query=$query" NOT ISNULL("$need"Status.fStartTime) AND "
     295         query=$query" NOT ISNULL("$need"Status.fStopTime) AND "
     296         query=$query" ISNULL("$need"Status.fReturnCode) "
     297      else
     298         query=$query" (SELECT COUNT(*) FROM "$need"Status "
     299         query=$query" "`getjoin $need`" "
     300         query=$query" WHERE "$step"Status."`echo ${prims[0]} | sed -e 's/,//g'`"="$step"Status."`echo ${prims[0]} | sed -e 's/,//g'`
     301         for (( j=1 ; j < ${#prims[@]} ; j++ ))
     302         do
     303            query=$query" AND "$step"Status."`echo ${prims[$j]} | sed -e 's/,//g'`"="$step"Status."`echo ${prims[$j]} | sed -e 's/,//g'`
     304         done
     305         query=$query") = (SELECT COUNT(*) FROM "$need"Status "
     306         query=$query" "`getjoin $need`" "
     307         query=$query" WHERE "$step"Status."`echo ${prims[0]} | sed -e 's/,//g'`"="$step"Status."`echo ${prims[0]} | sed -e 's/,//g'`
     308         for (( j=1 ; j < ${#prims[@]} ; j++ ))
     309         do
     310            query=$query" AND "$step"Status."`echo ${prims[$j]} | sed -e 's/,//g'`"="$step"Status."`echo ${prims[$j]} | sed -e 's/,//g'`
     311         done
     312         query=$query" AND NOT ISNULL(fStartTime) "
     313         query=$query" AND NOT ISNULL(fStopTime) "
     314         query=$query" AND ISNULL(fReturnCode)) "
     315      fi
     316      counter=`echo $counter + 1 | bc -l`
     317   done
     318   # add condition for the status of the step itself
     319   query=$query" AND ISNULL("$step"Status.fStartTime) "
     320   query=$query" AND ISNULL("$step"Status.fStopTime) "
     321   query=$query" AND ISNULL("$step"Status.fReturnCode) "
     322}
     323
    295324# function to get todolist
     325#   returns the next or the list of next steps
    296326function gettodo()
    297327{
     328   # reset the variable for the number of the next step
    298329   process=
    299330   printprocesslog "INFO getting todo..."
    300331   getstepinfo
    301332   # get query
    302    query=" SELECT "${prims[0]}
    303    for (( i=1 ; i < ${#prims[@]} ; i++ ))
     333   query=" SELECT "`echo ${prims[0]} | sed -e 's/,//g'`
     334   for (( j=1 ; j < ${#prims[@]} ; j++ ))
    304335   do
    305       query=$query", ${prims[$i]}"
     336      query=$query", "`echo ${prims[$j]} | sed -e 's/,//g'`
    306337   done
    307    query=$query" FROM $table WHERE "
    308    if ! echo $needs | grep '#' > /dev/null
    309    then
    310       for need in $needs
    311       do
    312          query=$query" NOT ISNULL($need) AND"
    313       done
    314    fi
    315    query=$query" ISNULL($column) "
     338   # get middle par of query
     339   middlepartofquery
     340   # add requirement for production host in case it is needed
    316341   if [ "$2 " != " " ]
    317342   then
    318343      query=$query" AND fProductionHostKEY=$2 "
    319344   fi
    320    query=$query" AND ISNULL(fStartTime) AND ISNULL(fFailedTime) AND ISNULL(fProgramId) AND ISNULL(fReturnCode) "
    321    query=$query" ORDER BY fPriority desc "
     345   # order by priority to the the number of the next step to be done
     346   query=$query" ORDER BY "$step"Status.fPriority desc "
     347   # add limitation in case only one or a limited number of
     348   #  processes should be executed
    322349   if [ "$1 " != " " ]
    323350   then
    324351      query=$query" limit 0, $1 "
    325352   fi
    326 #   echo " QUERY: "$query
     353   # print query
     354   echo " gettodo QUERY: "$query
    327355   printprocesslog "INFO gettodo QUERY: "$query
     356   # execute query
    328357   if ! process=`mysql -s -u $us --password=$pw --host=$ho $db -e " $query "`
    329358   then
     
    331360      finish
    332361   fi
    333 
     362   # get numbers of next step from mysql result
    334363   if [ "$process" = "" ]
    335364   then
     
    342371}
    343372
    344 
    345373# function to get the number of processes which still have to be done
    346374function getstatus()
    347375{
     376   # reset the variable for the number of steps to be done
    348377   numproc=
    349378   getstepinfo
    350379   # get query
    351    query=" SELECT COUNT(*) FROM $table WHERE "
    352    if ! echo $needs | grep '#' > /dev/null
    353    then
    354       for need in $needs
    355       do
    356          query=$query" NOT ISNULL($need) AND"
    357       done
    358    fi
    359    query=$query" ISNULL($column) "
     380   query=" SELECT COUNT(*), 1 " # the 1 is just for grouping
     381   # get middle part of query
     382   middlepartofquery
     383   # add requirement for production host in case it is needed
    360384   if [ "$1 " != " " ]
    361385   then
    362386      query=$query" AND fProductionHostKEY=$1 "
    363387   fi
    364    query=$query" AND ISNULL(fStartTime) AND ISNULL(fFailedTime) AND ISNULL(fProgramId) AND ISNULL(fReturnCode) "
    365    query=$query" GROUP BY $column "
    366 #   echo "QUERY: "$query
     388   # group by an 'artifical' column to get the number of lines
     389   query=$query" GROUP BY 2 "
     390   # printing query
     391   echo " getstatus QUERY: "$query
    367392   printprocesslog "INFO getstatus QUERY: "$query
    368    if ! numproc=`mysql -s -u $us --password=$pw --host=$ho $db -e " $query "`
     393   # execute query
     394   if ! numprocs=( `mysql -s -u $us --password=$pw --host=$ho $db -e " $query "` )
    369395   then
    370396      printprocesslog "ERROR could not query number of processes from db (program: $program, function getstatus)"
     
    372398      continue
    373399   fi
    374    if [ "$numproc" = "" ]
     400   # get number of processes from mysql result
     401   if [ "${numprocs[1]}" = "" ]
    375402   then
    376403      numproc=0
     404   else
     405      numproc=${numprocs[0]}
    377406   fi
    378407}
     
    381410function setstatus()
    382411{
    383    if [ "$column" = "no" ]
     412   # remark:
     413   # this function does not include the 'Default' flag
     414   # for resetting steps
     415
     416   # for dowebplots (there are steps which have no entry in the DB)
     417   if [ "$step" = "no" ]
    384418   then
    385419      return
    386420   fi
    387    resetstatusvalues
    388    evalstatus $@
     421   
     422   # reset status values
     423   starttime=NULL
     424   stoptime=NULL
     425   returncode=NULL
     426   # evaluate the status values
     427   case $@ in
     428      start)   printprocesslog "INFO setstatus start"
     429               starttime="Now()"
     430               ;;
     431       stop)   case $check in
     432                  ok)  printprocesslog "INFO setstatus stop - ok"
     433                       starttime=noreset
     434                       stoptime="Now()"
     435                       ;;
     436                  no)  printprocesslog "INFO setstatus stop - nothing new"
     437                       check="ok"
     438                       ;;
     439                   *)  printprocesslog "INFO setstatus stop - failed"
     440                       starttime=noreset
     441                       stoptime="Now()"
     442                       if [ "$check" == "" ]
     443                       then
     444                          returncode=1
     445                       else
     446                          returncode=$check
     447                       fi
     448                       check="ok"
     449                       ;;
     450               esac
     451               ;;
     452          *)   printprocesslog "ERROR function setstatus got wrong variable"
     453               finish
     454               ;;
     455   esac
     456   # get
    389457   getstepinfo
     458   
     459   # get the influences from the steps.rc by evaluating the needs of all steps
     460   influences=`grep $step $rc | grep "Needs" | grep -v "$step[.]Needs" | cut -d'.' -f1`
     461   
    390462   # get query
    391    reset=`grep "$coltab[.]Reset:" $steps | sed -e "s/$coltab[.]Reset://" -e 's/ //g'`
    392    if [ "$reset" = "no" ]
    393    then
    394       printprocesslog "ERROR You cannot reset $column for ${primaries[$s+$s]}"
    395       finish
    396    fi
    397    query=" update $table set $column=$statustime"
    398    if ! echo $influences | grep '#' > /dev/null
    399    then
    400       for influence in $influences
    401       do
    402          query=$query", $influence=NULL"
    403       done
    404    fi
     463   query=" UPDATE "$step"Status "
     464   # add joins to the influenced tables
     465   for influence in $influences
     466   do
     467      query=$query" LEFT JOIN $influence USING("`getprimary $influence`") "
     468      specialjoin=`getjoin $influence`
     469      if ! [ "$specialjoin" = "" ]
     470      then
     471         query=$query$specialjoin
     472      fi
     473   done
     474   # set the status values according to the new status of the step
     475   query=$query" SET "
    405476   if ! [ "$starttime" = "noreset" ]
    406477   then
    407       query=$query", fStartTime=$starttime"
    408    fi
    409    query=$query", fFailedTime=$failedtime, fProgramId=$programid, fReturnCode=$returncode "
    410    query=$query" where "
     478      query=$query" "$step"Status.fStartTime=$starttime, "
     479   fi
     480   query=$query" "$step"Status.fStopTime=$stoptime, "$step"Status.fReturnCode=$returncode "
     481   # set also the status values of the influenced steps
     482   for influence in $influences
     483   do
     484      query=$query", "$influence"Status.fStartTime=NULL "
     485      query=$query", "$influence"Status.fStopTime=NULL "
     486      query=$query", "$influence"Status.fReturnCode=NULL "
     487   done
     488   # give the condition for which step the status values have to be set
     489   query=$query" WHERE "
    411490   if [ "$s" = "" ]
    412491   then
    413492      s=0
    414493   fi
    415    query=$query" ${prims[0]}='${primaries[$s*${#prims[@]}]}'"
    416    for (( i=1 ; i < ${#prims[@]} ; i++ ))
     494   query=$query" "`echo ${prims[0]} | sed -e 's/,//g'`"='${primaries[$s*${#prims[@]}]}'"
     495   for (( j=1 ; j < ${#prims[@]} ; j++ ))
    417496   do
    418       query=$query" AND ${prims[$i]}='${primaries[$s*${#prims[@]}+$i]}' "
     497      query=$query" AND "`echo ${prims[$j]} | sed -e 's/,//g'`"='${primaries[$s*${#prims[@]}+$j]}' "
    419498   done   
    420 #   echo " QUERY: "$query
     499   # print query
     500   echo " setstatus QUERY: "$query
    421501   printprocesslog "INFO setstatus QUERY: "$query
     502   # execute query
    422503   if ! mysql -s -u $us --password=$pw --host=$ho $db -e " $query "
    423504   then
     
    425506      finish
    426507   fi
    427 
    428508}
    429509
Note: See TracChangeset for help on using the changeset viewer.