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(Bool_t noLocalDB)
45 // Open run database, and get or create tree.
49 if (noLocalDB) return;
52 char hostname[64], filename[64];
53 const char *fs = AliMDC::RunDBFS();
55 // check that fs exists (crude check fails if fs is a file)
56 gSystem->MakeDirectory(fs);
58 strcpy(hostname, gSystem->HostName());
61 if ((s = strchr(hostname, '.')))
64 sprintf(filename, "%s/%s_rundb.root", fs, hostname);
66 if (!gSystem->AccessPathName(filename, kFileExists))
67 fRunDB = new TFile(filename, "UPDATE");
69 fRunDB = new TFile(filename, "CREATE", Form("ALICE MDC%d Run DB", AliMDC::kMDC));
72 //______________________________________________________________________________
73 AliRunDB::AliRunDB(const AliRunDB& runDB): TObject(runDB)
77 Fatal("AliRunDB", "copy constructor not implemented");
80 //______________________________________________________________________________
81 AliRunDB& AliRunDB::operator = (const AliRunDB& /*runDB*/)
83 // assignment operator
85 Fatal("operator =", "assignment operator not implemented");
89 //______________________________________________________________________________
90 void AliRunDB::Update(AliStats *stats)
92 // Add stats object to database.
94 if (!stats || !fRunDB) return;
96 TDirectory *ds = gDirectory;
100 char *s = (char*)strrchr(stats->GetFileName(), '/');
105 strcpy(sname, stats->GetFileName());
106 s = strchr(sname, '.');
114 //______________________________________________________________________________
115 void AliRunDB::UpdateRDBMS(AliStats *stats)
117 // Add stats object to central MySQL DB.
124 strcpy(bt, stats->GetBeginTime().AsSQLString());
125 strcpy(et, stats->GetEndTime().AsSQLString());
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",
135 // open connection to MySQL server on pcsalo
136 TSQLServer *db = TSQLServer::Connect("mysql://pcsalo.cern.ch/mdc", "alice", "amdc");
138 if (!db || db->IsZombie()) {
139 Error("UpdateRDBMS", "failed to connect to MySQL server on pcsalo");
145 TSQLResult *res = db->Query(sql);
148 Error("UpdateRDBMS", Form("insert into mdc%dcatalog failed", AliMDC::kMDC));
156 //______________________________________________________________________________
157 void AliRunDB::UpdateAliEn(AliStats *stats)
159 // Record file in AliEn catalog.
163 TGrid *g = TGrid::Connect(AliMDC::AlienHost(), "");
165 TString lfn = AliMDC::AlienDir();
168 // make a subdirectory for each day
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();
181 if (res) g->CloseResult(res);
184 lfn += gSystem->BaseName(stats->GetFileName());
186 Int_t result = g->AddFile(lfn, stats->GetFileName(),
187 (int)stats->GetFileSize());
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());
198 //______________________________________________________________________________
199 void AliRunDB::Close()
201 // Close run database.
203 if (fRunDB) fRunDB->Close();