source: releases/Mars.2014.05.26/datacenter/macros/fillcondor.C@ 18527

Last change on this file since 18527 was 9098, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 5.0 KB
Line 
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, 06/2008 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2008
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// fillcondor.C
28// ============
29//
30// This macro is used to read self written condor log-files.
31// These files are written to /magic/data/autologs/condor/
32//
33// Usage:
34// .x fillcondor.C("/magic/datacenter/autologs/condor", "2008-06-28", kTRUE)
35// .x fillcondor.C("/magic/datacenter/autologs/condor/2008/06/28", kTRUE)
36//
37// The second argument is the 'dummy-mode'. If it is kTRUE dummy-mode is
38// switched on and nothing will be written into the database. This is usefull
39// for tests.
40//
41// The macro can also be run without ACLiC but this is a lot slower...
42//
43// Remark: Running it from the commandline looks like this:
44// root -q -l -b fillcondor.C+\(\"2008-06-28\"\,kFALSE\) 2>&1 | tee fillcondor.log
45//
46// Make sure, that database and password are corretly set in a resource
47// file called sql.rc and the resource file is found.
48//
49// Returns 2 in case of failure, 1 in case of success and 0 if the connection
50// to the database is not working.
51//
52/////////////////////////////////////////////////////////////////////////////
53#include <fstream>
54#include <iomanip>
55#include <iostream>
56
57#include <TSystem.h>
58
59#include "MTime.h"
60#include "MDirIter.h"
61#include "MSQLMagic.h"
62
63Bool_t Process(MSQLMagic &serv, const TString &path)
64{
65 Int_t rc[3] = {0, 0, 0};
66
67 MDirIter Next(path, "status.*", -1);
68 while (1)
69 {
70 TString fname=Next();
71 if (fname.IsNull())
72 break;
73
74 ifstream fin(fname);
75 if (!fin)
76 continue;
77
78 // Remove path and "status."
79 TString date = gSystem->BaseName(fname)-11;
80 date.ReplaceAll("/status.", " ");
81 date.ReplaceAll("/", "-");
82 date.Insert(13, ":");
83 date += ":00";
84
85 Int_t num = 0;
86 Double_t load = 0;
87 Double_t cload = 0;
88 Int_t claim = 0;
89
90 MTime tm(date);
91 while (1)
92 {
93 TString str;
94 str.ReadLine(fin);
95 if (!fin)
96 break;
97
98 if (str.IsNull())
99 continue;
100
101 if (str.Contains("coma"))
102 continue;
103
104 if (!str.BeginsWith("slot") && !str.BeginsWith("wast"))
105 continue;
106
107 TObjArray *obj = str.Tokenize(' ');
108
109 const TString ld = ((*obj)[3])->GetName();
110 const TString cm = ((*obj)[5])->GetName();
111
112 load += ld.Atof();
113 num++;
114
115 if (cm=="Claimed")
116 {
117 cload += ld.Atof();
118 claim++;
119 }
120
121 delete obj;
122 }
123
124 if (num==0)
125 continue;
126
127 const TString vars = Form("fNumTotal=%d, fNumClaimed=%d, fLoadTotal=%.2f, fLoadClaimed=%.2f",
128 num, claim, load, cload);
129
130 const Int_t res = serv.InsertUpdate("CondorStatus", "fTime", tm.GetSqlDateTime(), vars);
131 rc[res+1]++;
132 if (res==kFALSE)
133 break;
134 }
135
136 if (rc[0]==0 && rc[1]==0 && rc[2]==0)
137 return kTRUE;
138
139 cout << "Dummies: " << rc[0] << endl;
140 cout << "Failed: " << rc[1] << endl;
141 cout << "Success: " << rc[2] << endl;
142 cout << endl;
143
144 // Non failed -> success
145 if (rc[1]==0)
146 return kTRUE;
147
148 // At least one failed -> error
149 if (rc[1]>0)
150 return 2;
151
152 // Must have been dummy mode
153 return -1;
154}
155
156int fillcondor(TString path="/magic/datacenter/autologs/condor", Bool_t dummy=kTRUE)
157{
158 MSQLMagic serv("sql.rc");
159 if (!serv.IsConnected())
160 {
161 cout << "ERROR - Connection to database failed." << endl;
162 return 0;
163 }
164
165 cout << "fillcondor" << endl;
166 cout << "----------" << endl;
167 cout << endl;
168 cout << "Connected to " << serv.GetName() << endl;
169 cout << "Path: " << path << endl;
170 cout << endl;
171
172 serv.SetIsDummy(dummy);
173
174 return Process(serv, path);
175}
176
177int fillcondor(TString path, TString date, Bool_t dummy=kTRUE)
178{
179 if (!path.EndsWith("/"))
180 path += '/';
181
182 date.ReplaceAll("-", "/");
183 path += date;
184
185 return fillcondor(path, dummy);
186}
187
Note: See TracBrowser for help on using the repository browser.