1 // @(#)alimdc:$Name$:$Id$
2 // Author: Fons Rademakers 26/11/99
4 /**************************************************************************
5 * Copyright(c) 1998-2003, ALICE Experiment at CERN, All rights reserved. *
7 * Author: The ALICE Off-line Project. *
8 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
19 //////////////////////////////////////////////////////////////////////////
23 //////////////////////////////////////////////////////////////////////////
29 #include <TSQLServer.h>
30 #include <TSQLResult.h>
42 //______________________________________________________________________________
43 AliRunDB::AliRunDB(const char* localFS, Bool_t rdbms,
44 const char* alienHost, const char* alienDir) :
47 fAlienHost(alienHost),
50 // Open run database, and get or create tree.
55 char hostname[64], filename[64];
57 // check that fs exists (crude check fails if fs is a file)
58 gSystem->MakeDirectory(localFS);
60 // Put wide read-write permissions
61 if(gSystem->Chmod(localFS,1023)) {
62 Error("AliRunDB","can't set permissions for run DB directory");
66 strcpy(hostname, gSystem->HostName());
69 if ((s = strchr(hostname, '.')))
72 sprintf(filename, "%s/%s_rundb.root", localFS, hostname);
74 if (!gSystem->AccessPathName(filename, kFileExists))
75 fRunDB = new TFile(filename, "UPDATE");
77 fRunDB = new TFile(filename, "CREATE", Form("ALICE Run DB (%s)", AliRawDB::GetAliRootTag()));
79 // Put wide read-write permissions
80 if(gSystem->Chmod(filename,438)) {
81 Error("AliRunDB","can't set permissions for run DB file");
86 //______________________________________________________________________________
87 void AliRunDB::Update(AliStats *stats)
94 //______________________________________________________________________________
95 void AliRunDB::UpdateLocal(AliStats *stats)
97 // Add stats object to database.
99 if (!stats || !fRunDB) return;
101 TDirectory *ds = gDirectory;
105 char *s = (char*)strrchr(stats->GetFileName(), '/');
110 strcpy(sname, stats->GetFileName());
111 s = strchr(sname, '.');
119 //______________________________________________________________________________
120 void AliRunDB::UpdateRDBMS(AliStats *stats)
122 // Add stats object to central MySQL DB.
124 if (!stats || !fRDBMS) return;
129 strcpy(bt, stats->GetBeginTime().AsSQLString());
130 strcpy(et, stats->GetEndTime().AsSQLString());
132 sprintf(sql, "INSERT INTO mdccatalog VALUES (0, '%s', %d, "
133 "%d, %d, %d, %d, %d, %d, %.2f, '%s', '%s', '%s')",
134 stats->GetFileName(), (int)stats->GetFileSize(), stats->GetEvents(),
135 stats->GetFirstRun(), stats->GetFirstEvent(), stats->GetLastRun(),
136 stats->GetLastEvent(), stats->GetCompressionMode(),
137 stats->GetCompressionFactor(), stats->GetFilterState() ? "on" : "off",
140 // open connection to MySQL server on pcsalo
141 // TSQLServer *db = TSQLServer::Connect("mysql://pcsalo.cern.ch/mdc", "alice", "amdc");
143 // if (!db || db->IsZombie()) {
144 // Error("UpdateRDBMS", "failed to connect to MySQL server on pcsalo");
145 // printf("%s\n", sql);
150 // TSQLResult *res = db->Query(sql);
153 // Error("UpdateRDBMS", "insert into mdccatalog failed");
154 // printf("%s\n", sql);
161 //______________________________________________________________________________
162 void AliRunDB::UpdateAliEn(AliStats *stats)
164 // Record file in AliEn catalog.
166 if (!stats || fAlienHost.IsNull()) return;
168 TGrid *g = TGrid::Connect(fAlienHost, "");
170 //Protection in case root is compiled without AliEn support
172 Error("UpdateAliEn", "ROOT compiled without AliEn support");
176 TString lfn = fAlienDir;
179 // make a subdirectory for each day
183 // check if directory exists, if not create it
184 #if ROOT_VERSION_CODE < ROOT_VERSION(5,0,0)
185 Grid_ResultHandle_t res = 0;
186 if (!(res = g->OpenDir(lfn))) {
187 // directory does not exist, create it
188 if (g->Mkdir(lfn) == -1) {
189 Error("UpdateAliEn", "cannot create directory %s", lfn.Data());
193 if (res) g->CloseResult(res);
195 Error("UpdateAliEn", "needs to be ported to new TGrid");
199 lfn += gSystem->BaseName(stats->GetFileName());
201 #if ROOT_VERSION_CODE < ROOT_VERSION(5,0,0)
202 Int_t result = g->AddFile(lfn, stats->GetFileName(),
203 (int)stats->GetFileSize());
205 Error("UpdateAliEn", "error adding file to AliEn catalog");
206 printf("AliEn: AddFile(%s, %s, %d)\n", lfn.Data(), stats->GetFileName(),
207 (int)stats->GetFileSize());
210 Error("UpdateAliEn", "needs to be ported to new TGrid");
216 //______________________________________________________________________________
217 void AliRunDB::Close()
219 // Close run database.
221 if (fRunDB) fRunDB->Close();