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 MDC%d Run DB", AliRawDB::kMDC));
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 AliRunDB::AliRunDB(const AliRunDB& runDB): TObject(runDB)
91 Fatal("AliRunDB", "copy constructor not implemented");
94 //______________________________________________________________________________
95 AliRunDB& AliRunDB::operator = (const AliRunDB& /*runDB*/)
97 // assignment operator
99 Fatal("operator =", "assignment operator not implemented");
103 //______________________________________________________________________________
104 void AliRunDB::Update(AliStats *stats)
111 //______________________________________________________________________________
112 void AliRunDB::UpdateLocal(AliStats *stats)
114 // Add stats object to database.
116 if (!stats || !fRunDB) return;
118 TDirectory *ds = gDirectory;
122 char *s = (char*)strrchr(stats->GetFileName(), '/');
127 strcpy(sname, stats->GetFileName());
128 s = strchr(sname, '.');
136 //______________________________________________________________________________
137 void AliRunDB::UpdateRDBMS(AliStats *stats)
139 // Add stats object to central MySQL DB.
141 if (!stats || !fRDBMS) return;
146 strcpy(bt, stats->GetBeginTime().AsSQLString());
147 strcpy(et, stats->GetEndTime().AsSQLString());
149 sprintf(sql, "INSERT INTO mdc%dcatalog VALUES (0, '%s', %d, "
150 "%d, %d, %d, %d, %d, %d, %.2f, '%s', '%s', '%s')", AliRawDB::kMDC,
151 stats->GetFileName(), (int)stats->GetFileSize(), stats->GetEvents(),
152 stats->GetFirstRun(), stats->GetFirstEvent(), stats->GetLastRun(),
153 stats->GetLastEvent(), stats->GetCompressionMode(),
154 stats->GetCompressionFactor(), stats->GetFilterState() ? "on" : "off",
157 // open connection to MySQL server on pcsalo
158 // TSQLServer *db = TSQLServer::Connect("mysql://pcsalo.cern.ch/mdc", "alice", "amdc");
160 // if (!db || db->IsZombie()) {
161 // Error("UpdateRDBMS", "failed to connect to MySQL server on pcsalo");
162 // printf("%s\n", sql);
167 // TSQLResult *res = db->Query(sql);
170 // Error("UpdateRDBMS", Form("insert into mdc%dcatalog failed", AliRawDB::kMDC));
171 // printf("%s\n", sql);
178 //______________________________________________________________________________
179 void AliRunDB::UpdateAliEn(AliStats *stats)
181 // Record file in AliEn catalog.
183 if (!stats || fAlienHost.IsNull()) return;
185 TGrid *g = TGrid::Connect(fAlienHost, "");
187 //Protection in case root is compiled without AliEn support
189 Error("UpdateAliEn", "ROOT compiled without AliEn support");
193 TString lfn = fAlienDir;
196 // make a subdirectory for each day
200 // check if directory exists, if not create it
201 #if ROOT_VERSION_CODE < ROOT_VERSION(5,0,0)
202 Grid_ResultHandle_t res = 0;
203 if (!(res = g->OpenDir(lfn))) {
204 // directory does not exist, create it
205 if (g->Mkdir(lfn) == -1) {
206 Error("UpdateAliEn", "cannot create directory %s", lfn.Data());
210 if (res) g->CloseResult(res);
212 Error("UpdateAliEn", "needs to be ported to new TGrid");
216 lfn += gSystem->BaseName(stats->GetFileName());
218 #if ROOT_VERSION_CODE < ROOT_VERSION(5,0,0)
219 Int_t result = g->AddFile(lfn, stats->GetFileName(),
220 (int)stats->GetFileSize());
222 Error("UpdateAliEn", "error adding file to AliEn catalog");
223 printf("AliEn: AddFile(%s, %s, %d)\n", lfn.Data(), stats->GetFileName(),
224 (int)stats->GetFileSize());
227 Error("UpdateAliEn", "needs to be ported to new TGrid");
233 //______________________________________________________________________________
234 void AliRunDB::Close()
236 // Close run database.
238 if (fRunDB) fRunDB->Close();