| 1 | /* ======================================================================== *\ | 
|---|
| 2 | ! | 
|---|
| 3 | ! * | 
|---|
| 4 | ! * This file is part of MARS, the MAGIC Analysis and Reconstruction | 
|---|
| 5 | ! * Software. It is distributed to you in the hope that it can be a useful | 
|---|
| 6 | ! * and timesaving tool in analysing Data of imaging Cerenkov telescopes. | 
|---|
| 7 | ! * It is distributed WITHOUT ANY WARRANTY. | 
|---|
| 8 | ! * | 
|---|
| 9 | ! * Permission to use, copy, modify and distribute this software and its | 
|---|
| 10 | ! * documentation for any purpose is hereby granted without fee, | 
|---|
| 11 | ! * provided that the above copyright notice appear in all copies and | 
|---|
| 12 | ! * that both that copyright notice and this permission notice appear | 
|---|
| 13 | ! * in supporting documentation. It is provided "as is" without express | 
|---|
| 14 | ! * or implied warranty. | 
|---|
| 15 | ! * | 
|---|
| 16 | ! | 
|---|
| 17 | ! | 
|---|
| 18 | !   Author(s): Daniela Dorner, 01/2005 <mailto:dorner@astro.uni-wuerzburg.de> | 
|---|
| 19 | ! | 
|---|
| 20 | !   Copyright: MAGIC Software Development, 2000-2006 | 
|---|
| 21 | ! | 
|---|
| 22 | ! | 
|---|
| 23 | \* ======================================================================== */ | 
|---|
| 24 |  | 
|---|
| 25 | ///////////////////////////////////////////////////////////////////////////// | 
|---|
| 26 | // | 
|---|
| 27 | // insertcacofiles.C | 
|---|
| 28 | // ================= | 
|---|
| 29 | // | 
|---|
| 30 | // Macro to insert runnumber of the caco files, which contain the information | 
|---|
| 31 | // for a run, for which no caco file is available. | 
|---|
| 32 | // | 
|---|
| 33 | // Sometimes the DAQ aborts a run and starts itself a new one. In this cases | 
|---|
| 34 | // the camera controll doesn't start a new file, as the command to | 
|---|
| 35 | // start a new run was not sent by the central control. So the caco | 
|---|
| 36 | // information is stored in the previous caco file, which has a different | 
|---|
| 37 | // runnumber. To be able to merpp the information into the calibrated data | 
|---|
| 38 | // file, the runnumber of the file containing the information has to be found. | 
|---|
| 39 | // This is done by a script. | 
|---|
| 40 | // insertcacofiles.C inserts the runnumber of the file, that has been found, | 
|---|
| 41 | // into the column CaCoFileFound. | 
|---|
| 42 | // | 
|---|
| 43 | // Usage: | 
|---|
| 44 | //   .x insertcacofile.C+("runnumber", "newrunnumber") | 
|---|
| 45 | // The first is the runnumber of which the cacofile is missing, the second is | 
|---|
| 46 | // the runnumber of the file in which the information probably can be found. | 
|---|
| 47 | // | 
|---|
| 48 | // Make sure, that database and password are corretly set in a resource | 
|---|
| 49 | // file called sql.rc and the resource file is found. | 
|---|
| 50 | // | 
|---|
| 51 | // Returns 0 in case of failure and 1 in case of success. | 
|---|
| 52 | // | 
|---|
| 53 | ///////////////////////////////////////////////////////////////////////////// | 
|---|
| 54 |  | 
|---|
| 55 | #include <iostream> | 
|---|
| 56 | #include <iomanip> | 
|---|
| 57 | #include <fstream> | 
|---|
| 58 |  | 
|---|
| 59 | #include <TSystem.h> | 
|---|
| 60 |  | 
|---|
| 61 | #include <TSQLRow.h> | 
|---|
| 62 | #include <TSQLResult.h> | 
|---|
| 63 |  | 
|---|
| 64 | #include "MSQLServer.h" | 
|---|
| 65 |  | 
|---|
| 66 | using namespace std; | 
|---|
| 67 |  | 
|---|
| 68 | int insertcacofile(TString runnumber, TString newrunnumber) | 
|---|
| 69 | { | 
|---|
| 70 | MSQLServer serv("sql.rc"); | 
|---|
| 71 | if (!serv.IsConnected()) | 
|---|
| 72 | { | 
|---|
| 73 | cout << "ERROR - Connection to database failed." << endl; | 
|---|
| 74 | return 0; | 
|---|
| 75 | } | 
|---|
| 76 | cout << "insertcacofile" << endl; | 
|---|
| 77 | cout << "--------------" << endl; | 
|---|
| 78 | cout << endl; | 
|---|
| 79 | cout << "Connected to " << serv.GetName() << endl; | 
|---|
| 80 | cout << endl; | 
|---|
| 81 |  | 
|---|
| 82 | //get new runnumber | 
|---|
| 83 | Int_t newrunno=atoi(newrunnumber.Data()); | 
|---|
| 84 | //build query and insert information | 
|---|
| 85 | TString query(Form("UPDATE RunProcessStatus SET fCaCoFileAvail=Now(), fCaCoFileFound=%d WHERE fRunNumber=%s ", | 
|---|
| 86 | newrunno, runnumber.Data())); | 
|---|
| 87 | cout << "qu: " << query << endl; | 
|---|
| 88 |  | 
|---|
| 89 | TSQLResult *res = serv.Query(query); | 
|---|
| 90 | if (!res) | 
|---|
| 91 | { | 
|---|
| 92 | cout << "Error - update didn't work." << endl; | 
|---|
| 93 | return 0; | 
|---|
| 94 | } | 
|---|
| 95 |  | 
|---|
| 96 | delete res; | 
|---|
| 97 | return 1; | 
|---|
| 98 | } | 
|---|
| 99 |  | 
|---|
| 100 |  | 
|---|