Ignore:
Timestamp:
05/09/07 17:05:15 (18 years ago)
Author:
Daniela Dorner
Message:
*** empty log message ***
File:
1 edited

Legend:

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

    r7460 r8482  
    2828// ===============
    2929//
    30 // Macro to get from the database the number of the runs, for which no caco
    31 // file is available.
     30// Macro to find caco files for runs which don't have a dedicated caco file.
     31// Called by the script filesondisk
    3232//
    3333// Sometimes the DAQ aborts a run and starts itself a new one. In this cases
     
    3737// runnumber. To be able to merpp the information into the calibrated data
    3838// file, the runnumber of the file containing the information has to be found.
    39 // This is done by a script.
    40 // findcacofiles.C produces the input for this script. It queries from the
    41 // database, for which runs no caco file with the same runnumber is available
    42 // and writes the runnumbers into an txt file.
     39//
     40// findcacofiles.C searches in the database for runs which don't have a
     41// dedicated caco file, and searches for each of these runs, if one of the 10
     42// previous runs has a dedicated caco file. In case one is found, it is
     43// inserted into the database.
    4344//
    4445// Usage:
    45 //   .x findcacofiles.C+("date", "logpath")
    46 // date and logpath are needed only for the output file
     46//   .x findcacofiles.C+
    4747//
    4848// Make sure, that database and password are corretly set in a resource
     
    6060#include <TSystem.h>
    6161
    62 #include <MSQLServer.h>
     62#include "MSQLMagic.h"
    6363#include <TSQLRow.h>
    6464#include <TSQLResult.h>
     
    6767
    6868
    69 int findcacofiles(TString date, TString logpath)
     69int findcacofiles()
    7070{
    7171    TEnv env("sql.rc");
    7272
    73     MSQLServer serv(env);
     73    MSQLMagic serv(env);
    7474    if (!serv.IsConnected())
    7575    {
     
    8383    cout << endl;
    8484
    85     //get runnumbers from database
    86     TString query="SELECT RunProcessStatus.fRunNumber FROM RunProcessStatus ";
    87     query+=" LEFT JOIN RunData on RunData.fRunNumber=RunProcessStatus.fRunNumber ";
    88     query+=" WHERE IsNull(fCaCoFileFound) and fExcludedFDAKEY=1 ";
    89     query+=" and RunProcessStatus.fRunNumber > 10000 and not IsNull(fCCFileAvail)";
     85    //get runnumbers and dates from database
     86    TString query="SELECT RunProcessStatus.fRunNumber, ";
     87    query+=" DATE_FORMAT(ADDDATE(if(fRunStart='0000-00-00 00:00:00', fRunStop, fRunStart), INTERVAL +13 HOUR), '%Y/%m/%d') ";
     88    query+=" FROM RunProcessStatus ";
     89    query+=" LEFT JOIN RunData ON RunData.fRunNumber=RunProcessStatus.fRunNumber ";
     90    query+=" LEFT JOIN Source ON RunData.fSourceKEY=Source.fSourceKEY ";
     91    query+=" WHERE IsNull(fCaCoFileFound) AND fExcludedFDAKEY=1 ";
     92    query+=" AND RunProcessStatus.fRunNumber > 10000 AND NOT IsNull(fCCFileAvail)";
     93    query+=" AND fTest='no'";
    9094
    9195    TSQLResult *res = serv.Query(query);
     
    96100    }
    97101
    98     //create output file
    99     TString filename(Form("%s/findcacofiles-%s.txt", logpath.Data(), date.Data()));
    100     ofstream fout(filename, ios::app);
    101     if (!fout)
    102     {
    103         cout << "ERROR - Cannot open file " << filename << endl;
    104         return 0;
    105     }
    106 
    107     //write runnumbers into output file
     102    Int_t counter=0;
     103    Int_t counter2=0;
    108104    TSQLRow *row=0;
    109105    while ((row = res->Next()))
    110         fout << (*row)[0] << endl;
     106    {
     107        //search nearest previous available CaCoFile
     108        Int_t run=atoi((*row)[0]);
     109        if (TString((*row)[1]).IsNull())
     110        {
     111            cout << "For run " << (*row)[0] << " fRunStart and fRunStop are 0000-00-00 00:00:00. No CaCoFile can be determined. " << endl;
     112            continue;
     113        }
     114        cout << "CaCoFile missing for run " << (*row)[0] << " with date " << (*row)[1] << endl;
     115
     116        query ="SELECT MAX(fCaCoFileFound) FROM RunProcessStatus ";
     117        query+=" LEFT JOIN RunData ON RunData.fRunNumber=RunProcessStatus.fRunNumber ";
     118        query+=Form("WHERE DATE_FORMAT(ADDDATE(fRunStart, INTERVAL +13 HOUR), '%%Y/%%m/%%d')='%s' ",
     119                    (*row)[1]);
     120        query+=Form("AND RunData.fRunNumber IN (%d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d)",
     121                    run, run-1, run-2, run-3, run-4, run-5,
     122                    run-6, run-7, run-8, run-9, run-10);
     123
     124        TSQLResult *res2 = serv.Query(query);
     125        if (!res2)
     126        {
     127            cout << "Error." << endl;
     128            return 0;
     129        }
     130        TSQLRow *row2=0;
     131        row2 = res2->Next();
     132        if ((*row2)[0])
     133        {
     134            cout << "Found CaCoFile at run " << (*row2)[0] << endl;
     135            TString vals=Form("fCaCoFileAvail=Now(), fCaCoFileFound=%s", (*row2)[0]);
     136            TString where=Form("fRunNumber=%d", run);
     137
     138            //insert found runnumber
     139            if (!serv.Update("RunProcessStatus", vals,where))
     140                return 0;
     141            counter2+=1;
     142        }
     143        else
     144            cout << " No caco file found for run " << run << endl;
     145
     146        delete res2;
     147        counter+=1;
     148    }
     149    cout << endl << counter << " missing caco files. " << endl;
     150    cout << counter2 << " caco files found and inserted. " << endl;
    111151
    112152    delete res;
Note: See TracChangeset for help on using the changeset viewer.