// @(#)alimdc:$Name$:$Id$ // Author: Fons Rademakers 26/11/99 /************************************************************************** * Copyright(c) 1998-2003, ALICE Experiment at CERN, All rights reserved. * * * * Author: The ALICE Off-line Project. * * Contributors are mentioned in the code where appropriate. * * * * Permission to use, copy, modify and distribute this software and its * * documentation strictly for non-commercial purposes is hereby granted * * without fee, provided that the above copyright notice appears in all * * copies and that both the copyright notice and this permission notice * * appear in the supporting documentation. The authors make no claims * * about the suitability of this software for any purpose. It is * * provided "as is" without express or implied warranty. * **************************************************************************/ ////////////////////////////////////////////////////////////////////////// // // // AliRunDB // // // ////////////////////////////////////////////////////////////////////////// #include #include #include #include #include #include #include #include "AliStats.h" #include "AliMDC.h" #include "AliRunDB.h" ClassImp(AliRunDB) //______________________________________________________________________________ AliRunDB::AliRunDB(Bool_t noLocalDB) { // Open run database, and get or create tree. fRunDB = 0; if (noLocalDB) return; // Get hostname char hostname[64], filename[64]; const char *fs = AliMDC::RunDBFS(); // check that fs exists (crude check fails if fs is a file) gSystem->MakeDirectory(fs); strcpy(hostname, gSystem->HostName()); char *s; if ((s = strchr(hostname, '.'))) *s = 0; sprintf(filename, "%s/%s_rundb.root", fs, hostname); if (!gSystem->AccessPathName(filename, kFileExists)) fRunDB = new TFile(filename, "UPDATE"); else fRunDB = new TFile(filename, "CREATE", Form("ALICE MDC%d Run DB", AliMDC::kMDC)); } //______________________________________________________________________________ AliRunDB::AliRunDB(const AliRunDB& runDB): TObject(runDB) { // copy constructor Fatal("AliRunDB", "copy constructor not implemented"); } //______________________________________________________________________________ AliRunDB& AliRunDB::operator = (const AliRunDB& /*runDB*/) { // assignment operator Fatal("operator =", "assignment operator not implemented"); return *this; } //______________________________________________________________________________ void AliRunDB::Update(AliStats *stats) { // Add stats object to database. if (!stats || !fRunDB) return; TDirectory *ds = gDirectory; fRunDB->cd(); char sname[64]; char *s = (char*)strrchr(stats->GetFileName(), '/'); if (s) { s++; strcpy(sname, s); } else strcpy(sname, stats->GetFileName()); s = strchr(sname, '.'); if (s) *s = 0; stats->Write(sname); ds->cd(); } //______________________________________________________________________________ void AliRunDB::UpdateRDBMS(AliStats *stats) { // Add stats object to central MySQL DB. if (!stats) return; char sql[4096]; char bt[25], et[25]; strcpy(bt, stats->GetBeginTime().AsSQLString()); strcpy(et, stats->GetEndTime().AsSQLString()); sprintf(sql, "INSERT INTO mdc%dcatalog VALUES (0, '%s', %d, " "%d, %d, %d, %d, %d, %d, %.2f, '%s', '%s', '%s')", AliMDC::kMDC, stats->GetFileName(), (int)stats->GetFileSize(), stats->GetEvents(), stats->GetFirstRun(), stats->GetFirstEvent(), stats->GetLastRun(), stats->GetLastEvent(), stats->GetCompressionMode(), stats->GetCompressionFactor(), stats->GetFilterState() ? "on" : "off", bt, et); // open connection to MySQL server on pcsalo TSQLServer *db = TSQLServer::Connect("mysql://pcsalo.cern.ch/mdc", "alice", "amdc"); if (!db || db->IsZombie()) { Error("UpdateRDBMS", "failed to connect to MySQL server on pcsalo"); printf("%s\n", sql); delete db; return; } TSQLResult *res = db->Query(sql); if (!res) { Error("UpdateRDBMS", Form("insert into mdc%dcatalog failed", AliMDC::kMDC)); printf("%s\n", sql); } delete res; delete db; } //______________________________________________________________________________ void AliRunDB::UpdateAliEn(AliStats *stats) { // Record file in AliEn catalog. if (!stats) return; TGrid *g = TGrid::Connect(AliMDC::AlienHost(), ""); TString lfn = AliMDC::AlienDir(); TDatime dt; // make a subdirectory for each day lfn += "/adc-"; lfn += dt.GetDate(); // check if directory exists, if not create it Grid_ResultHandle_t res = 0; if (!(res = g->OpenDir(lfn))) { // directory does not exist, create it if (g->Mkdir(lfn) == -1) { Error("UpdateAliEn", "cannot create directory %s", lfn.Data()); lfn = AliMDC::AlienDir(); } } if (res) g->CloseResult(res); lfn += "/"; lfn += gSystem->BaseName(stats->GetFileName()); Int_t result = g->AddFile(lfn, stats->GetFileName(), (int)stats->GetFileSize()); if (result == -1) { Error("UpdateAliEn", "error adding file to AliEn catalog"); printf("AliEn: AddFile(%s, %s, %d)\n", lfn.Data(), stats->GetFileName(), (int)stats->GetFileSize()); } delete g; } //______________________________________________________________________________ void AliRunDB::Close() { // Close run database. if (fRunDB) fRunDB->Close(); delete fRunDB; }