Ignore:
Timestamp:
07/20/08 15:47:10 (16 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/datacenter
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/datacenter/macros/checkfileavail.C

    r8851 r9018  
    1818!   Author(s): Daniela Dorner, 01/2005 <mailto:dorner@astro.uni-wuerzburg.de>
    1919!
    20 !   Copyright: MAGIC Software Development, 2000-2006
     20!   Copyright: MAGIC Software Development, 2000-2008
    2121!
    2222!
     
    3434//
    3535// executing the macro:
    36 //  .x checkfileavail.C+("sequencefile")
     36//  .x checkfileavail.C+(100002)
    3737// the sequencefile (including path) has to be given, as the macro retrieves
    3838// from there the runnumbers
    3939//
    40 // the macro returns 0, if there's no connection to the database, 2, if a
    41 // file is missing, and 1 if all files are there
     40// the macro returns 0, if there's no connection to the database, 2 if a
     41// file is missing, and 1 if all files are there, 3 in case of error.
    4242// the return value is checked by the script, that executes the macro
    4343//
     
    4545//
    4646/////////////////////////////////////////////////////////////////////////////
    47 
    4847#include <iostream>
    4948#include <iomanip>
    50 #include <fstream>
    5149
    52 #include <TEnv.h>
    53 
    54 #include <MSQLServer.h>
    5550#include <TSQLRow.h>
    5651#include <TSQLResult.h>
    5752
     53#include "MSQLServer.h"
     54
    5855using namespace std;
    5956
    60 
    61 //check the value of a column for a run
    62 //if a file is not available, the column contains nothing (NULL) - this value is returned
    63 TString GetStatus(MSQLServer &serv, TEnv &rc, TString primary, TString table, TString column)
     57int checkfileavail(Int_t num, Int_t tel)
    6458{
    65     TString query(Form("SELECT %s FROM %s WHERE %s=%s",
    66                        column.Data(), table.Data(),
    67                        rc.GetValue(table+".Primary", ""),
    68                        primary.Data()));
    69 
    70     cout << "Query: " << query << endl;
    71 
    72     TSQLResult *res = serv.Query(query);
    73     if (!res)
    74     {
    75         cout << "Error - no run to check" << endl;
    76         return "";
    77     }
    78 
    79     TSQLRow *row = res->Next();
    80 
    81     TString ret = row ? (*row)[0] : "";
    82 
    83     delete res;
    84 
    85     return ret;
    86 }
    87 
    88 int checkfileavail(TString sequencefile)
    89 {
    90     TEnv env("sql.rc");
    91 
    92     MSQLServer serv(env);
     59    MSQLServer serv("sql.rc");
    9360    if (!serv.IsConnected())
    9461    {
     
    9663        return 0;
    9764    }
     65
    9866    cout << "checkfileavail" << endl;
    9967    cout << "--------------" << endl;
     
    10169    cout << "Connected to " << serv.GetName() << endl;
    10270    cout << endl;
     71    cout << "Sequence: " << num << endl;
     72    cout << "Telecope: " << tel << endl;
     73    cout << endl;
    10374
    104     TEnv rc("steps.rc");
     75    // -------------------------------------------
    10576
    106     //reading runnumbers from Sequencefile
    107     TEnv sequ(sequencefile);
    108     cout << "sequ file: " << sequencefile.Data() << endl;
    109     TString runs;
    110     runs = sequ.GetValue("Runs", "");
    111     runs.ReplaceAll(" ", ",");
    112     if (runs.IsNull())
    113     {
    114         cout << "ERROR - No runs in file " << sequencefile << " found." << endl;
    115         return 0;
    116     }
    117 
    118     //getting runnumbers from database
    119     //(not neccessary anymore -> can be changed)
    120     TString query="SELECT fRunNumber FROM RunData WHERE fRunNumber in (";
    121     query +=runs.Data();
    122     query +=")";
     77    TString query = "MIN( NOT ("
     78        "ISNULL(fRawFileAvail) OR "
     79        "ISNULL(fCCFileAvail) OR "
     80        "ISNULL(fCaCoFileAvail) OR "
     81        "ISNULL(fCaCoFileFound) OR "
     82        "ISNULL(fTimingCorrection) OR "
     83        "ISNULL(fCompmux) "
     84        ")) "
     85        "FROM RunProcessStatus "
     86        "LEFT JOIN RunData USING (fTelescopeNumber,fRunNumber,fFileNumber) "
     87    query += Form("WHERE fSequenceFirst=%d AND fTelescopeNumber=%d", num, tel);
    12388
    12489    TSQLResult *res = serv.Query(query);
    12590    if (!res)
    126         cout << "Error - no run to check" << endl;
     91        return 3;
    12792
    128     //check for each run the availability of files from the table RunProcessStatus
    129     //the following columns have to be checked:
    130     //fCCFileAvail, fCaCoFileAvail, fCaCoFileFound, fRawFileAvail, fTimingCorrection, fCompmux
    131     //fTimingCorrection has to be checked, as only rawfiles with correct timing should be calibrated
    132     TSQLRow *row=0;
    133     while ((row = res->Next()))
     93    if (res->GetRowCount()!=1)
    13494    {
    135         TString runno=(*row)[0];
    136         cout << "run#: " << runno << endl;
    137         //if one value returns "" (i.e. column is NULL), 0 is returned
    138         if (GetStatus(serv, rc, runno, "RunProcessStatus", "fCCFileAvail").IsNull()
    139             || GetStatus(serv, rc, runno, "RunProcessStatus", "fCaCoFileAvail").IsNull()
    140             || GetStatus(serv, rc, runno, "RunProcessStatus", "fCaCoFileFound").IsNull()
    141             || GetStatus(serv, rc, runno, "RunProcessStatus", "fTimingCorrection").IsNull()
    142             || GetStatus(serv, rc, runno, "RunProcessStatus", "fCompmux").IsNull()
    143 //            || GetStatus(serv, rc, runno, "RunProcessStatus", "fTimingCorrection")=="1970-01-01 00:00:00"
    144             || GetStatus(serv, rc, runno, "RunProcessStatus", "fRawFileAvail").IsNull())
    145             return 2;
     95        cout << "ERROR - Unexpected number of returned rows (" << res->GetRowCount() << ")" << endl;
     96        delete res;
     97        return 3;
    14698    }
    147     //if all values are okay (i.e. files are availabel), 1 is returned
    148     return 1;
    14999
     100    TSQlRow *row = res->Next();
     101
     102    if (!row || !(*row)[0])
     103    {
     104        cout << "ERROR - Unexpected result." << endl;
     105        delete res;
     106        return 3;
     107    }
     108
     109    const Int_t rc = atoi((*row)[0]);
     110
     111    delete res;
     112
     113    return rc==1 ? 1 : 2;
    150114}
    151 
  • trunk/MagicSoft/Mars/datacenter/macros/checkstardone.C

    r7859 r9018  
    1818!   Author(s): Daniela Dorner, 05/2005 <mailto:dorner@astro.uni-wuerzburg.de>
    1919!
    20 !   Copyright: MAGIC Software Development, 2000-2006
     20!   Copyright: MAGIC Software Development, 2000-2008
    2121!
    2222!
     
    2828// ===============
    2929//
    30 // check the availability of the star files for one sequence:
     30// check the availability of all star files for one dataset:
    3131// if star has been executed successfully, this information has been inserted
    3232// into the database (SequenceProcessStatus) with this macro this information
     
    3434//
    3535// executing the macro:
    36 //  .x checkstardone.C+("sequencenumber")
     36//  .x checkstardone.C+(1)
    3737//
    38 // the macro returns 0, if there's no connection to the database, 2, if a
    39 // file is missing, and 1 if all files are there
     38// The macro returns 0, if there's no connection to the database, 2 if
     39// star is not done, and 1 if star done, 3 in case of error.
    4040// the return value is checked by the script, that executes the macro
    4141//
    42 // this macro is very similar to the macro checkfileavail.C
     42// This macro is very similar to the macro checkfileavail.C
    4343//
    4444/////////////////////////////////////////////////////////////////////////////
    45 
    4645#include <iostream>
    4746#include <iomanip>
    48 #include <fstream>
    4947
    50 #include <TEnv.h>
    51 
    52 #include <MSQLServer.h>
    5348#include <TSQLRow.h>
    5449#include <TSQLResult.h>
    5550
     51#include "MSQLServer.h"
     52
    5653using namespace std;
    5754
    58 
    59 //check the value of a column for a sequence
    60 TString GetStatus(MSQLServer &serv, TEnv &env, TString primary, TString table, TString column)
     55int checkstardone(Int_t num)
    6156{
    62     TString query(Form("SELECT %s FROM %s WHERE %s=%s",
    63                        column.Data(), table.Data(),
    64                        env.GetValue(table+".Primary", ""),
    65                        primary.Data()));
    66 
    67     cout << "Query: " << query << endl;
    68 
    69     TSQLResult *res = serv.Query(query);
    70     if (!res)
    71     {
    72         cout << "Error - no sequence to check" << endl;
    73         return "";
    74     }
    75 
    76     TSQLRow *row = res->Next();
    77 
    78     TString rc = row ? (*row)[0] : "";
    79 
    80     delete res;
    81 
    82     return rc;
    83 }
    84 
    85 int checkstardone(TString datasetno)
    86 {
    87     TEnv env("sql.rc");
    88 
    89     MSQLServer serv(env);
     57    MSQLServer serv("sql.rc");
    9058    if (!serv.IsConnected())
    9159    {
     
    9361        return 0;
    9462    }
     63
    9564    cout << "checkstardone" << endl;
    9665    cout << "-------------" << endl;
     
    9867    cout << "Connected to " << serv.GetName() << endl;
    9968    cout << endl;
     69    cout << "Dataset: " << num << endl;
     70    cout << endl;
    10071
    101     TEnv rc("steps.rc");
     72    // -------------------------------------------
    10273
    103     //check if fStar not NULL for sequence
    104     if (GetStatus(serv, rc, datasetno, "SequenceProcessStatus", "fStar").IsNull())
    105         return 2;
     74    TString query = "NOT ISNULL(fStar) FROM SequenceProcessStatus "
     75        "LEFT JOIN DataSetSequenceMapping USING (fTelescopeNumber,fSequenceFirst) ";
     76    query += Form("WHERE fDataSetNumber=%d", num);
    10677
    107     return 1;
     78    TSQLResult *res = serv.Query(query);
     79    if (!res)
     80        return 3;
     81
     82    if (res->GetRowCount()!=1)
     83    {
     84        cout << "ERROR - Unexpected number of returned rows (" << res->GetRowCount() << ")" << endl;
     85        delete res;
     86        return 3;
     87    }
     88
     89    TSQlRow *row = res->Next();
     90
     91    if (!row || !(*row)[0])
     92    {
     93        cout << "ERROR - Unexpected result." << endl;
     94        delete res;
     95        return 3;
     96    }
     97
     98    const Int_t rc = atoi((*row)[0]);
     99
     100    delete res;
     101
     102    return rc==1 ? 1 : 2;
    108103}
    109 
  • trunk/MagicSoft/Mars/datacenter/scripts/checkstardone

    r8482 r9018  
    2020#   Author(s): Daniela Dorner  08/2004 <mailto:dorner@astro.uni-wuerzburg.de>
    2121#
    22 #   Copyright: MAGIC Software Development, 2000-2007
     22#   Copyright: MAGIC Software Development, 2000-2008
    2323#
    2424#
     
    3535# the function setstatus.
    3636#
    37 
    3837source `dirname $0`/sourcefile
    3938printprocesslog "INFO starting $0"
     
    6463for dataset in ${datasets[@]}
    6564do
    66    echo "checking files for dataset $dataset..." >> $scriptlog 2>&1
    67    printprocesslog "INFO checking files for dataset $dataset"
     65   echo "checking star done for sequences of dataset $dataset..." >> $scriptlog 2>&1
     66   printprocesslog "INFO checking star done for sequences of dataset $dataset"
     67
    6868   no=`printf %08d $dataset | cut -c 0-5`
    6969   no2=`printf %08d $dataset`
    70    datasetfile=$datasetpath/$no/dataset`printf %08d $dataset`.txt
    71    
    72    sequences=(`cat $datasetfile | grep Sequences | sed -e 's/SequencesOn://g' | sed -e 's/SequencesOff://g'`)
    73    if [ "$sequences" = "" ]
    74    then
    75       echo "no sequences found" >> $scriptlog 2>&1
    76       echo "continue with next dataset" >> $scriptlog 2>&1
    77       continue
    78    fi
    79    echo "sequences: "${sequences[@]} >> $scriptlog 2>&1
    80    
     70   dsnum=`printf %08d $dataset`
     71
     72   echo "run $program for sequence $sequence..." >> $scriptlog 2>&1
     73
    8174   outpath=$logpath/$program/$no/$no2
    8275   makedir $outpath  >> $scriptlog 2>&1
    83    
     76
    8477   primvar=$dataset
    8578   setstatus "start" >> $scriptlog 2>&1
    8679
    87    for sequence in ${sequences[@]}
    88    do
    89       echo "run $program for sequence $sequence..." >> $scriptlog 2>&1
    90       printprocesslog "INFO check availability for sequence $sequence"
     80   check1=`root -q -b $macrospath/checkstardone.C+\(\""$dsnum\""\) | tee $outpath/checkstardone-$dsnum.log | intgrep`
    9181
    92       check1=`root -q -b $macrospath/checkstardone.C+\(\""$sequence\""\) | tee $outpath/checkstardone-$sequence.log | intgrep`
     82   case $check1 in
     83      1)   echo " check1=$check1 -> everything ok -> continue with next dataset..." >> $scriptlog 2>&1 ;;
     84      2)   echo " check1=$check1 -> star files for dataset $dsnum not yet available -> continue..." >> $scriptlog 2>&1
     85           printprocesslog "INFO files not yet available for dataset $dsnum"
     86           check="no"
     87           break
     88           ;;
     89      0)   echo " check1=$check1 -> no connection to db -> continue..." >> $scriptlog 2>&1
     90           printprocesslog "WARN connection to DB failed"
     91           check="no"
     92           break
     93           ;;
     94      *)   echo " check1=$check1 -> ERROR " >> $scriptlog 2>&1
     95           printprocesslog "ERROR checkstardone.C failed"
     96           com=$Fstardone
     97           comadd=$sequence
     98           check=$check1
     99           break
     100           ;;
     101   esac
    93102
    94       case $check1 in
    95          1)   echo " check1=$check1 -> everything ok -> continue with next sequence..." >> $scriptlog 2>&1 ;;
    96          2)   echo " check1=$check1 -> files for sequence $sequence not yet available -> continue..." >> $scriptlog 2>&1
    97               printprocesslog "INFO files not yet available for sequence $sequence"
    98               check="no"
    99               break
    100               ;;
    101          0)   echo " check1=$check1 -> no connection to db -> continue..." >> $scriptlog 2>&1
    102               printprocesslog "WARN connection to DB failed"
    103               check="no"
    104               break
    105               ;;
    106          *)   echo " check1=$check1 -> ERROR " >> $scriptlog 2>&1
    107               printprocesslog "ERROR $program.C failed"
    108               com=$Fstardone
    109               comadd=$sequence
    110               check=$check1
    111               break
    112               ;;
    113       esac
    114    done
    115    
    116103   setstatus "stop" >> $scriptlog 2>&1
    117104done
    118105
    119106finish >> $scriptlog 2>&1
    120 
Note: See TracChangeset for help on using the changeset viewer.