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 strcpy(hostname, gSystem->HostName());
63 if ((s = strchr(hostname, '.')))
66 sprintf(filename, "%s/%s_rundb.root", localFS, hostname);
68 if (!gSystem->AccessPathName(filename, kFileExists))
69 fRunDB = new TFile(filename, "UPDATE");
71 fRunDB = new TFile(filename, "CREATE", Form("ALICE MDC%d Run DB", AliRawDB::kMDC));
74 //______________________________________________________________________________
75 AliRunDB::AliRunDB(const AliRunDB& runDB): TObject(runDB)
79 Fatal("AliRunDB", "copy constructor not implemented");
82 //______________________________________________________________________________
83 AliRunDB& AliRunDB::operator = (const AliRunDB& /*runDB*/)
85 // assignment operator
87 Fatal("operator =", "assignment operator not implemented");
91 //______________________________________________________________________________
92 void AliRunDB::Update(AliStats *stats)
99 //______________________________________________________________________________
100 void AliRunDB::UpdateLocal(AliStats *stats)
102 // Add stats object to database.
104 if (!stats || !fRunDB) return;
106 TDirectory *ds = gDirectory;
110 char *s = (char*)strrchr(stats->GetFileName(), '/');
115 strcpy(sname, stats->GetFileName());
116 s = strchr(sname, '.');
124 //______________________________________________________________________________
125 void AliRunDB::UpdateRDBMS(AliStats *stats)
127 // Add stats object to central MySQL DB.
129 if (!stats || !fRDBMS) return;
134 strcpy(bt, stats->GetBeginTime().AsSQLString());
135 strcpy(et, stats->GetEndTime().AsSQLString());
137 sprintf(sql, "INSERT INTO mdc%dcatalog VALUES (0, '%s', %d, "
138 "%d, %d, %d, %d, %d, %d, %.2f, '%s', '%s', '%s')", AliRawDB::kMDC,
139 stats->GetFileName(), (int)stats->GetFileSize(), stats->GetEvents(),
140 stats->GetFirstRun(), stats->GetFirstEvent(), stats->GetLastRun(),
141 stats->GetLastEvent(), stats->GetCompressionMode(),
142 stats->GetCompressionFactor(), stats->GetFilterState() ? "on" : "off",
145 // open connection to MySQL server on pcsalo
146 TSQLServer *db = TSQLServer::Connect("mysql://pcsalo.cern.ch/mdc", "alice", "amdc");
148 if (!db || db->IsZombie()) {
149 Error("UpdateRDBMS", "failed to connect to MySQL server on pcsalo");
155 TSQLResult *res = db->Query(sql);
158 Error("UpdateRDBMS", Form("insert into mdc%dcatalog failed", AliRawDB::kMDC));
166 //______________________________________________________________________________
167 void AliRunDB::UpdateAliEn(AliStats *stats)
169 // Record file in AliEn catalog.
171 if (!stats || fAlienHost.IsNull()) return;
173 TGrid *g = TGrid::Connect(fAlienHost, "");
175 TString lfn = fAlienDir;
178 // make a subdirectory for each day
182 // check if directory exists, if not create it
183 Grid_ResultHandle_t res = 0;
184 if (!(res = g->OpenDir(lfn))) {
185 // directory does not exist, create it
186 if (g->Mkdir(lfn) == -1) {
187 Error("UpdateAliEn", "cannot create directory %s", lfn.Data());
191 if (res) g->CloseResult(res);
194 lfn += gSystem->BaseName(stats->GetFileName());
196 Int_t result = g->AddFile(lfn, stats->GetFileName(),
197 (int)stats->GetFileSize());
200 Error("UpdateAliEn", "error adding file to AliEn catalog");
201 printf("AliEn: AddFile(%s, %s, %d)\n", lfn.Data(), stats->GetFileName(),
202 (int)stats->GetFileSize());
208 //______________________________________________________________________________
209 void AliRunDB::Close()
211 // Close run database.
213 if (fRunDB) fRunDB->Close();