]> git.uio.no Git - u/mrichter/AliRoot.git/blame - RAW/AliRunDB.cxx
Minor fix in order to reflect the changes in hlt.conf
[u/mrichter/AliRoot.git] / RAW / AliRunDB.cxx
CommitLineData
a197a4ce 1// @(#)alimdc:$Name$:$Id$
2// Author: Fons Rademakers 26/11/99
3
4/**************************************************************************
5 * Copyright(c) 1998-2003, ALICE Experiment at CERN, All rights reserved. *
6 * *
7 * Author: The ALICE Off-line Project. *
8 * Contributors are mentioned in the code where appropriate. *
9 * *
10 * Permission to use, copy, modify and distribute this software and its *
11 * documentation strictly for non-commercial purposes is hereby granted *
12 * without fee, provided that the above copyright notice appears in all *
13 * copies and that both the copyright notice and this permission notice *
14 * appear in the supporting documentation. The authors make no claims *
15 * about the suitability of this software for any purpose. It is *
16 * provided "as is" without express or implied warranty. *
17 **************************************************************************/
18
19//////////////////////////////////////////////////////////////////////////
20// //
21// AliRunDB //
22// //
23//////////////////////////////////////////////////////////////////////////
24
25#include <TSystem.h>
26#include <TFile.h>
27#include <TString.h>
28#include <TDatime.h>
29#include <TSQLServer.h>
30#include <TSQLResult.h>
31#include <TGrid.h>
32
33#include "AliStats.h"
34#include "AliMDC.h"
35
36#include "AliRunDB.h"
37
38
39ClassImp(AliRunDB)
40
41
42//______________________________________________________________________________
43AliRunDB::AliRunDB(Bool_t noLocalDB)
44{
45 // Open run database, and get or create tree.
46
47 fRunDB = 0;
48
49 if (noLocalDB) return;
50
51 // Get hostname
52 char hostname[64], filename[64];
53 const char *fs = AliMDC::RunDBFS();
54
55 // check that fs exists (crude check fails if fs is a file)
56 gSystem->MakeDirectory(fs);
57
58 strcpy(hostname, gSystem->HostName());
59
60 char *s;
61 if ((s = strchr(hostname, '.')))
62 *s = 0;
63
64 sprintf(filename, "%s/%s_rundb.root", fs, hostname);
65
66 if (!gSystem->AccessPathName(filename, kFileExists))
67 fRunDB = new TFile(filename, "UPDATE");
68 else
69 fRunDB = new TFile(filename, "CREATE", Form("ALICE MDC%d Run DB", AliMDC::kMDC));
70}
71
72//______________________________________________________________________________
73AliRunDB::AliRunDB(const AliRunDB& runDB): TObject(runDB)
74{
75// copy constructor
76
77 Fatal("AliRunDB", "copy constructor not implemented");
78}
79
80//______________________________________________________________________________
81AliRunDB& AliRunDB::operator = (const AliRunDB& /*runDB*/)
82{
83// assignment operator
84
85 Fatal("operator =", "assignment operator not implemented");
86 return *this;
87}
88
89//______________________________________________________________________________
90void AliRunDB::Update(AliStats *stats)
91{
92 // Add stats object to database.
93
94 if (!stats || !fRunDB) return;
95
96 TDirectory *ds = gDirectory;
97 fRunDB->cd();
98
99 char sname[64];
100 char *s = (char*)strrchr(stats->GetFileName(), '/');
101 if (s) {
102 s++;
103 strcpy(sname, s);
104 } else
105 strcpy(sname, stats->GetFileName());
106 s = strchr(sname, '.');
107 if (s) *s = 0;
108
109 stats->Write(sname);
110
111 ds->cd();
112}
113
114//______________________________________________________________________________
115void AliRunDB::UpdateRDBMS(AliStats *stats)
116{
117 // Add stats object to central MySQL DB.
118
119 if (!stats) return;
120
121 char sql[4096];
122 char bt[25], et[25];
123
124 strcpy(bt, stats->GetBeginTime().AsSQLString());
125 strcpy(et, stats->GetEndTime().AsSQLString());
126
127 sprintf(sql, "INSERT INTO mdc%dcatalog VALUES (0, '%s', %d, "
128 "%d, %d, %d, %d, %d, %d, %.2f, '%s', '%s', '%s')", AliMDC::kMDC,
129 stats->GetFileName(), (int)stats->GetFileSize(), stats->GetEvents(),
130 stats->GetFirstRun(), stats->GetFirstEvent(), stats->GetLastRun(),
131 stats->GetLastEvent(), stats->GetCompressionMode(),
132 stats->GetCompressionFactor(), stats->GetFilterState() ? "on" : "off",
133 bt, et);
134
135 // open connection to MySQL server on pcsalo
136 TSQLServer *db = TSQLServer::Connect("mysql://pcsalo.cern.ch/mdc", "alice", "amdc");
137
138 if (!db || db->IsZombie()) {
139 Error("UpdateRDBMS", "failed to connect to MySQL server on pcsalo");
140 printf("%s\n", sql);
141 delete db;
142 return;
143 }
144
145 TSQLResult *res = db->Query(sql);
146
147 if (!res) {
148 Error("UpdateRDBMS", Form("insert into mdc%dcatalog failed", AliMDC::kMDC));
149 printf("%s\n", sql);
150 }
151
152 delete res;
153 delete db;
154}
155
156//______________________________________________________________________________
157void AliRunDB::UpdateAliEn(AliStats *stats)
158{
159 // Record file in AliEn catalog.
160
161 if (!stats) return;
162
163 TGrid *g = TGrid::Connect(AliMDC::AlienHost(), "");
164
165 TString lfn = AliMDC::AlienDir();
166 TDatime dt;
167
168 // make a subdirectory for each day
169 lfn += "/adc-";
170 lfn += dt.GetDate();
171
172 // check if directory exists, if not create it
173 Grid_ResultHandle_t res = 0;
174 if (!(res = g->OpenDir(lfn))) {
175 // directory does not exist, create it
176 if (g->Mkdir(lfn) == -1) {
177 Error("UpdateAliEn", "cannot create directory %s", lfn.Data());
178 lfn = AliMDC::AlienDir();
179 }
180 }
181 if (res) g->CloseResult(res);
182
183 lfn += "/";
184 lfn += gSystem->BaseName(stats->GetFileName());
185
186 Int_t result = g->AddFile(lfn, stats->GetFileName(),
187 (int)stats->GetFileSize());
188
189 if (result == -1) {
190 Error("UpdateAliEn", "error adding file to AliEn catalog");
191 printf("AliEn: AddFile(%s, %s, %d)\n", lfn.Data(), stats->GetFileName(),
192 (int)stats->GetFileSize());
193 }
194
195 delete g;
196}
197
198//______________________________________________________________________________
199void AliRunDB::Close()
200{
201 // Close run database.
202
203 if (fRunDB) fRunDB->Close();
204 delete fRunDB;
205}