| 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): Thomas Bretz, 08/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
|
|---|
| 19 | ! Author(s): Daniela Dorner, 08/2004 <mailto:dorner@astro.uni-wuerzburg.de>
|
|---|
| 20 | !
|
|---|
| 21 | ! Copyright: MAGIC Software Development, 2000-2004
|
|---|
| 22 | !
|
|---|
| 23 | !
|
|---|
| 24 | \* ======================================================================== */
|
|---|
| 25 |
|
|---|
| 26 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 27 | //
|
|---|
| 28 | // fillcalib.C
|
|---|
| 29 | // ===========
|
|---|
| 30 | //
|
|---|
| 31 | // This macro is used to read the calibartion-/callisto-output files.
|
|---|
| 32 | // These files are automatically called calib00000.root.
|
|---|
| 33 | //
|
|---|
| 34 | // From this file the MBadPixelsCam and the MGeomCam is extracted. If
|
|---|
| 35 | // the geometry isn't found MGeomCamMagic is used as a default.
|
|---|
| 36 | //
|
|---|
| 37 | // Usage:
|
|---|
| 38 | // .x fillcalib.C("/data/MAGIC/Period014/calib00000.root", kTRUE)
|
|---|
| 39 | //
|
|---|
| 40 | // The second argument is the 'dummy-mode'. If it is kTRUE dummy-mode is
|
|---|
| 41 | // switched on and nothing will be written into the database. This is usefull
|
|---|
| 42 | // for tests.
|
|---|
| 43 | //
|
|---|
| 44 | // The corresponding sequence number is extracted from the filename...
|
|---|
| 45 | // FIXME: MSeqeuence should be stored in the calib-file?
|
|---|
| 46 | //
|
|---|
| 47 | // The macro can also be run without ACLiC but this is a lot slower...
|
|---|
| 48 | //
|
|---|
| 49 | // Remark: Running it from the commandline looks like this:
|
|---|
| 50 | // root -q -l -b fillcalib.C+\(\"filename\"\,kFALSE\) 2>&1 | tee fillcalib.log
|
|---|
| 51 | //
|
|---|
| 52 | // Make sure, that database and password are corretly set in a resource
|
|---|
| 53 | // file called sql.rc and the resource file is found.
|
|---|
| 54 | //
|
|---|
| 55 | // Returns 0 in case of failure and 1 in case of success.
|
|---|
| 56 | //
|
|---|
| 57 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 58 | #include <iostream>
|
|---|
| 59 |
|
|---|
| 60 | #include <TEnv.h>
|
|---|
| 61 | #include <TRegexp.h>
|
|---|
| 62 |
|
|---|
| 63 | #include <TFile.h>
|
|---|
| 64 | #include <TSQLResult.h>
|
|---|
| 65 | #include <TSQLRow.h>
|
|---|
| 66 |
|
|---|
| 67 | #include "MSQLServer.h"
|
|---|
| 68 |
|
|---|
| 69 | #include "MGeomCamMagic.h"
|
|---|
| 70 | #include "MBadPixelsCam.h"
|
|---|
| 71 |
|
|---|
| 72 | using namespace std;
|
|---|
| 73 |
|
|---|
| 74 | // --------------------------------------------------------------------------
|
|---|
| 75 | //
|
|---|
| 76 | // Checks whether an entry is already existing
|
|---|
| 77 | //
|
|---|
| 78 | Bool_t ExistStr(MSQLServer &serv, const char *column, const char *table, Int_t test)
|
|---|
| 79 | {
|
|---|
| 80 | TString query(Form("SELECT %s FROM %s WHERE %s='%d'", column, table, column, test));
|
|---|
| 81 | TSQLResult *res = serv.Query(query);
|
|---|
| 82 | if (!res)
|
|---|
| 83 | return kFALSE;
|
|---|
| 84 |
|
|---|
| 85 | TSQLRow *row;
|
|---|
| 86 |
|
|---|
| 87 | Bool_t rc = kFALSE;
|
|---|
| 88 | while ((row=res->Next()))
|
|---|
| 89 | {
|
|---|
| 90 | if ((*row)[0])
|
|---|
| 91 | {
|
|---|
| 92 | rc = kTRUE;
|
|---|
| 93 | break;
|
|---|
| 94 | }
|
|---|
| 95 | }
|
|---|
| 96 |
|
|---|
| 97 | delete res;
|
|---|
| 98 |
|
|---|
| 99 | return rc;
|
|---|
| 100 | }
|
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 | int Process(MSQLServer &serv, TString fname, Bool_t dummy)
|
|---|
| 104 | {
|
|---|
| 105 | MBadPixelsCam badpix;
|
|---|
| 106 |
|
|---|
| 107 | TFile file(fname, "READ");
|
|---|
| 108 | if (badpix.Read("MBadPixelsCam")<=0)
|
|---|
| 109 | {
|
|---|
| 110 | cout << "ERROR - Reading of MBadPixelsCam failed." << endl;
|
|---|
| 111 | return 0;
|
|---|
| 112 | }
|
|---|
| 113 |
|
|---|
| 114 | MGeomCamMagic def;
|
|---|
| 115 |
|
|---|
| 116 | MGeomCam *geom = (MGeomCam*)file.Get("MGeomCam");
|
|---|
| 117 | if (!geom)
|
|---|
| 118 | {
|
|---|
| 119 | cout << "WARNING - Reading of MGeomCam failed... using default <MGeomCamMagic>" << endl;
|
|---|
| 120 | geom = &def;
|
|---|
| 121 | }
|
|---|
| 122 |
|
|---|
| 123 | cout << "Camera Geometry: " << geom->ClassName() << endl;
|
|---|
| 124 |
|
|---|
| 125 | const Short_t unsin = badpix.GetNumUnsuitable(MBadPixelsPix::kUnsuitableRun, geom, 0);
|
|---|
| 126 | const Short_t unsout = badpix.GetNumUnsuitable(MBadPixelsPix::kUnsuitableRun, geom, 1);
|
|---|
| 127 |
|
|---|
| 128 | const Short_t unrin = badpix.GetNumUnsuitable(MBadPixelsPix::kUnreliableRun, geom, 0);
|
|---|
| 129 | const Short_t unrout = badpix.GetNumUnsuitable(MBadPixelsPix::kUnreliableRun, geom, 1);
|
|---|
| 130 |
|
|---|
| 131 | const Short_t isoin = badpix.GetNumIsolated(*geom, 0);
|
|---|
| 132 | const Short_t isoout = badpix.GetNumIsolated(*geom, 1);
|
|---|
| 133 |
|
|---|
| 134 | const Short_t clumax = badpix.GetNumMaxCluster(*geom);
|
|---|
| 135 |
|
|---|
| 136 | if (unsin<0 || unsout<0 || unrin<0 || unrout<0 || isoin<0 || isoout<0 || clumax<0)
|
|---|
| 137 | return 0;
|
|---|
| 138 |
|
|---|
| 139 | // MHCamera hist(geom);
|
|---|
| 140 | // hist.SetCamContent(badpix, 1);
|
|---|
| 141 | // hist.DrawCopy();
|
|---|
| 142 | // hist.SetCamContent(badpix, 3);
|
|---|
| 143 | // hist.DrawCopy();
|
|---|
| 144 |
|
|---|
| 145 | TString sequence = fname(TRegexp("calib[0-9]+[.]root$"));
|
|---|
| 146 | if (sequence.IsNull())
|
|---|
| 147 | return 0;
|
|---|
| 148 |
|
|---|
| 149 | Int_t seq = atoi(sequence.Data()+5);
|
|---|
| 150 |
|
|---|
| 151 | cout << "Sequence #" << seq << endl;
|
|---|
| 152 | cout << " Unsuitable: (i/o) " << Form("%3d %3d", (int)unsin, (int)unsout) << endl; // Unbrauchbar
|
|---|
| 153 | cout << " Unreliable: (i/o) " << Form("%3d %3d", (int)unrin, (int)unrout) << endl; // Unzuverlaessig
|
|---|
| 154 | cout << " Isolated: (i/o) " << Form("%3d %3d", (int)isoin, (int)isoout) << endl; // Isolated (unbrauchbar)
|
|---|
| 155 | cout << " Max.Cluster: (i/o) " << Form("%3d", (int)clumax) << endl; // Max Cluster
|
|---|
| 156 |
|
|---|
| 157 | TString query;
|
|---|
| 158 | if (!ExistStr(serv, "fSequenceFirst", "MyMagic.Calibration", seq))
|
|---|
| 159 | {
|
|---|
| 160 |
|
|---|
| 161 | query = Form("INSERT MyMagic.Calibration SET"
|
|---|
| 162 | " fSequenceFirst=%d,"
|
|---|
| 163 | " fUnsuitableInner=%d, "
|
|---|
| 164 | " fUnsuitableOuter=%d, "
|
|---|
| 165 | " fUnreliableInner=%d, "
|
|---|
| 166 | " fUnreliableOuter=%d, "
|
|---|
| 167 | " fIsolatedInner=%d, "
|
|---|
| 168 | " fIsolatedOuter=%d, "
|
|---|
| 169 | " fIsolatedMaxCluster=%d",
|
|---|
| 170 | seq, (int)unsin, (int)unsout, (int)unrin,
|
|---|
| 171 | (int)unrout, (int)isoin, (int)isoout, (int)clumax);
|
|---|
| 172 | }
|
|---|
| 173 | else
|
|---|
| 174 | {
|
|---|
| 175 | query = Form("UPDATE MyMagic.Calibration SET"
|
|---|
| 176 | " fUnsuitableInner=%d, "
|
|---|
| 177 | " fUnsuitableOuter=%d, "
|
|---|
| 178 | " fUnreliableInner=%d, "
|
|---|
| 179 | " fUnreliableOuter=%d, "
|
|---|
| 180 | " fIsolatedInner=%d, "
|
|---|
| 181 | " fIsolatedOuter=%d, "
|
|---|
| 182 | " fIsolatedMaxCluster=%d"
|
|---|
| 183 | " WHERE fSequenceFirst=%d,",
|
|---|
| 184 | (int)unsin, (int)unsout, (int)unrin,(int)unrout,
|
|---|
| 185 | (int)isoin, (int)isoout, (int)clumax, seq);
|
|---|
| 186 | }
|
|---|
| 187 |
|
|---|
| 188 | if (dummy)
|
|---|
| 189 | return 0;
|
|---|
| 190 |
|
|---|
| 191 | TSQLResult *res = serv.Query(query);
|
|---|
| 192 | if (!res)
|
|---|
| 193 | {
|
|---|
| 194 | cout << "ERROR - Query failed: " << query << endl;
|
|---|
| 195 | return 0;
|
|---|
| 196 | }
|
|---|
| 197 | delete res;
|
|---|
| 198 |
|
|---|
| 199 | return 1;
|
|---|
| 200 | }
|
|---|
| 201 |
|
|---|
| 202 | int fillcalib(TString fname, Bool_t dummy=kTRUE)
|
|---|
| 203 | {
|
|---|
| 204 | TEnv env("sql.rc");
|
|---|
| 205 |
|
|---|
| 206 | MSQLServer serv(env);
|
|---|
| 207 | if (!serv.IsConnected())
|
|---|
| 208 | {
|
|---|
| 209 | cout << "ERROR - Connection to database failed." << endl;
|
|---|
| 210 | return 0;
|
|---|
| 211 | }
|
|---|
| 212 |
|
|---|
| 213 | cout << "fillcalib" << endl;
|
|---|
| 214 | cout << "---------" << endl;
|
|---|
| 215 | cout << endl;
|
|---|
| 216 | cout << "Connected to " << serv.GetName() << endl;
|
|---|
| 217 | cout << "File: " << fname << endl;
|
|---|
| 218 | cout << endl;
|
|---|
| 219 |
|
|---|
| 220 | return Process(serv, fname, dummy);
|
|---|
| 221 | }
|
|---|