]>
Commit | Line | Data |
---|---|---|
a197a4ce | 1 | // @(#)alimdc:$Name$:$Id$ |
2 | // Author: Fons Rademakers 26/11/99 | |
3 | ||
4 | /************************************************************************** | |
5 | * Copyright(c) 1998-2003, ALICE Experiment at CERN, All rights reserved. * | |
6 | * * | |
7 | * Author: The ALICE Off-line Project. * | |
8 | * Contributors are mentioned in the code where appropriate. * | |
9 | * * | |
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 | **************************************************************************/ | |
18 | ||
19 | ////////////////////////////////////////////////////////////////////////// | |
20 | // // | |
21 | // AliRunDB // | |
22 | // // | |
23 | ////////////////////////////////////////////////////////////////////////// | |
24 | ||
25 | #include <TSystem.h> | |
26 | #include <TFile.h> | |
27 | #include <TString.h> | |
28 | #include <TDatime.h> | |
29 | #include <TSQLServer.h> | |
30 | #include <TSQLResult.h> | |
31 | #include <TGrid.h> | |
32 | ||
33 | #include "AliStats.h" | |
e10815f1 | 34 | #include "AliRawDB.h" |
a197a4ce | 35 | |
36 | #include "AliRunDB.h" | |
37 | ||
38 | ||
39 | ClassImp(AliRunDB) | |
40 | ||
41 | ||
42 | //______________________________________________________________________________ | |
43073eba | 43 | AliRunDB::AliRunDB(const char* localFS, Bool_t rdbms, |
e10815f1 | 44 | const char* alienHost, const char* alienDir) : |
45 | fRunDB(NULL), | |
46 | fRDBMS(rdbms), | |
47 | fAlienHost(alienHost), | |
48 | fAlienDir(alienDir) | |
a197a4ce | 49 | { |
50 | // Open run database, and get or create tree. | |
51 | ||
e10815f1 | 52 | if (!localFS) return; |
a197a4ce | 53 | |
54 | // Get hostname | |
55 | char hostname[64], filename[64]; | |
a197a4ce | 56 | |
57 | // check that fs exists (crude check fails if fs is a file) | |
e10815f1 | 58 | gSystem->MakeDirectory(localFS); |
a197a4ce | 59 | |
f07ec911 | 60 | // Put wide read-write permissions |
61 | if(gSystem->Chmod(localFS,1023)) { | |
62 | Error("AliRunDB","can't set permissions for run DB directory"); | |
63 | return; | |
64 | } | |
65 | ||
a197a4ce | 66 | strcpy(hostname, gSystem->HostName()); |
67 | ||
68 | char *s; | |
69 | if ((s = strchr(hostname, '.'))) | |
70 | *s = 0; | |
71 | ||
e10815f1 | 72 | sprintf(filename, "%s/%s_rundb.root", localFS, hostname); |
a197a4ce | 73 | |
74 | if (!gSystem->AccessPathName(filename, kFileExists)) | |
75 | fRunDB = new TFile(filename, "UPDATE"); | |
76 | else | |
e10815f1 | 77 | fRunDB = new TFile(filename, "CREATE", Form("ALICE MDC%d Run DB", AliRawDB::kMDC)); |
f07ec911 | 78 | |
79 | // Put wide read-write permissions | |
80 | if(gSystem->Chmod(filename,438)) { | |
81 | Error("AliRunDB","can't set permissions for run DB file"); | |
82 | return; | |
83 | } | |
a197a4ce | 84 | } |
85 | ||
86 | //______________________________________________________________________________ | |
87 | AliRunDB::AliRunDB(const AliRunDB& runDB): TObject(runDB) | |
88 | { | |
89 | // copy constructor | |
90 | ||
91 | Fatal("AliRunDB", "copy constructor not implemented"); | |
92 | } | |
93 | ||
94 | //______________________________________________________________________________ | |
95 | AliRunDB& AliRunDB::operator = (const AliRunDB& /*runDB*/) | |
96 | { | |
97 | // assignment operator | |
98 | ||
99 | Fatal("operator =", "assignment operator not implemented"); | |
100 | return *this; | |
101 | } | |
102 | ||
103 | //______________________________________________________________________________ | |
104 | void AliRunDB::Update(AliStats *stats) | |
e10815f1 | 105 | { |
106 | UpdateLocal(stats); | |
107 | UpdateRDBMS(stats); | |
108 | UpdateAliEn(stats); | |
109 | } | |
110 | ||
111 | //______________________________________________________________________________ | |
112 | void AliRunDB::UpdateLocal(AliStats *stats) | |
a197a4ce | 113 | { |
114 | // Add stats object to database. | |
115 | ||
116 | if (!stats || !fRunDB) return; | |
117 | ||
118 | TDirectory *ds = gDirectory; | |
119 | fRunDB->cd(); | |
120 | ||
121 | char sname[64]; | |
122 | char *s = (char*)strrchr(stats->GetFileName(), '/'); | |
123 | if (s) { | |
124 | s++; | |
125 | strcpy(sname, s); | |
126 | } else | |
127 | strcpy(sname, stats->GetFileName()); | |
128 | s = strchr(sname, '.'); | |
129 | if (s) *s = 0; | |
130 | ||
131 | stats->Write(sname); | |
132 | ||
133 | ds->cd(); | |
134 | } | |
135 | ||
136 | //______________________________________________________________________________ | |
137 | void AliRunDB::UpdateRDBMS(AliStats *stats) | |
138 | { | |
139 | // Add stats object to central MySQL DB. | |
140 | ||
e10815f1 | 141 | if (!stats || !fRDBMS) return; |
a197a4ce | 142 | |
143 | char sql[4096]; | |
144 | char bt[25], et[25]; | |
145 | ||
146 | strcpy(bt, stats->GetBeginTime().AsSQLString()); | |
147 | strcpy(et, stats->GetEndTime().AsSQLString()); | |
148 | ||
149 | sprintf(sql, "INSERT INTO mdc%dcatalog VALUES (0, '%s', %d, " | |
e10815f1 | 150 | "%d, %d, %d, %d, %d, %d, %.2f, '%s', '%s', '%s')", AliRawDB::kMDC, |
a197a4ce | 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", | |
155 | bt, et); | |
156 | ||
157 | // open connection to MySQL server on pcsalo | |
a2f3d533 | 158 | // TSQLServer *db = TSQLServer::Connect("mysql://pcsalo.cern.ch/mdc", "alice", "amdc"); |
a197a4ce | 159 | |
a2f3d533 | 160 | // if (!db || db->IsZombie()) { |
161 | // Error("UpdateRDBMS", "failed to connect to MySQL server on pcsalo"); | |
162 | // printf("%s\n", sql); | |
163 | // delete db; | |
164 | // return; | |
165 | // } | |
a197a4ce | 166 | |
a2f3d533 | 167 | // TSQLResult *res = db->Query(sql); |
a197a4ce | 168 | |
a2f3d533 | 169 | // if (!res) { |
170 | // Error("UpdateRDBMS", Form("insert into mdc%dcatalog failed", AliRawDB::kMDC)); | |
171 | // printf("%s\n", sql); | |
172 | // } | |
a197a4ce | 173 | |
a2f3d533 | 174 | // delete res; |
175 | // delete db; | |
a197a4ce | 176 | } |
177 | ||
178 | //______________________________________________________________________________ | |
179 | void AliRunDB::UpdateAliEn(AliStats *stats) | |
180 | { | |
181 | // Record file in AliEn catalog. | |
182 | ||
e10815f1 | 183 | if (!stats || fAlienHost.IsNull()) return; |
a197a4ce | 184 | |
e10815f1 | 185 | TGrid *g = TGrid::Connect(fAlienHost, ""); |
a197a4ce | 186 | |
424d21e8 | 187 | //Protection in case root is compiled without AliEn support |
188 | if(!g) { | |
189 | Error("UpdateAliEn", "ROOT compiled without AliEn support"); | |
190 | return; | |
191 | } | |
192 | ||
e10815f1 | 193 | TString lfn = fAlienDir; |
a197a4ce | 194 | TDatime dt; |
195 | ||
196 | // make a subdirectory for each day | |
197 | lfn += "/adc-"; | |
198 | lfn += dt.GetDate(); | |
199 | ||
200 | // check if directory exists, if not create it | |
43073eba | 201 | #if ROOT_VERSION_CODE < ROOT_VERSION(5,0,0) |
a197a4ce | 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()); | |
e10815f1 | 207 | lfn = fAlienDir; |
a197a4ce | 208 | } |
209 | } | |
210 | if (res) g->CloseResult(res); | |
43073eba | 211 | #else |
212 | Error("UpdateAliEn", "needs to be ported to new TGrid"); | |
213 | #endif | |
a197a4ce | 214 | |
215 | lfn += "/"; | |
216 | lfn += gSystem->BaseName(stats->GetFileName()); | |
217 | ||
43073eba | 218 | #if ROOT_VERSION_CODE < ROOT_VERSION(5,0,0) |
a197a4ce | 219 | Int_t result = g->AddFile(lfn, stats->GetFileName(), |
220 | (int)stats->GetFileSize()); | |
a197a4ce | 221 | if (result == -1) { |
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()); | |
225 | } | |
43073eba | 226 | #else |
227 | Error("UpdateAliEn", "needs to be ported to new TGrid"); | |
228 | #endif | |
a197a4ce | 229 | |
230 | delete g; | |
231 | } | |
232 | ||
233 | //______________________________________________________________________________ | |
234 | void AliRunDB::Close() | |
235 | { | |
236 | // Close run database. | |
237 | ||
238 | if (fRunDB) fRunDB->Close(); | |
239 | delete fRunDB; | |
240 | } | |
b7d09bb3 | 241 |