]>
Commit | Line | Data |
---|---|---|
73abe331 | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
7 | * Permission to use, copy, modify and distribute this software and its * | |
8 | * documentation strictly for non-commercial purposes is hereby granted * | |
9 | * without fee, provided that the above copyright notice appears in all * | |
10 | * copies and that both the copyright notice and this permission notice * | |
11 | * appear in the supporting documentation. The authors make no claims * | |
12 | * about the suitability of this software for any purpose. It is * | |
13 | * provided "as is" without express or implied warranty. * | |
14 | **************************************************************************/ | |
15 | ||
ff3781ad | 16 | /* $Id$ */ |
73abe331 | 17 | |
18 | // | |
19 | // This class is the main manager for AliShuttle. | |
20 | // It organizes the data retrieval from DCS and call the | |
b948db8d | 21 | // interface methods of AliPreprocessor. |
73abe331 | 22 | // For every detector in AliShuttleConfgi (see AliShuttleConfig), |
23 | // data for its set of aliases is retrieved. If there is registered | |
b948db8d | 24 | // AliPreprocessor for this detector then it will be used |
25 | // accroding to the schema (see AliPreprocessor). | |
26 | // If there isn't registered AliPreprocessor than the retrieved | |
73abe331 | 27 | // data is stored automatically to the undelying AliCDBStorage. |
28 | // For detSpec is used the alias name. | |
29 | // | |
30 | ||
31 | #include "AliShuttle.h" | |
32 | ||
33 | #include "AliCDBManager.h" | |
34 | #include "AliCDBStorage.h" | |
35 | #include "AliCDBId.h" | |
84090f85 | 36 | #include "AliCDBRunRange.h" |
37 | #include "AliCDBPath.h" | |
5164a766 | 38 | #include "AliCDBEntry.h" |
73abe331 | 39 | #include "AliShuttleConfig.h" |
eba76848 | 40 | #include "DCSClient/AliDCSClient.h" |
73abe331 | 41 | #include "AliLog.h" |
b948db8d | 42 | #include "AliPreprocessor.h" |
5164a766 | 43 | #include "AliShuttleStatus.h" |
2bb7b766 | 44 | #include "AliShuttleLogbookEntry.h" |
73abe331 | 45 | |
57f50b3c | 46 | #include <TSystem.h> |
58bc3020 | 47 | #include <TObject.h> |
b948db8d | 48 | #include <TString.h> |
57f50b3c | 49 | #include <TTimeStamp.h> |
73abe331 | 50 | #include <TObjString.h> |
57f50b3c | 51 | #include <TSQLServer.h> |
52 | #include <TSQLResult.h> | |
53 | #include <TSQLRow.h> | |
cb343cfd | 54 | #include <TMutex.h> |
9827400b | 55 | #include <TSystemDirectory.h> |
56 | #include <TSystemFile.h> | |
a986b218 | 57 | #include <TFile.h> |
9827400b | 58 | #include <TGrid.h> |
59 | #include <TGridResult.h> | |
73abe331 | 60 | |
e7f62f16 | 61 | #include <TMonaLisaWriter.h> |
62 | ||
5164a766 | 63 | #include <fstream> |
64 | ||
cb343cfd | 65 | #include <sys/types.h> |
66 | #include <sys/wait.h> | |
67 | ||
1bd183ba | 68 | #include <signal.h> |
69 | ||
73abe331 | 70 | ClassImp(AliShuttle) |
71 | ||
b948db8d | 72 | //______________________________________________________________________________________________ |
73 | AliShuttle::AliShuttle(const AliShuttleConfig* config, | |
74 | UInt_t timeout, Int_t retries): | |
4f0ab988 | 75 | fConfig(config), |
76 | fTimeout(timeout), fRetries(retries), | |
77 | fPreprocessorMap(), | |
2bb7b766 | 78 | fLogbookEntry(0), |
eba76848 | 79 | fCurrentDetector(), |
926cbc0e | 80 | fFirstProcessing(0), |
339adafa | 81 | fFXSError(-1), |
85a80aa9 | 82 | fStatusEntry(0), |
cb343cfd | 83 | fMonitoringMutex(0), |
eba76848 | 84 | fLastActionTime(0), |
e7f62f16 | 85 | fLastAction(), |
9827400b | 86 | fMonaLisa(0), |
87 | fTestMode(kNone), | |
ffa29e93 | 88 | fReadTestMode(kFALSE), |
89 | fOutputRedirected(kFALSE) | |
73abe331 | 90 | { |
91 | // | |
92 | // config: AliShuttleConfig used | |
73abe331 | 93 | // timeout: timeout used for AliDCSClient connection |
94 | // retries: the number of retries in case of connection error. | |
95 | // | |
96 | ||
57f50b3c | 97 | if (!fConfig->IsValid()) AliFatal("********** !!!!! Invalid configuration !!!!! **********"); |
be48e3ea | 98 | for(int iSys=0;iSys<4;iSys++) { |
57f50b3c | 99 | fServer[iSys]=0; |
be48e3ea | 100 | if (iSys < 3) |
2c15234c | 101 | fFXSlist[iSys].SetOwner(kTRUE); |
57f50b3c | 102 | } |
2bb7b766 | 103 | fPreprocessorMap.SetOwner(kTRUE); |
be48e3ea | 104 | |
105 | for (UInt_t iDet=0; iDet<NDetectors(); iDet++) | |
106 | fFirstUnprocessed[iDet] = kFALSE; | |
107 | ||
cb343cfd | 108 | fMonitoringMutex = new TMutex(); |
58bc3020 | 109 | } |
110 | ||
b948db8d | 111 | //______________________________________________________________________________________________ |
57f50b3c | 112 | AliShuttle::~AliShuttle() |
58bc3020 | 113 | { |
9827400b | 114 | // |
115 | // destructor | |
116 | // | |
58bc3020 | 117 | |
b948db8d | 118 | fPreprocessorMap.DeleteAll(); |
be48e3ea | 119 | for(int iSys=0;iSys<4;iSys++) |
57f50b3c | 120 | if(fServer[iSys]) { |
121 | fServer[iSys]->Close(); | |
122 | delete fServer[iSys]; | |
eba76848 | 123 | fServer[iSys] = 0; |
57f50b3c | 124 | } |
2bb7b766 | 125 | |
126 | if (fStatusEntry){ | |
127 | delete fStatusEntry; | |
128 | fStatusEntry = 0; | |
129 | } | |
cb343cfd | 130 | |
131 | if (fMonitoringMutex) | |
132 | { | |
133 | delete fMonitoringMutex; | |
134 | fMonitoringMutex = 0; | |
135 | } | |
73abe331 | 136 | } |
137 | ||
b948db8d | 138 | //______________________________________________________________________________________________ |
57f50b3c | 139 | void AliShuttle::RegisterPreprocessor(AliPreprocessor* preprocessor) |
58bc3020 | 140 | { |
73abe331 | 141 | // |
b948db8d | 142 | // Registers new AliPreprocessor. |
73abe331 | 143 | // It uses GetName() for indentificator of the pre processor. |
144 | // The pre processor is registered it there isn't any other | |
145 | // with the same identificator (GetName()). | |
146 | // | |
147 | ||
eba76848 | 148 | const char* detName = preprocessor->GetName(); |
149 | if(GetDetPos(detName) < 0) | |
150 | AliFatal(Form("********** !!!!! Invalid detector name: %s !!!!! **********", detName)); | |
151 | ||
152 | if (fPreprocessorMap.GetValue(detName)) { | |
153 | AliWarning(Form("AliPreprocessor %s is already registered!", detName)); | |
73abe331 | 154 | return; |
155 | } | |
156 | ||
eba76848 | 157 | fPreprocessorMap.Add(new TObjString(detName), preprocessor); |
73abe331 | 158 | } |
b948db8d | 159 | //______________________________________________________________________________________________ |
3301427a | 160 | Bool_t AliShuttle::Store(const AliCDBPath& path, TObject* object, |
84090f85 | 161 | AliCDBMetaData* metaData, Int_t validityStart, Bool_t validityInfinite) |
73abe331 | 162 | { |
9827400b | 163 | // Stores a CDB object in the storage for offline reconstruction. Objects that are not needed for |
164 | // offline reconstruction, but should be stored anyway (e.g. for debugging) should NOT be stored | |
165 | // using this function. Use StoreReferenceData instead! | |
166 | // It calls StoreLocally function which temporarily stores the data locally; when the preprocessor | |
167 | // finishes the data are transferred to the main storage (Grid). | |
b948db8d | 168 | |
3301427a | 169 | return StoreLocally(fgkLocalCDB, path, object, metaData, validityStart, validityInfinite); |
84090f85 | 170 | } |
171 | ||
172 | //______________________________________________________________________________________________ | |
3301427a | 173 | Bool_t AliShuttle::StoreReferenceData(const AliCDBPath& path, TObject* object, AliCDBMetaData* metaData) |
84090f85 | 174 | { |
9827400b | 175 | // Stores a CDB object in the storage for reference data. This objects will not be available during |
176 | // offline reconstrunction. Use this function for reference data only! | |
177 | // It calls StoreLocally function which temporarily stores the data locally; when the preprocessor | |
178 | // finishes the data are transferred to the main storage (Grid). | |
85a80aa9 | 179 | |
3301427a | 180 | return StoreLocally(fgkLocalRefStorage, path, object, metaData); |
85a80aa9 | 181 | } |
182 | ||
183 | //______________________________________________________________________________________________ | |
3301427a | 184 | Bool_t AliShuttle::StoreLocally(const TString& localUri, |
85a80aa9 | 185 | const AliCDBPath& path, TObject* object, AliCDBMetaData* metaData, |
186 | Int_t validityStart, Bool_t validityInfinite) | |
187 | { | |
9827400b | 188 | // Store object temporarily in local storage. Parameters are passed by Store and StoreReferenceData functions. |
189 | // when the preprocessor finishes the data are transferred to the main storage (Grid). | |
190 | // The parameters are: | |
191 | // 1) Uri of the backup storage (Local) | |
192 | // 2) the object's path. | |
193 | // 3) the object to be stored | |
194 | // 4) the metaData to be associated with the object | |
195 | // 5) the validity start run number w.r.t. the current run, | |
196 | // if the data is valid only for this run leave the default 0 | |
197 | // 6) specifies if the calibration data is valid for infinity (this means until updated), | |
198 | // typical for calibration runs, the default is kFALSE | |
199 | // | |
200 | // returns 0 if fail, 1 otherwise | |
84090f85 | 201 | |
9827400b | 202 | if (fTestMode & kErrorStorage) |
203 | { | |
204 | Log(fCurrentDetector, "StoreLocally - In TESTMODE - Simulating error while storing locally"); | |
205 | return kFALSE; | |
206 | } | |
207 | ||
3301427a | 208 | const char* cdbType = (localUri == fgkLocalCDB) ? "CDB" : "Reference"; |
2bb7b766 | 209 | |
85a80aa9 | 210 | Int_t firstRun = GetCurrentRun() - validityStart; |
84090f85 | 211 | if(firstRun < 0) { |
9827400b | 212 | AliWarning("First valid run happens to be less than 0! Setting it to 0."); |
84090f85 | 213 | firstRun=0; |
214 | } | |
215 | ||
216 | Int_t lastRun = -1; | |
217 | if(validityInfinite) { | |
218 | lastRun = AliCDBRunRange::Infinity(); | |
219 | } else { | |
220 | lastRun = GetCurrentRun(); | |
221 | } | |
222 | ||
3301427a | 223 | // Version is set to current run, it will be used later to transfer data to Grid |
224 | AliCDBId id(path, firstRun, lastRun, GetCurrentRun(), -1); | |
2bb7b766 | 225 | |
226 | if(! dynamic_cast<TObjString*> (metaData->GetProperty("RunUsed(TObjString)"))){ | |
227 | TObjString runUsed = Form("%d", GetCurrentRun()); | |
9e080f92 | 228 | metaData->SetProperty("RunUsed(TObjString)", runUsed.Clone()); |
2bb7b766 | 229 | } |
84090f85 | 230 | |
3301427a | 231 | Bool_t result = kFALSE; |
84090f85 | 232 | |
3301427a | 233 | if (!(AliCDBManager::Instance()->GetStorage(localUri))) { |
234 | Log("SHUTTLE", Form("StoreLocally - Cannot activate local %s storage", cdbType)); | |
84090f85 | 235 | } else { |
3301427a | 236 | result = AliCDBManager::Instance()->GetStorage(localUri) |
84090f85 | 237 | ->Put(object, id, metaData); |
238 | } | |
239 | ||
240 | if(!result) { | |
241 | ||
9827400b | 242 | Log(fCurrentDetector, Form("StoreLocally - Can't store object <%s>!", id.ToString().Data())); |
3301427a | 243 | } |
2bb7b766 | 244 | |
3301427a | 245 | return result; |
246 | } | |
84090f85 | 247 | |
3301427a | 248 | //______________________________________________________________________________________________ |
249 | Bool_t AliShuttle::StoreOCDB() | |
250 | { | |
9827400b | 251 | // |
252 | // Called when preprocessor ends successfully or when previous storage attempt failed (kStoreError status) | |
253 | // Calls underlying StoreOCDB(const char*) function twice, for OCDB and Reference storage. | |
254 | // Then calls StoreRefFilesToGrid to store reference files. | |
255 | // | |
256 | ||
5e993b6f | 257 | UpdateShuttleStatus(AliShuttleStatus::kStoreStarted); |
258 | ||
9827400b | 259 | if (fTestMode & kErrorGrid) |
260 | { | |
261 | Log("SHUTTLE", "StoreOCDB - In TESTMODE - Simulating error while storing in the Grid"); | |
262 | Log(fCurrentDetector, "StoreOCDB - In TESTMODE - Simulating error while storing in the Grid"); | |
263 | return kFALSE; | |
264 | } | |
265 | ||
c88ad5db | 266 | Log("SHUTTLE","StoreOCDB - Storing OCDB data ..."); |
5e993b6f | 267 | Int_t resultCDB = StoreOCDB(fgkMainCDB); |
86aa42c3 | 268 | |
c88ad5db | 269 | Log("SHUTTLE","StoreOCDB - Storing reference data ..."); |
5e993b6f | 270 | Int_t resultRef = StoreOCDB(fgkMainRefStorage); |
9827400b | 271 | |
c88ad5db | 272 | Log("SHUTTLE","StoreOCDB - Storing reference files ..."); |
273 | Bool_t resultRefFiles = CopyFilesToGrid("reference"); | |
274 | ||
275 | Bool_t resultMetadata = kTRUE; | |
276 | if(fCurrentDetector == "GRP") | |
277 | { | |
278 | Log("StoreOCDB - SHUTTLE","Storing Run Metadata file ..."); | |
279 | resultMetadata = CopyFilesToGrid("metadata"); | |
280 | } | |
9827400b | 281 | |
5e993b6f | 282 | Int_t storeResult = 0; |
283 | ||
284 | if (resultCDB < 0 || resultRef < 0 || resultRefFiles == kFALSE || resultMetadata == kFALSE) | |
285 | storeResult = -1; | |
286 | else if (resultCDB > 0 || resultRef > 0) | |
287 | storeResult = 1; | |
288 | ||
289 | if (storeResult < 0) | |
290 | { | |
291 | Log("SHUTTLE", | |
292 | Form("\t\t\t****** run %d - %s: STORAGE ERROR ******", | |
293 | GetCurrentRun(), fCurrentDetector.Data())); | |
294 | UpdateShuttleStatus(AliShuttleStatus::kStoreError); | |
295 | } | |
296 | else if (storeResult > 0) | |
297 | { | |
298 | Log("SHUTTLE", | |
299 | Form("\t\t\t****** run %d - %s: STORAGE DELAYED ******", | |
300 | GetCurrentRun(), fCurrentDetector.Data())); | |
301 | UpdateShuttleStatus(AliShuttleStatus::kStoreDelayed); | |
302 | } | |
303 | else if (storeResult == 0) | |
304 | { | |
305 | Log("SHUTTLE", | |
306 | Form("\t\t\t****** run %d - %s: DONE ******", | |
307 | GetCurrentRun(), fCurrentDetector.Data())); | |
308 | UpdateShuttleStatus(AliShuttleStatus::kDone); | |
309 | UpdateShuttleLogbook(fCurrentDetector, "DONE"); | |
310 | } | |
311 | ||
312 | return (storeResult == 0); | |
3301427a | 313 | } |
314 | ||
315 | //______________________________________________________________________________________________ | |
5e993b6f | 316 | Int_t AliShuttle::StoreOCDB(const TString& gridURI) |
3301427a | 317 | { |
318 | // | |
319 | // Called by StoreOCDB(), performs actual storage to the main OCDB and reference storages (Grid) | |
320 | // | |
5e993b6f | 321 | // Return code: |
322 | // -2 initialization error | |
323 | // -1 storage error | |
324 | // 0 success | |
325 | // 1 storage delayed (e.g. previous unprocessed runs) | |
326 | // | |
3301427a | 327 | |
328 | TObjArray* gridIds=0; | |
329 | ||
330 | Bool_t result = kTRUE; | |
5e993b6f | 331 | Bool_t delayed = kFALSE; |
3301427a | 332 | |
333 | const char* type = 0; | |
334 | TString localURI; | |
335 | if(gridURI == fgkMainCDB) { | |
336 | type = "OCDB"; | |
337 | localURI = fgkLocalCDB; | |
338 | } else if(gridURI == fgkMainRefStorage) { | |
339 | type = "reference"; | |
340 | localURI = fgkLocalRefStorage; | |
341 | } else { | |
342 | AliError(Form("Invalid storage URI: %s", gridURI.Data())); | |
5e993b6f | 343 | return -2; |
3301427a | 344 | } |
345 | ||
346 | AliCDBManager* man = AliCDBManager::Instance(); | |
347 | ||
348 | AliCDBStorage *gridSto = man->GetStorage(gridURI); | |
349 | if(!gridSto) { | |
350 | Log("SHUTTLE", | |
351 | Form("StoreOCDB - cannot activate main %s storage", type)); | |
5e993b6f | 352 | return -2; |
3301427a | 353 | } |
354 | ||
355 | gridIds = gridSto->GetQueryCDBList(); | |
356 | ||
357 | // get objects previously stored in local CDB | |
358 | AliCDBStorage *localSto = man->GetStorage(localURI); | |
359 | if(!localSto) { | |
360 | Log("SHUTTLE", | |
361 | Form("StoreOCDB - cannot activate local %s storage", type)); | |
5e993b6f | 362 | return -2; |
3301427a | 363 | } |
364 | AliCDBPath aPath(GetOfflineDetName(fCurrentDetector.Data()),"*","*"); | |
365 | // Local objects were stored with current run as Grid version! | |
366 | TList* localEntries = localSto->GetAll(aPath.GetPath(), GetCurrentRun(), GetCurrentRun()); | |
367 | localEntries->SetOwner(1); | |
368 | ||
369 | // loop on local stored objects | |
370 | TIter localIter(localEntries); | |
371 | AliCDBEntry *aLocEntry = 0; | |
372 | while((aLocEntry = dynamic_cast<AliCDBEntry*> (localIter.Next()))){ | |
373 | aLocEntry->SetOwner(1); | |
374 | AliCDBId aLocId = aLocEntry->GetId(); | |
375 | aLocEntry->SetVersion(-1); | |
376 | aLocEntry->SetSubVersion(-1); | |
377 | ||
378 | // If local object is valid up to infinity we store it only if it is | |
379 | // the first unprocessed run! | |
380 | if (aLocId.GetLastRun() == AliCDBRunRange::Infinity() && | |
381 | !fFirstUnprocessed[GetDetPos(fCurrentDetector)]) | |
382 | { | |
383 | Log("SHUTTLE", Form("StoreOCDB - %s: object %s has validity infinite but " | |
384 | "there are previous unprocessed runs!", | |
385 | fCurrentDetector.Data(), aLocId.GetPath().Data())); | |
5e993b6f | 386 | Log(fCurrentDetector.Data(), Form("StoreOCDB - %s: object %s has validity infinite but " |
387 | "there are previous unprocessed runs!", | |
388 | fCurrentDetector.Data(), aLocId.GetPath().Data())); | |
389 | delayed = kTRUE; | |
3301427a | 390 | continue; |
391 | } | |
392 | ||
393 | // loop on Grid valid Id's | |
394 | Bool_t store = kTRUE; | |
395 | TIter gridIter(gridIds); | |
396 | AliCDBId* aGridId = 0; | |
397 | while((aGridId = dynamic_cast<AliCDBId*> (gridIter.Next()))){ | |
398 | if(aGridId->GetPath() != aLocId.GetPath()) continue; | |
399 | // skip all objects valid up to infinity | |
400 | if(aGridId->GetLastRun() == AliCDBRunRange::Infinity()) continue; | |
401 | // if we get here, it means there's already some more recent object stored on Grid! | |
402 | store = kFALSE; | |
403 | break; | |
404 | } | |
405 | ||
406 | // If we get here, the file can be stored! | |
407 | Bool_t storeOk = gridSto->Put(aLocEntry); | |
408 | if(!store || storeOk){ | |
409 | ||
410 | if (!store) | |
411 | { | |
412 | Log(fCurrentDetector.Data(), | |
413 | Form("StoreOCDB - A more recent object already exists in %s storage: <%s>", | |
414 | type, aGridId->ToString().Data())); | |
415 | } else { | |
416 | Log("SHUTTLE", | |
417 | Form("StoreOCDB - Object <%s> successfully put into %s storage", | |
418 | aLocId.ToString().Data(), type)); | |
2d9019b4 | 419 | Log(fCurrentDetector.Data(), |
420 | Form("StoreOCDB - Object <%s> successfully put into %s storage", | |
421 | aLocId.ToString().Data(), type)); | |
3301427a | 422 | } |
84090f85 | 423 | |
3301427a | 424 | // removing local filename... |
425 | TString filename; | |
426 | localSto->IdToFilename(aLocId, filename); | |
c88ad5db | 427 | Log("SHUTTLE", Form("StoreOCDB - Removing local file %s", filename.Data())); |
3301427a | 428 | RemoveFile(filename.Data()); |
429 | continue; | |
430 | } else { | |
431 | Log("SHUTTLE", | |
432 | Form("StoreOCDB - Grid %s storage of object <%s> failed", | |
433 | type, aLocId.ToString().Data())); | |
2d9019b4 | 434 | Log(fCurrentDetector.Data(), |
435 | Form("StoreOCDB - Grid %s storage of object <%s> failed", | |
436 | type, aLocId.ToString().Data())); | |
3301427a | 437 | result = kFALSE; |
b948db8d | 438 | } |
439 | } | |
3301427a | 440 | localEntries->Clear(); |
2bb7b766 | 441 | |
5e993b6f | 442 | Int_t returnCode = 0; |
443 | ||
444 | if (result == kFALSE) | |
445 | returnCode = -1; | |
446 | else if (delayed != kFALSE) | |
447 | returnCode = 1; | |
448 | ||
449 | Log("SHUTTLE", Form("StoreOCDB - Returning with %d (result = %d, delayed = %d)", returnCode, result, delayed)); | |
450 | Log(fCurrentDetector.Data(), Form("StoreOCDB - Returning with %d (result = %d, delayed = %d)", returnCode, result, delayed)); | |
451 | ||
452 | return returnCode; | |
3301427a | 453 | } |
454 | ||
546242fb | 455 | //______________________________________________________________________________________________ |
456 | Bool_t AliShuttle::CleanReferenceStorage(const char* detector) | |
457 | { | |
2d9019b4 | 458 | // clears the directory used to store reference files of a given subdetector |
546242fb | 459 | |
460 | AliCDBManager* man = AliCDBManager::Instance(); | |
461 | AliCDBStorage* sto = man->GetStorage(fgkLocalRefStorage); | |
2d9019b4 | 462 | TString localBaseFolder = sto->GetBaseFolder(); |
463 | ||
464 | TString targetDir = GetRefFilePrefix(localBaseFolder.Data(), detector); | |
465 | ||
d524ade6 | 466 | Log("SHUTTLE", Form("CleanReferenceStorage - Cleaning %s", targetDir.Data())); |
2d9019b4 | 467 | |
468 | TString begin; | |
469 | begin.Form("%d_", GetCurrentRun()); | |
470 | ||
471 | TSystemDirectory* baseDir = new TSystemDirectory("/", targetDir); | |
472 | if (!baseDir) | |
473 | return kTRUE; | |
474 | ||
475 | TList* dirList = baseDir->GetListOfFiles(); | |
476 | delete baseDir; | |
477 | ||
478 | if (!dirList) return kTRUE; | |
479 | ||
480 | if (dirList->GetEntries() < 3) | |
481 | { | |
482 | delete dirList; | |
483 | return kTRUE; | |
484 | } | |
485 | ||
486 | Int_t nDirs = 0, nDel = 0; | |
487 | TIter dirIter(dirList); | |
488 | TSystemFile* entry = 0; | |
546242fb | 489 | |
2d9019b4 | 490 | Bool_t success = kTRUE; |
546242fb | 491 | |
2d9019b4 | 492 | while ((entry = dynamic_cast<TSystemFile*> (dirIter.Next()))) |
493 | { | |
494 | if (entry->IsDirectory()) | |
495 | continue; | |
496 | ||
497 | TString fileName(entry->GetName()); | |
498 | if (!fileName.BeginsWith(begin)) | |
499 | continue; | |
500 | ||
501 | nDirs++; | |
502 | ||
503 | // delete file | |
504 | Int_t result = gSystem->Unlink(fileName.Data()); | |
505 | ||
506 | if (result) | |
507 | { | |
d524ade6 | 508 | Log("SHUTTLE", Form("CleanReferenceStorage - Could not delete file %s!", fileName.Data())); |
2d9019b4 | 509 | success = kFALSE; |
510 | } else { | |
511 | nDel++; | |
512 | } | |
513 | } | |
514 | ||
515 | if(nDirs > 0) | |
516 | Log("SHUTTLE", Form("CleanReferenceStorage - %d (over %d) reference files in folder %s were deleted.", | |
517 | nDel, nDirs, targetDir.Data())); | |
518 | ||
519 | ||
520 | delete dirList; | |
521 | return success; | |
522 | ||
523 | ||
524 | ||
525 | ||
526 | ||
546242fb | 527 | |
528 | Int_t result = gSystem->GetPathInfo(targetDir, 0, (Long64_t*) 0, 0, 0); | |
529 | if (result == 0) | |
530 | { | |
531 | // delete directory | |
d524ade6 | 532 | result = gSystem->Exec(Form("rm -rf %s", targetDir.Data())); |
546242fb | 533 | if (result != 0) |
534 | { | |
d524ade6 | 535 | Log("SHUTTLE", Form("CleanReferenceStorage - Could not clean directory %s", targetDir.Data())); |
546242fb | 536 | return kFALSE; |
537 | } | |
538 | } | |
539 | ||
540 | result = gSystem->mkdir(targetDir, kTRUE); | |
541 | if (result != 0) | |
542 | { | |
c88ad5db | 543 | Log("SHUTTLE", Form("CleanReferenceStorage - Error creating base directory %s", targetDir.Data())); |
546242fb | 544 | return kFALSE; |
545 | } | |
546 | ||
547 | return kTRUE; | |
548 | } | |
549 | ||
9827400b | 550 | //______________________________________________________________________________________________ |
551 | Bool_t AliShuttle::StoreReferenceFile(const char* detector, const char* localFile, const char* gridFileName) | |
552 | { | |
553 | // | |
3c2a21c8 | 554 | // Stores reference file directly (without opening it). This function stores the file locally. |
9827400b | 555 | // |
3c2a21c8 | 556 | // The file is stored under the following location: |
557 | // <base folder of local reference storage>/<DET>/<RUN#>_<gridFileName> | |
558 | // where <gridFileName> is the second parameter given to the function | |
559 | // | |
9827400b | 560 | |
561 | if (fTestMode & kErrorStorage) | |
562 | { | |
563 | Log(fCurrentDetector, "StoreReferenceFile - In TESTMODE - Simulating error while storing locally"); | |
564 | return kFALSE; | |
565 | } | |
566 | ||
567 | AliCDBManager* man = AliCDBManager::Instance(); | |
568 | AliCDBStorage* sto = man->GetStorage(fgkLocalRefStorage); | |
569 | ||
570 | TString localBaseFolder = sto->GetBaseFolder(); | |
571 | ||
d524ade6 | 572 | TString target = GetRefFilePrefix(localBaseFolder.Data(), detector); |
573 | target.Append(Form("/%d_%s", GetCurrentRun(), gridFileName)); | |
9827400b | 574 | |
d524ade6 | 575 | return CopyFileLocally(localFile, target); |
c88ad5db | 576 | } |
577 | ||
578 | //______________________________________________________________________________________________ | |
579 | Bool_t AliShuttle::StoreRunMetadataFile(const char* localFile, const char* gridFileName) | |
580 | { | |
581 | // | |
582 | // Stores Run metadata file to the Grid, in the run folder | |
583 | // | |
584 | // Only GRP can call this function. | |
585 | ||
586 | if (fTestMode & kErrorStorage) | |
587 | { | |
588 | Log(fCurrentDetector, "StoreRunMetaDataFile - In TESTMODE - Simulating error while storing locally"); | |
589 | return kFALSE; | |
590 | } | |
591 | ||
592 | AliCDBManager* man = AliCDBManager::Instance(); | |
593 | AliCDBStorage* sto = man->GetStorage(fgkLocalRefStorage); | |
594 | ||
595 | TString localBaseFolder = sto->GetBaseFolder(); | |
596 | ||
597 | // Build Run level folder | |
955d2abc | 598 | // folder = /alice/data/year/lhcPeriod/runNb/raw |
c88ad5db | 599 | |
c88ad5db | 600 | |
675f64cd | 601 | TString lhcPeriod = GetLHCPeriod(); |
c88ad5db | 602 | if (lhcPeriod.Length() == 0) |
603 | { | |
604 | Log("SHUTTLE","StoreRunMetaDataFile - LHCPeriod not found in logbook!"); | |
605 | return 0; | |
606 | } | |
a1c5723b | 607 | |
608 | // TODO partitions with one detector only write data into LHCperiod_DET | |
2694f253 | 609 | TString partition = GetRunParameter("detector"); |
a1c5723b | 610 | |
611 | if (partition.Length() > 0 && partition != "ALICE") | |
612 | { | |
613 | lhcPeriod.Append(Form("_%s", partition.Data())); | |
614 | Log(fCurrentDetector, Form("Run data tags merged file will be written in %s", | |
615 | lhcPeriod.Data())); | |
616 | } | |
8884d71e | 617 | |
955d2abc | 618 | TString target = Form("%s/GRP/RunMetadata/alice/data/%d/%s/%09d/raw/%s", |
675f64cd | 619 | localBaseFolder.Data(), GetCurrentYear(), |
d524ade6 | 620 | lhcPeriod.Data(), GetCurrentRun(), gridFileName); |
c88ad5db | 621 | |
d524ade6 | 622 | return CopyFileLocally(localFile, target); |
c88ad5db | 623 | } |
624 | ||
625 | //______________________________________________________________________________________________ | |
d524ade6 | 626 | Bool_t AliShuttle::CopyFileLocally(const char* localFile, const TString& target) |
c88ad5db | 627 | { |
628 | // | |
629 | // Stores file locally. Called by StoreReferenceFile and StoreRunMetadataFile | |
d524ade6 | 630 | // Files are temporarily stored in the local reference storage. When the preprocessor |
631 | // finishes, the Shuttle calls CopyFilesToGrid to transfer the files to AliEn | |
632 | // (in reference or run level folders) | |
c88ad5db | 633 | // |
634 | ||
d524ade6 | 635 | TString targetDir(target(0, target.Last('/'))); |
636 | ||
637 | //try to open base dir folder, if it does not exist | |
2d9019b4 | 638 | void* dir = gSystem->OpenDirectory(targetDir.Data()); |
639 | if (dir == NULL) { | |
640 | if (gSystem->mkdir(targetDir.Data(), kTRUE)) { | |
a1c5723b | 641 | Log("SHUTTLE", Form("CopyFileLocally - Can't open directory <%s>", targetDir.Data())); |
2d9019b4 | 642 | return kFALSE; |
643 | } | |
644 | ||
645 | } else { | |
646 | gSystem->FreeDirectory(dir); | |
647 | } | |
9827400b | 648 | |
7d43a416 | 649 | Int_t result = 0; |
650 | ||
651 | result = gSystem->GetPathInfo(localFile, 0, (Long64_t*) 0, 0, 0); | |
9827400b | 652 | if (result) |
653 | { | |
a1c5723b | 654 | Log("SHUTTLE", Form("CopyFileLocally - %s does not exist", localFile)); |
546242fb | 655 | return kFALSE; |
9827400b | 656 | } |
546242fb | 657 | |
7d43a416 | 658 | result = gSystem->GetPathInfo(target, 0, (Long64_t*) 0, 0, 0); |
659 | if (!result) | |
660 | { | |
a1c5723b | 661 | Log("SHUTTLE", Form("CopyFileLocally - target file %s already exist, removing...", target.Data())); |
7d43a416 | 662 | if (gSystem->Unlink(target.Data())) |
663 | { | |
a1c5723b | 664 | Log("SHUTTLE", Form("CopyFileLocally - Could not remove existing target file %s!", target.Data())); |
7d43a416 | 665 | return kFALSE; |
666 | } | |
667 | } | |
668 | ||
9827400b | 669 | result = gSystem->CopyFile(localFile, target); |
670 | ||
671 | if (result == 0) | |
672 | { | |
a1c5723b | 673 | Log("SHUTTLE", Form("CopyFileLocally - File %s stored locally to %s", localFile, target.Data())); |
9827400b | 674 | return kTRUE; |
675 | } | |
676 | else | |
677 | { | |
a1c5723b | 678 | Log("SHUTTLE", Form("CopyFileLocally - Could not store file %s to %s! Error code = %d", |
546242fb | 679 | localFile, target.Data(), result)); |
9827400b | 680 | return kFALSE; |
681 | } | |
c88ad5db | 682 | |
683 | ||
684 | ||
9827400b | 685 | } |
686 | ||
687 | //______________________________________________________________________________________________ | |
c88ad5db | 688 | Bool_t AliShuttle::CopyFilesToGrid(const char* type) |
9827400b | 689 | { |
690 | // | |
c88ad5db | 691 | // Transfers local files to the Grid. Local files can be reference files |
692 | // or run metadata file (from GRP only). | |
9827400b | 693 | // |
c88ad5db | 694 | // According to the type (ref, metadata) the files are stored under the following location: |
695 | // ref --> <base folder of reference storage>/<DET>/<RUN#>_<gridFileName> | |
696 | // metadata --> <run data folder>/<MetadataFileName> | |
86aa42c3 | 697 | // |
c88ad5db | 698 | |
9827400b | 699 | AliCDBManager* man = AliCDBManager::Instance(); |
700 | AliCDBStorage* sto = man->GetStorage(fgkLocalRefStorage); | |
701 | if (!sto) | |
702 | return kFALSE; | |
703 | TString localBaseFolder = sto->GetBaseFolder(); | |
9827400b | 704 | |
c88ad5db | 705 | TString dir; |
706 | TString alienDir; | |
9827400b | 707 | TString begin; |
9827400b | 708 | |
c88ad5db | 709 | if (strcmp(type, "reference") == 0) |
710 | { | |
711 | dir = GetRefFilePrefix(localBaseFolder.Data(), fCurrentDetector.Data()); | |
712 | AliCDBStorage* gridSto = man->GetStorage(fgkMainRefStorage); | |
713 | if (!gridSto) | |
714 | return kFALSE; | |
715 | TString gridBaseFolder = gridSto->GetBaseFolder(); | |
716 | alienDir = GetRefFilePrefix(gridBaseFolder.Data(), fCurrentDetector.Data()); | |
717 | begin = Form("%d_", GetCurrentRun()); | |
718 | } | |
719 | else if (strcmp(type, "metadata") == 0) | |
720 | { | |
c88ad5db | 721 | |
675f64cd | 722 | TString lhcPeriod = GetLHCPeriod(); |
c88ad5db | 723 | |
724 | if (lhcPeriod.Length() == 0) | |
725 | { | |
726 | Log("SHUTTLE","CopyFilesToGrid - LHCPeriod not found in logbook!"); | |
727 | return 0; | |
728 | } | |
729 | ||
a1c5723b | 730 | // TODO partitions with one detector only write data into LHCperiod_DET |
2694f253 | 731 | TString partition = GetRunParameter("detector"); |
a1c5723b | 732 | |
733 | if (partition.Length() > 0 && partition != "ALICE") | |
734 | { | |
735 | lhcPeriod.Append(Form("_%s", partition.Data())); | |
736 | } | |
737 | ||
955d2abc | 738 | dir = Form("%s/GRP/RunMetadata/alice/data/%d/%s/%09d/raw", |
675f64cd | 739 | localBaseFolder.Data(), GetCurrentYear(), |
c88ad5db | 740 | lhcPeriod.Data(), GetCurrentRun()); |
675f64cd | 741 | alienDir = dir(dir.Index("/alice/data/"), dir.Length()); |
742 | ||
c88ad5db | 743 | begin = ""; |
744 | } | |
745 | else | |
746 | { | |
747 | Log("SHUTTLE", "CopyFilesToGrid - Unexpected: type label must be reference or metadata!"); | |
748 | return kFALSE; | |
749 | } | |
750 | ||
9827400b | 751 | TSystemDirectory* baseDir = new TSystemDirectory("/", dir); |
3d8bc902 | 752 | if (!baseDir) |
753 | return kTRUE; | |
754 | ||
2d9019b4 | 755 | TList* dirList = baseDir->GetListOfFiles(); |
756 | delete baseDir; | |
757 | ||
758 | if (!dirList) return kTRUE; | |
759 | ||
760 | if (dirList->GetEntries() < 3) | |
3d8bc902 | 761 | { |
2d9019b4 | 762 | delete dirList; |
9827400b | 763 | return kTRUE; |
3d8bc902 | 764 | } |
2d9019b4 | 765 | |
546242fb | 766 | if (!gGrid) |
767 | { | |
c88ad5db | 768 | Log("SHUTTLE", "CopyFilesToGrid - Connection to Grid failed: Cannot continue!"); |
2d9019b4 | 769 | delete dirList; |
546242fb | 770 | return kFALSE; |
771 | } | |
772 | ||
2d9019b4 | 773 | Int_t nDirs = 0, nTransfer = 0; |
774 | TIter dirIter(dirList); | |
775 | TSystemFile* entry = 0; | |
776 | ||
9827400b | 777 | Bool_t success = kTRUE; |
3d8bc902 | 778 | Bool_t first = kTRUE; |
9827400b | 779 | |
2d9019b4 | 780 | while ((entry = dynamic_cast<TSystemFile*> (dirIter.Next()))) |
781 | { | |
9827400b | 782 | if (entry->IsDirectory()) |
783 | continue; | |
784 | ||
785 | TString fileName(entry->GetName()); | |
786 | if (!fileName.BeginsWith(begin)) | |
787 | continue; | |
788 | ||
2d9019b4 | 789 | nDirs++; |
790 | ||
3d8bc902 | 791 | if (first) |
792 | { | |
793 | first = kFALSE; | |
c88ad5db | 794 | // check that folder exists, otherwise create it |
3d8bc902 | 795 | TGridResult* result = gGrid->Ls(alienDir.Data(), "a"); |
796 | ||
797 | if (!result) | |
2d9019b4 | 798 | { |
799 | delete dirList; | |
3d8bc902 | 800 | return kFALSE; |
2d9019b4 | 801 | } |
3d8bc902 | 802 | |
546242fb | 803 | if (!result->GetFileName(1)) // TODO: It looks like element 0 is always 0!! |
3d8bc902 | 804 | { |
675f64cd | 805 | // TODO It does not work currently! Bug in TAliEn::Mkdir |
806 | // TODO Manually fixed in local root v5-16-00 | |
c88ad5db | 807 | if (!gGrid->Mkdir(alienDir.Data(),"-p",0)) |
3d8bc902 | 808 | { |
c88ad5db | 809 | Log("SHUTTLE", Form("CopyFilesToGrid - Cannot create directory %s", |
3d8bc902 | 810 | alienDir.Data())); |
2d9019b4 | 811 | delete dirList; |
3d8bc902 | 812 | return kFALSE; |
546242fb | 813 | } else { |
c88ad5db | 814 | Log("SHUTTLE",Form("CopyFilesToGrid - Folder %s created", alienDir.Data())); |
3d8bc902 | 815 | } |
816 | ||
546242fb | 817 | } else { |
c88ad5db | 818 | Log("SHUTTLE",Form("CopyFilesToGrid - Folder %s found", alienDir.Data())); |
3d8bc902 | 819 | } |
820 | } | |
821 | ||
9827400b | 822 | TString fullLocalPath; |
823 | fullLocalPath.Form("%s/%s", dir.Data(), fileName.Data()); | |
824 | ||
825 | TString fullGridPath; | |
826 | fullGridPath.Form("alien://%s/%s", alienDir.Data(), fileName.Data()); | |
827 | ||
a986b218 | 828 | Bool_t result = TFile::Cp(fullLocalPath, fullGridPath); |
9827400b | 829 | |
830 | if (result) | |
831 | { | |
c88ad5db | 832 | Log("SHUTTLE", Form("CopyFilesToGrid - Copying local file %s to %s succeeded!", |
833 | fullLocalPath.Data(), fullGridPath.Data())); | |
9827400b | 834 | RemoveFile(fullLocalPath); |
2d9019b4 | 835 | nTransfer++; |
9827400b | 836 | } |
837 | else | |
838 | { | |
c88ad5db | 839 | Log("SHUTTLE", Form("CopyFilesToGrid - Copying local file %s to %s FAILED!", |
840 | fullLocalPath.Data(), fullGridPath.Data())); | |
9827400b | 841 | success = kFALSE; |
842 | } | |
843 | } | |
2d9019b4 | 844 | |
c88ad5db | 845 | Log("SHUTTLE", Form("CopyFilesToGrid - %d (over %d) files in folder %s copied to Grid.", |
846 | nTransfer, nDirs, dir.Data())); | |
2d9019b4 | 847 | |
848 | ||
849 | delete dirList; | |
9827400b | 850 | return success; |
851 | } | |
852 | ||
2d9019b4 | 853 | //______________________________________________________________________________________________ |
854 | const char* AliShuttle::GetRefFilePrefix(const char* base, const char* detector) | |
855 | { | |
856 | // | |
857 | // Get folder name of reference files | |
858 | // | |
859 | ||
860 | TString offDetStr(GetOfflineDetName(detector)); | |
861 | TString dir; | |
862 | if (offDetStr == "ITS" || offDetStr == "MUON" || offDetStr == "PHOS") | |
863 | { | |
864 | dir.Form("%s/%s/%s", base, offDetStr.Data(), detector); | |
865 | } else { | |
866 | dir.Form("%s/%s", base, offDetStr.Data()); | |
867 | } | |
868 | ||
869 | return dir.Data(); | |
870 | ||
871 | ||
872 | } | |
c88ad5db | 873 | |
3301427a | 874 | //______________________________________________________________________________________________ |
875 | void AliShuttle::CleanLocalStorage(const TString& uri) | |
876 | { | |
9827400b | 877 | // |
878 | // Called in case the preprocessor is declared failed. Remove remaining objects from the local storages. | |
879 | // | |
3301427a | 880 | |
881 | const char* type = 0; | |
882 | if(uri == fgkLocalCDB) { | |
883 | type = "OCDB"; | |
884 | } else if(uri == fgkLocalRefStorage) { | |
546242fb | 885 | type = "Reference"; |
3301427a | 886 | } else { |
887 | AliError(Form("Invalid storage URI: %s", uri.Data())); | |
888 | return; | |
889 | } | |
890 | ||
891 | AliCDBManager* man = AliCDBManager::Instance(); | |
b948db8d | 892 | |
3301427a | 893 | // open local storage |
894 | AliCDBStorage *localSto = man->GetStorage(uri); | |
895 | if(!localSto) { | |
896 | Log("SHUTTLE", | |
897 | Form("CleanLocalStorage - cannot activate local %s storage", type)); | |
898 | return; | |
899 | } | |
900 | ||
901 | TString filename(Form("%s/%s/*/Run*_v%d_s*.root", | |
546242fb | 902 | localSto->GetBaseFolder().Data(), GetOfflineDetName(fCurrentDetector.Data()), GetCurrentRun())); |
3301427a | 903 | |
c88ad5db | 904 | AliDebug(2, Form("filename = %s", filename.Data())); |
3301427a | 905 | |
c88ad5db | 906 | Log("SHUTTLE", Form("Removing remaining local files for run %d and detector %s ...", |
3301427a | 907 | GetCurrentRun(), fCurrentDetector.Data())); |
908 | ||
909 | RemoveFile(filename.Data()); | |
910 | ||
911 | } | |
912 | ||
913 | //______________________________________________________________________________________________ | |
914 | void AliShuttle::RemoveFile(const char* filename) | |
915 | { | |
9827400b | 916 | // |
917 | // removes local file | |
918 | // | |
3301427a | 919 | |
920 | TString command(Form("rm -f %s", filename)); | |
921 | ||
922 | Int_t result = gSystem->Exec(command.Data()); | |
923 | if(result != 0) | |
924 | { | |
925 | Log("SHUTTLE", Form("RemoveFile - %s: Cannot remove file %s!", | |
926 | fCurrentDetector.Data(), filename)); | |
927 | } | |
73abe331 | 928 | } |
929 | ||
b948db8d | 930 | //______________________________________________________________________________________________ |
5164a766 | 931 | AliShuttleStatus* AliShuttle::ReadShuttleStatus() |
932 | { | |
9827400b | 933 | // |
934 | // Reads the AliShuttleStatus from the CDB | |
935 | // | |
5164a766 | 936 | |
2bb7b766 | 937 | if (fStatusEntry){ |
938 | delete fStatusEntry; | |
939 | fStatusEntry = 0; | |
940 | } | |
5164a766 | 941 | |
10a5a932 | 942 | fStatusEntry = AliCDBManager::Instance()->GetStorage(GetLocalCDB()) |
2bb7b766 | 943 | ->Get(Form("/SHUTTLE/STATUS/%s", fCurrentDetector.Data()), GetCurrentRun()); |
5164a766 | 944 | |
2bb7b766 | 945 | if (!fStatusEntry) return 0; |
946 | fStatusEntry->SetOwner(1); | |
5164a766 | 947 | |
2bb7b766 | 948 | AliShuttleStatus* status = dynamic_cast<AliShuttleStatus*> (fStatusEntry->GetObject()); |
949 | if (!status) { | |
950 | AliError("Invalid object stored to CDB!"); | |
951 | return 0; | |
952 | } | |
5164a766 | 953 | |
2bb7b766 | 954 | return status; |
5164a766 | 955 | } |
956 | ||
957 | //______________________________________________________________________________________________ | |
7bfb2090 | 958 | Bool_t AliShuttle::WriteShuttleStatus(AliShuttleStatus* status) |
5164a766 | 959 | { |
9827400b | 960 | // |
961 | // writes the status for one subdetector | |
962 | // | |
2bb7b766 | 963 | |
964 | if (fStatusEntry){ | |
965 | delete fStatusEntry; | |
966 | fStatusEntry = 0; | |
967 | } | |
5164a766 | 968 | |
2bb7b766 | 969 | Int_t run = GetCurrentRun(); |
5164a766 | 970 | |
2bb7b766 | 971 | AliCDBId id(AliCDBPath("SHUTTLE", "STATUS", fCurrentDetector), run, run); |
5164a766 | 972 | |
2bb7b766 | 973 | fStatusEntry = new AliCDBEntry(status, id, new AliCDBMetaData); |
974 | fStatusEntry->SetOwner(1); | |
5164a766 | 975 | |
2bb7b766 | 976 | UInt_t result = AliCDBManager::Instance()->GetStorage(fgkLocalCDB)->Put(fStatusEntry); |
7bfb2090 | 977 | |
2bb7b766 | 978 | if (!result) { |
3301427a | 979 | Log("SHUTTLE", Form("WriteShuttleStatus - Failed for %s, run %d", |
980 | fCurrentDetector.Data(), run)); | |
2bb7b766 | 981 | return kFALSE; |
982 | } | |
e7f62f16 | 983 | |
984 | SendMLInfo(); | |
7bfb2090 | 985 | |
2bb7b766 | 986 | return kTRUE; |
5164a766 | 987 | } |
988 | ||
989 | //______________________________________________________________________________________________ | |
990 | void AliShuttle::UpdateShuttleStatus(AliShuttleStatus::Status newStatus, Bool_t increaseCount) | |
991 | { | |
9827400b | 992 | // |
993 | // changes the AliShuttleStatus for the given detector and run to the given status | |
994 | // | |
5164a766 | 995 | |
2bb7b766 | 996 | if (!fStatusEntry){ |
997 | AliError("UNEXPECTED: fStatusEntry empty"); | |
998 | return; | |
999 | } | |
5164a766 | 1000 | |
2bb7b766 | 1001 | AliShuttleStatus* status = dynamic_cast<AliShuttleStatus*> (fStatusEntry->GetObject()); |
5164a766 | 1002 | |
2bb7b766 | 1003 | if (!status){ |
c88ad5db | 1004 | Log("SHUTTLE", "UpdateShuttleStatus - UNEXPECTED: status could not be read from current CDB entry"); |
2bb7b766 | 1005 | return; |
1006 | } | |
5164a766 | 1007 | |
2c15234c | 1008 | TString actionStr = Form("UpdateShuttleStatus - %s: Changing state from %s to %s", |
eba76848 | 1009 | fCurrentDetector.Data(), |
36c99a6a | 1010 | status->GetStatusName(), |
eba76848 | 1011 | status->GetStatusName(newStatus)); |
cb343cfd | 1012 | Log("SHUTTLE", actionStr); |
1013 | SetLastAction(actionStr); | |
5164a766 | 1014 | |
2bb7b766 | 1015 | status->SetStatus(newStatus); |
1016 | if (increaseCount) status->IncreaseCount(); | |
5164a766 | 1017 | |
2bb7b766 | 1018 | AliCDBManager::Instance()->GetStorage(fgkLocalCDB)->Put(fStatusEntry); |
e7f62f16 | 1019 | |
1020 | SendMLInfo(); | |
5164a766 | 1021 | } |
e7f62f16 | 1022 | |
1023 | //______________________________________________________________________________________________ | |
1024 | void AliShuttle::SendMLInfo() | |
1025 | { | |
1026 | // | |
1027 | // sends ML information about the current status of the current detector being processed | |
1028 | // | |
1029 | ||
1030 | AliShuttleStatus* status = dynamic_cast<AliShuttleStatus*> (fStatusEntry->GetObject()); | |
1031 | ||
1032 | if (!status){ | |
3301427a | 1033 | Log("SHUTTLE", "SendMLInfo - UNEXPECTED: status could not be read from current CDB entry"); |
e7f62f16 | 1034 | return; |
1035 | } | |
1036 | ||
1037 | TMonaLisaText mlStatus(Form("%s_status", fCurrentDetector.Data()), status->GetStatusName()); | |
1038 | TMonaLisaValue mlRetryCount(Form("%s_count", fCurrentDetector.Data()), status->GetCount()); | |
1039 | ||
1040 | TList mlList; | |
1041 | mlList.Add(&mlStatus); | |
1042 | mlList.Add(&mlRetryCount); | |
1043 | ||
ee6f7523 | 1044 | TString mlID; |
1045 | mlID.Form("%d", GetCurrentRun()); | |
1046 | fMonaLisa->SendParameters(&mlList, mlID); | |
e7f62f16 | 1047 | } |
1048 | ||
5164a766 | 1049 | //______________________________________________________________________________________________ |
1050 | Bool_t AliShuttle::ContinueProcessing() | |
1051 | { | |
9827400b | 1052 | // this function reads the AliShuttleStatus information from CDB and |
1053 | // checks if the processing should be continued | |
1054 | // if yes it returns kTRUE and updates the AliShuttleStatus with nextStatus | |
2bb7b766 | 1055 | |
926cbc0e | 1056 | if (!fConfig->HostProcessDetector(fCurrentDetector)) |
1057 | return kFALSE; | |
57c1a579 | 1058 | |
1059 | AliPreprocessor* aPreprocessor = | |
1060 | dynamic_cast<AliPreprocessor*> (fPreprocessorMap.GetValue(fCurrentDetector)); | |
1061 | if (!aPreprocessor) | |
1062 | { | |
c88ad5db | 1063 | Log("SHUTTLE", Form("ContinueProcessing - %s: no preprocessor registered", fCurrentDetector.Data())); |
57c1a579 | 1064 | return kFALSE; |
1065 | } | |
1066 | ||
2bb7b766 | 1067 | AliShuttleLogbookEntry::Status entryStatus = |
eba76848 | 1068 | fLogbookEntry->GetDetectorStatus(fCurrentDetector); |
2bb7b766 | 1069 | |
5e993b6f | 1070 | if (entryStatus != AliShuttleLogbookEntry::kUnprocessed) { |
c88ad5db | 1071 | Log("SHUTTLE", Form("ContinueProcessing - %s is %s", |
2bb7b766 | 1072 | fCurrentDetector.Data(), |
1073 | fLogbookEntry->GetDetectorStatusName(entryStatus))); | |
1074 | return kFALSE; | |
1075 | } | |
1076 | ||
1077 | // if we get here, according to Shuttle logbook subdetector is in UNPROCESSED state | |
be48e3ea | 1078 | |
1079 | // check if current run is first unprocessed run for current detector | |
1080 | if (fConfig->StrictRunOrder(fCurrentDetector) && | |
1081 | !fFirstUnprocessed[GetDetPos(fCurrentDetector)]) | |
1082 | { | |
86aa42c3 | 1083 | if (fTestMode == kNone) |
1084 | { | |
c88ad5db | 1085 | Log("SHUTTLE", Form("ContinueProcessing - %s requires strict run ordering" |
1086 | " but this is not the first unprocessed run!")); | |
86aa42c3 | 1087 | return kFALSE; |
1088 | } | |
1089 | else | |
1090 | { | |
c88ad5db | 1091 | Log("SHUTTLE", Form("ContinueProcessing - In TESTMODE - " |
1092 | "Although %s requires strict run ordering " | |
1093 | "and this is not the first unprocessed run, " | |
1094 | "the SHUTTLE continues")); | |
86aa42c3 | 1095 | } |
be48e3ea | 1096 | } |
1097 | ||
926cbc0e | 1098 | // Is the subdetector processed first time for this run? |
1099 | fFirstProcessing = kFALSE; | |
1100 | ||
2bb7b766 | 1101 | AliShuttleStatus* status = ReadShuttleStatus(); |
1102 | if (!status) { | |
1103 | // first time | |
1104 | Log("SHUTTLE", Form("ContinueProcessing - %s: Processing first time", | |
1105 | fCurrentDetector.Data())); | |
1106 | status = new AliShuttleStatus(AliShuttleStatus::kStarted); | |
926cbc0e | 1107 | fFirstProcessing = kTRUE; |
2bb7b766 | 1108 | return WriteShuttleStatus(status); |
1109 | } | |
1110 | ||
ffa25f20 | 1111 | // The following case shouldn't happen if Shuttle Logbook was correctly updated. |
2bb7b766 | 1112 | // If it happens it may mean Logbook updating failed... let's do it now! |
1113 | if (status->GetStatus() == AliShuttleStatus::kDone || | |
ffa25f20 | 1114 | status->GetStatus() == AliShuttleStatus::kFailed || |
1115 | status->GetStatus() == AliShuttleStatus::kSkipped) { | |
2bb7b766 | 1116 | Log("SHUTTLE", Form("ContinueProcessing - %s is already %s. Updating Shuttle Logbook", |
1117 | fCurrentDetector.Data(), | |
1118 | status->GetStatusName(status->GetStatus()))); | |
ffa25f20 | 1119 | |
1120 | if (status->GetStatus() == AliShuttleStatus::kSkipped) | |
1121 | { | |
1122 | UpdateShuttleLogbook(fCurrentDetector.Data(), "DONE"); | |
1123 | } | |
1124 | else | |
1125 | UpdateShuttleLogbook(fCurrentDetector.Data(), status->GetStatusName(status->GetStatus())); | |
1126 | ||
2bb7b766 | 1127 | return kFALSE; |
1128 | } | |
1129 | ||
5e993b6f | 1130 | if (status->GetStatus() == AliShuttleStatus::kStoreStarted || status->GetStatus() == AliShuttleStatus::kStoreDelayed ||status->GetStatus() == AliShuttleStatus::kStoreError) { |
2bb7b766 | 1131 | Log("SHUTTLE", |
c88ad5db | 1132 | Form("ContinueProcessing - %s: Grid storage of one or more " |
1133 | "objects failed. Trying again now", | |
2bb7b766 | 1134 | fCurrentDetector.Data())); |
5e993b6f | 1135 | StoreOCDB(); |
2bb7b766 | 1136 | return kFALSE; |
1137 | } | |
1138 | ||
1139 | // if we get here, there is a restart | |
57c1a579 | 1140 | Bool_t cont = kFALSE; |
2bb7b766 | 1141 | |
1142 | // abort conditions | |
cb343cfd | 1143 | if (status->GetCount() >= fConfig->GetMaxRetries()) { |
57c1a579 | 1144 | Log("SHUTTLE", Form("ContinueProcessing - %s failed %d times in status %s - " |
1145 | "Updating Shuttle Logbook", fCurrentDetector.Data(), | |
2bb7b766 | 1146 | status->GetCount(), status->GetStatusName())); |
1147 | UpdateShuttleLogbook(fCurrentDetector.Data(), "FAILED"); | |
e7f62f16 | 1148 | UpdateShuttleStatus(AliShuttleStatus::kFailed); |
3301427a | 1149 | |
1150 | // there may still be objects in local OCDB and reference storage | |
1151 | // and FXS databases may be not updated: do it now! | |
9827400b | 1152 | |
1153 | // TODO Currently disabled, we want to keep files in case of failure! | |
1154 | // CleanLocalStorage(fgkLocalCDB); | |
1155 | // CleanLocalStorage(fgkLocalRefStorage); | |
1156 | // UpdateTableFailCase(); | |
1157 | ||
1158 | // Send mail to detector expert! | |
c88ad5db | 1159 | Log("SHUTTLE", Form("ContinueProcessing - Sending mail to %s expert...", |
926cbc0e | 1160 | fCurrentDetector.Data())); |
339adafa | 1161 | if (!SendMail(kPPEMail)) |
9827400b | 1162 | Log("SHUTTLE", Form("ContinueProcessing - Could not send mail to %s expert", |
926cbc0e | 1163 | fCurrentDetector.Data())); |
3301427a | 1164 | |
57c1a579 | 1165 | } else { |
1166 | Log("SHUTTLE", Form("ContinueProcessing - %s: restarting. " | |
1167 | "Aborted before with %s. Retry number %d.", fCurrentDetector.Data(), | |
1168 | status->GetStatusName(), status->GetCount())); | |
9827400b | 1169 | Bool_t increaseCount = kTRUE; |
c88ad5db | 1170 | if (status->GetStatus() == AliShuttleStatus::kDCSError || |
8da81210 | 1171 | status->GetStatus() == AliShuttleStatus::kDCSStarted || |
1172 | status->GetStatus() == AliShuttleStatus::kFXSError) | |
c88ad5db | 1173 | increaseCount = kFALSE; |
675f64cd | 1174 | |
9827400b | 1175 | UpdateShuttleStatus(AliShuttleStatus::kStarted, increaseCount); |
57c1a579 | 1176 | cont = kTRUE; |
2bb7b766 | 1177 | } |
1178 | ||
57c1a579 | 1179 | return cont; |
5164a766 | 1180 | } |
1181 | ||
1182 | //______________________________________________________________________________________________ | |
2bb7b766 | 1183 | Bool_t AliShuttle::Process(AliShuttleLogbookEntry* entry) |
58bc3020 | 1184 | { |
73abe331 | 1185 | // |
b948db8d | 1186 | // Makes data retrieval for all detectors in the configuration. |
2bb7b766 | 1187 | // entry: Shuttle logbook entry, contains run paramenters and status of detectors |
1188 | // (Unprocessed, Inactive, Failed or Done). | |
d477ad88 | 1189 | // Returns kFALSE in case of error occured and kTRUE otherwise |
73abe331 | 1190 | // |
1191 | ||
9827400b | 1192 | if (!entry) return kFALSE; |
2bb7b766 | 1193 | |
1194 | fLogbookEntry = entry; | |
1195 | ||
c88ad5db | 1196 | Log("SHUTTLE", Form("\t\t\t^*^*^*^*^*^*^*^*^*^*^*^* run %d: START ^*^*^*^*^*^*^*^*^*^*^*^*", |
9827400b | 1197 | GetCurrentRun())); |
2bb7b766 | 1198 | |
e7f62f16 | 1199 | // Send the information to ML |
339adafa | 1200 | CountOpenRuns(); |
1201 | ||
e7f62f16 | 1202 | TMonaLisaText mlStatus("SHUTTLE_status", "Processing"); |
339adafa | 1203 | TString runType(entry->GetRunType()); |
1204 | if (strlen(entry->GetRunParameter("log")) > 0){ | |
1205 | ||
1206 | runType += "("; | |
1207 | runType += entry->GetRunParameter("log"); | |
1208 | runType += ")"; | |
1209 | } | |
1210 | TMonaLisaText mlRunType("SHUTTLE_runtype", runType); | |
e7f62f16 | 1211 | |
1212 | TList mlList; | |
1213 | mlList.Add(&mlStatus); | |
9827400b | 1214 | mlList.Add(&mlRunType); |
e7f62f16 | 1215 | |
ee6f7523 | 1216 | TString mlID; |
1217 | mlID.Form("%d", GetCurrentRun()); | |
1218 | fMonaLisa->SendParameters(&mlList, mlID); | |
3301427a | 1219 | |
9827400b | 1220 | if (fLogbookEntry->IsDone()) |
1221 | { | |
1222 | Log("SHUTTLE","Process - Shuttle is already DONE. Updating logbook"); | |
1223 | UpdateShuttleLogbook("shuttle_done"); | |
1224 | fLogbookEntry = 0; | |
1225 | return kTRUE; | |
1226 | } | |
1227 | ||
1228 | // read test mode if flag is set | |
1229 | if (fReadTestMode) | |
1230 | { | |
3d8bc902 | 1231 | fTestMode = kNone; |
9827400b | 1232 | TString logEntry(entry->GetRunParameter("log")); |
1233 | //printf("log entry = %s\n", logEntry.Data()); | |
1234 | TString searchStr("Testmode: "); | |
1235 | Int_t pos = logEntry.Index(searchStr.Data()); | |
1236 | //printf("%d\n", pos); | |
1237 | if (pos >= 0) | |
1238 | { | |
1239 | TSubString subStr = logEntry(pos + searchStr.Length(), logEntry.Length()); | |
1240 | //printf("%s\n", subStr.String().Data()); | |
1241 | TString newStr(subStr.Data()); | |
1242 | TObjArray* token = newStr.Tokenize(' '); | |
1243 | if (token) | |
1244 | { | |
1245 | //token->Print(); | |
1246 | TObjString* tmpStr = dynamic_cast<TObjString*> (token->First()); | |
1247 | if (tmpStr) | |
1248 | { | |
1249 | Int_t testMode = tmpStr->String().Atoi(); | |
1250 | if (testMode > 0) | |
1251 | { | |
c88ad5db | 1252 | Log("SHUTTLE", Form("Process - Enabling test mode %d", testMode)); |
9827400b | 1253 | SetTestMode((TestMode) testMode); |
1254 | } | |
1255 | } | |
1256 | delete token; | |
1257 | } | |
1258 | } | |
1259 | } | |
c88ad5db | 1260 | |
eba76848 | 1261 | fLogbookEntry->Print("all"); |
57f50b3c | 1262 | |
1263 | // Initialization | |
d477ad88 | 1264 | Bool_t hasError = kFALSE; |
5164a766 | 1265 | |
675f64cd | 1266 | // Set the CDB and Reference folders according to the year and LHC period |
1267 | TString lhcPeriod(GetLHCPeriod()); | |
1268 | if (lhcPeriod.Length() == 0) | |
1269 | { | |
7d4cf768 | 1270 | Log("SHUTTLE","Process - LHCPeriod not found in logbook!"); |
1271 | return 0; | |
675f64cd | 1272 | } |
1273 | ||
1274 | if (fgkMainCDB.Length() == 0) | |
1275 | fgkMainCDB = Form("alien://folder=/alice/data/%d/%s/OCDB?user=alidaq?cacheFold=/tmp/OCDBCache", | |
1276 | GetCurrentYear(), lhcPeriod.Data()); | |
1277 | ||
1278 | if (fgkMainRefStorage.Length() == 0) | |
1279 | fgkMainRefStorage = Form("alien://folder=/alice/data/%d/%s/Reference?user=alidaq?cacheFold=/tmp/OCDBCache", | |
1280 | GetCurrentYear(), lhcPeriod.Data()); | |
1281 | ||
57f50b3c | 1282 | // Loop on detectors in the configuration |
b948db8d | 1283 | TIter iter(fConfig->GetDetectors()); |
2bb7b766 | 1284 | TObjString* aDetector = 0; |
b948db8d | 1285 | |
4508ab8b | 1286 | Bool_t first = kTRUE; |
1287 | ||
be48e3ea | 1288 | while ((aDetector = (TObjString*) iter.Next())) |
1289 | { | |
7bfb2090 | 1290 | fCurrentDetector = aDetector->String(); |
5164a766 | 1291 | |
5e993b6f | 1292 | if (ContinueProcessing() == kFALSE) |
1293 | continue; | |
4508ab8b | 1294 | |
1295 | if (first) | |
1296 | { | |
1297 | // only read QueryCDB when needed and only once | |
1298 | AliCDBStorage *mainCDBSto = AliCDBManager::Instance()->GetStorage(fgkMainCDB); | |
1299 | if(mainCDBSto) mainCDBSto->QueryCDB(GetCurrentRun()); | |
1300 | AliCDBStorage *mainRefSto = AliCDBManager::Instance()->GetStorage(fgkMainRefStorage); | |
1301 | if(mainRefSto) mainRefSto->QueryCDB(GetCurrentRun()); | |
1302 | first = kFALSE; | |
1303 | } | |
9e080f92 | 1304 | |
c88ad5db | 1305 | Log("SHUTTLE", Form("\t\t\t****** run %d - %s: START ******", |
2bb7b766 | 1306 | GetCurrentRun(), aDetector->GetName())); |
1307 | ||
9d733021 | 1308 | for(Int_t iSys=0;iSys<3;iSys++) fFXSCalled[iSys]=kFALSE; |
1309 | ||
c88ad5db | 1310 | Log(fCurrentDetector.Data(), "Process - Starting processing"); |
85a80aa9 | 1311 | |
be48e3ea | 1312 | Int_t pid = fork(); |
1313 | ||
1314 | if (pid < 0) | |
1315 | { | |
c88ad5db | 1316 | Log("SHUTTLE", "Process - ERROR: Forking failed"); |
be48e3ea | 1317 | } |
1318 | else if (pid > 0) | |
1319 | { | |
1320 | // parent | |
c88ad5db | 1321 | Log("SHUTTLE", Form("Process - In parent process of %d - %s: Starting monitoring", |
be48e3ea | 1322 | GetCurrentRun(), aDetector->GetName())); |
1323 | ||
1324 | Long_t begin = time(0); | |
1325 | ||
1326 | int status; // to be used with waitpid, on purpose an int (not Int_t)! | |
1327 | while (waitpid(pid, &status, WNOHANG) == 0) | |
1328 | { | |
1329 | Long_t expiredTime = time(0) - begin; | |
1330 | ||
1331 | if (expiredTime > fConfig->GetPPTimeOut()) | |
1332 | { | |
9827400b | 1333 | TString tmp; |
c88ad5db | 1334 | tmp.Form("Process - Process of %s time out. " |
1335 | "Run time: %d seconds. Killing...", | |
1336 | fCurrentDetector.Data(), expiredTime); | |
9827400b | 1337 | Log("SHUTTLE", tmp); |
1338 | Log(fCurrentDetector, tmp); | |
be48e3ea | 1339 | |
1340 | kill(pid, 9); | |
1341 | ||
3301427a | 1342 | UpdateShuttleStatus(AliShuttleStatus::kPPTimeOut); |
be48e3ea | 1343 | hasError = kTRUE; |
1344 | ||
1345 | gSystem->Sleep(1000); | |
1346 | } | |
1347 | else | |
1348 | { | |
be48e3ea | 1349 | gSystem->Sleep(1000); |
9827400b | 1350 | |
1351 | TString checkStr; | |
1352 | checkStr.Form("ps -o vsize --pid %d | tail -n 1", pid); | |
1353 | FILE* pipe = gSystem->OpenPipe(checkStr, "r"); | |
1354 | if (!pipe) | |
1355 | { | |
c88ad5db | 1356 | Log("SHUTTLE", Form("Process - Error: " |
1357 | "Could not open pipe to %s", checkStr.Data())); | |
9827400b | 1358 | continue; |
1359 | } | |
1360 | ||
1361 | char buffer[100]; | |
1362 | if (!fgets(buffer, 100, pipe)) | |
1363 | { | |
c88ad5db | 1364 | Log("SHUTTLE", "Process - Error: ps did not return anything"); |
9827400b | 1365 | gSystem->ClosePipe(pipe); |
1366 | continue; | |
1367 | } | |
1368 | gSystem->ClosePipe(pipe); | |
1369 | ||
1370 | //Log("SHUTTLE", Form("ps returned %s", buffer)); | |
1371 | ||
1372 | Int_t mem = 0; | |
1373 | if ((sscanf(buffer, "%d\n", &mem) != 1) || !mem) | |
1374 | { | |
c88ad5db | 1375 | Log("SHUTTLE", "Process - Error: Could not parse output of ps"); |
9827400b | 1376 | continue; |
1377 | } | |
1378 | ||
1379 | if (expiredTime % 60 == 0) | |
ee6f7523 | 1380 | { |
c88ad5db | 1381 | Log("SHUTTLE", Form("Process - %s: Checking process. " |
1382 | "Run time: %d seconds - Memory consumption: %d KB", | |
1383 | fCurrentDetector.Data(), expiredTime, mem)); | |
ee6f7523 | 1384 | SendAlive(); |
1385 | } | |
9827400b | 1386 | |
1387 | if (mem > fConfig->GetPPMaxMem()) | |
1388 | { | |
1389 | TString tmp; | |
c88ad5db | 1390 | tmp.Form("Process - Process exceeds maximum allowed memory " |
1391 | "(%d KB > %d KB). Killing...", | |
9827400b | 1392 | mem, fConfig->GetPPMaxMem()); |
1393 | Log("SHUTTLE", tmp); | |
1394 | Log(fCurrentDetector, tmp); | |
1395 | ||
1396 | kill(pid, 9); | |
1397 | ||
1398 | UpdateShuttleStatus(AliShuttleStatus::kPPOutOfMemory); | |
1399 | hasError = kTRUE; | |
1400 | ||
1401 | gSystem->Sleep(1000); | |
1402 | } | |
be48e3ea | 1403 | } |
1404 | } | |
1405 | ||
c88ad5db | 1406 | Log("SHUTTLE", Form("Process - In parent process of %d - %s: Client has terminated.", |
be48e3ea | 1407 | GetCurrentRun(), aDetector->GetName())); |
1408 | ||
1409 | if (WIFEXITED(status)) | |
1410 | { | |
1411 | Int_t returnCode = WEXITSTATUS(status); | |
1412 | ||
c88ad5db | 1413 | Log("SHUTTLE", Form("Process - %s: the return code is %d", fCurrentDetector.Data(), |
3301427a | 1414 | returnCode)); |
be48e3ea | 1415 | |
9827400b | 1416 | if (returnCode == 0) hasError = kTRUE; |
be48e3ea | 1417 | } |
1418 | } | |
1419 | else if (pid == 0) | |
1420 | { | |
1421 | // client | |
c88ad5db | 1422 | Log("SHUTTLE", Form("Process - In client process of %d - %s", GetCurrentRun(), |
1423 | aDetector->GetName())); | |
be48e3ea | 1424 | |
c88ad5db | 1425 | Log("SHUTTLE", Form("Process - Redirecting output to %s log",fCurrentDetector.Data())); |
ffa29e93 | 1426 | |
546242fb | 1427 | if ((freopen(GetLogFileName(fCurrentDetector), "a", stdout)) == 0) |
ffa29e93 | 1428 | { |
c88ad5db | 1429 | Log("SHUTTLE", "Process - Could not freopen stdout"); |
ffa29e93 | 1430 | } |
1431 | else | |
1432 | { | |
1433 | fOutputRedirected = kTRUE; | |
1434 | if ((dup2(fileno(stdout), fileno(stderr))) < 0) | |
c88ad5db | 1435 | Log("SHUTTLE", "Process - Could not redirect stderr"); |
ffa29e93 | 1436 | |
1437 | } | |
1438 | ||
5bac2bde | 1439 | TString wd = gSystem->WorkingDirectory(); |
675f64cd | 1440 | TString tmpDir = Form("%s/%s_%d_process", GetShuttleTempDir(), |
1441 | fCurrentDetector.Data(), GetCurrentRun()); | |
5bac2bde | 1442 | |
d524ade6 | 1443 | Int_t result = gSystem->GetPathInfo(tmpDir.Data(), 0, (Long64_t*) 0, 0, 0); |
1444 | if (!result) // temp dir already exists! | |
1445 | { | |
1446 | Log(fCurrentDetector.Data(), | |
1447 | Form("Process - %s dir already exists! Removing...", tmpDir.Data())); | |
1448 | gSystem->Exec(Form("rm -rf %s",tmpDir.Data())); | |
675f64cd | 1449 | } |
1450 | ||
1451 | if (gSystem->mkdir(tmpDir.Data(), 1)) | |
1452 | { | |
1453 | Log(fCurrentDetector.Data(), "Process - could not make temp directory!!"); | |
1454 | gSystem->Exit(1); | |
d524ade6 | 1455 | } |
1456 | ||
1457 | if (!gSystem->ChangeDirectory(tmpDir.Data())) | |
1458 | { | |
1459 | Log(fCurrentDetector.Data(), "Process - could not change directory!!"); | |
1460 | gSystem->Exit(1); | |
1461 | } | |
5bac2bde | 1462 | |
ffa25f20 | 1463 | Int_t success = ProcessCurrentDetector(); |
5bac2bde | 1464 | |
1465 | gSystem->ChangeDirectory(wd.Data()); | |
b1d18693 | 1466 | |
ffa25f20 | 1467 | if (success == 1) // Preprocessor finished successfully! |
9827400b | 1468 | { |
fb40ead4 | 1469 | // remove temporary folder or DCS map |
1470 | if (!fConfig->KeepTempFolder()) | |
1471 | { | |
1472 | gSystem->Exec(Form("rm -rf %s",tmpDir.Data())); | |
1473 | } else if (!fConfig->KeepDCSMap()) | |
1474 | { | |
1475 | gSystem->Exec(Form("rm -f %s/DCSMap.root",tmpDir.Data())); | |
1476 | } | |
b1d18693 | 1477 | |
3301427a | 1478 | // Update time_processed field in FXS DB |
1479 | if (UpdateTable() == kFALSE) | |
5bac2bde | 1480 | Log("SHUTTLE", Form("Process - %s: Could not update FXS databases!", |
1481 | fCurrentDetector.Data())); | |
3301427a | 1482 | |
1483 | // Transfer the data from local storage to main storage (Grid) | |
3301427a | 1484 | if (StoreOCDB() == kFALSE) |
9827400b | 1485 | success = kFALSE; |
5e993b6f | 1486 | } |
ffa25f20 | 1487 | else if (success == 0) |
c88ad5db | 1488 | { |
1489 | Log("SHUTTLE", | |
1490 | Form("\t\t\t****** run %d - %s: PP ERROR ******", | |
1491 | GetCurrentRun(), aDetector->GetName())); | |
be48e3ea | 1492 | } |
1493 | ||
4b95672b | 1494 | for (UInt_t iSys=0; iSys<3; iSys++) |
1495 | { | |
1496 | if (fFXSCalled[iSys]) fFXSlist[iSys].Clear(); | |
1497 | } | |
1498 | ||
c88ad5db | 1499 | Log("SHUTTLE", Form("Process - Client process of %d - %s is exiting now with %d.", |
9827400b | 1500 | GetCurrentRun(), aDetector->GetName(), success)); |
be48e3ea | 1501 | |
1502 | // the client exits here | |
9827400b | 1503 | gSystem->Exit(success); |
be48e3ea | 1504 | |
1505 | AliError("We should never get here!!!"); | |
1506 | } | |
7bfb2090 | 1507 | } |
5164a766 | 1508 | |
c88ad5db | 1509 | Log("SHUTTLE", Form("\t\t\t^*^*^*^*^*^*^*^*^*^*^*^* run %d: FINISH ^*^*^*^*^*^*^*^*^*^*^*^*", |
2bb7b766 | 1510 | GetCurrentRun())); |
1511 | ||
1512 | //check if shuttle is done for this run, if so update logbook | |
1513 | TObjArray checkEntryArray; | |
1514 | checkEntryArray.SetOwner(1); | |
9e080f92 | 1515 | TString whereClause = Form("where run=%d", GetCurrentRun()); |
b0e53b15 | 1516 | if (!QueryShuttleLogbook(whereClause.Data(), checkEntryArray) || |
1517 | checkEntryArray.GetEntries() == 0) { | |
9e080f92 | 1518 | Log("SHUTTLE", Form("Process - Warning: Cannot check status of run %d on Shuttle logbook!", |
1519 | GetCurrentRun())); | |
1520 | return hasError == kFALSE; | |
1521 | } | |
b948db8d | 1522 | |
9e080f92 | 1523 | AliShuttleLogbookEntry* checkEntry = dynamic_cast<AliShuttleLogbookEntry*> |
1524 | (checkEntryArray.At(0)); | |
2bb7b766 | 1525 | |
9e080f92 | 1526 | if (checkEntry) |
1527 | { | |
1528 | if (checkEntry->IsDone()) | |
be48e3ea | 1529 | { |
9e080f92 | 1530 | Log("SHUTTLE","Process - Shuttle is DONE. Updating logbook"); |
1531 | UpdateShuttleLogbook("shuttle_done"); | |
1532 | } | |
1533 | else | |
1534 | { | |
1535 | for (UInt_t iDet=0; iDet<NDetectors(); iDet++) | |
be48e3ea | 1536 | { |
9e080f92 | 1537 | if (checkEntry->GetDetectorStatus(iDet) == AliShuttleLogbookEntry::kUnprocessed) |
be48e3ea | 1538 | { |
9e080f92 | 1539 | AliDebug(2, Form("Run %d: setting %s as \"not first time unprocessed\"", |
1540 | checkEntry->GetRun(), GetDetName(iDet))); | |
1541 | fFirstUnprocessed[iDet] = kFALSE; | |
be48e3ea | 1542 | } |
1543 | } | |
339adafa | 1544 | TMonaLisaText mlStatusPending("SHUTTLE_status", "Pending"); |
1545 | mlList.Clear(); | |
1546 | mlList.Add(&mlStatusPending); | |
1547 | fMonaLisa->SendParameters(&mlList, mlID); | |
2bb7b766 | 1548 | } |
1549 | } | |
1550 | ||
1551 | fLogbookEntry = 0; | |
85a80aa9 | 1552 | |
a7160fe9 | 1553 | return hasError == kFALSE; |
73abe331 | 1554 | } |
1555 | ||
b948db8d | 1556 | //______________________________________________________________________________________________ |
ffa25f20 | 1557 | Int_t AliShuttle::ProcessCurrentDetector() |
73abe331 | 1558 | { |
1559 | // | |
2bb7b766 | 1560 | // Makes data retrieval just for a specific detector (fCurrentDetector). |
73abe331 | 1561 | // Threre should be a configuration for this detector. |
73abe331 | 1562 | |
1d172743 | 1563 | Log("SHUTTLE", Form("ProcessCurrentDetector - Retrieving values for %s, run %d", |
1564 | fCurrentDetector.Data(), GetCurrentRun())); | |
73abe331 | 1565 | |
d524ade6 | 1566 | TString wd = gSystem->WorkingDirectory(); |
1567 | ||
2d9019b4 | 1568 | if (!CleanReferenceStorage(fCurrentDetector.Data())) |
ffa25f20 | 1569 | return 0; |
d524ade6 | 1570 | |
1571 | gSystem->ChangeDirectory(wd.Data()); | |
1572 | ||
3301427a | 1573 | // call preprocessor |
1574 | AliPreprocessor* aPreprocessor = | |
1575 | dynamic_cast<AliPreprocessor*> (fPreprocessorMap.GetValue(fCurrentDetector)); | |
1576 | ||
8579c6fb | 1577 | // check if the preprocessor wants to process this run type |
1578 | if (aPreprocessor->ProcessRunType() == kFALSE) | |
ffa25f20 | 1579 | { |
1580 | UpdateShuttleStatus(AliShuttleStatus::kSkipped); | |
1581 | UpdateShuttleLogbook(fCurrentDetector, "DONE"); | |
1582 | Log(fCurrentDetector, Form("ProcessCurrentDetector - %s preprocessor is not interested in this run type", fCurrentDetector.Data())); | |
1583 | ||
1584 | return 2; | |
1585 | } | |
1586 | ||
1587 | TMap* dcsMap = new TMap(); | |
1588 | ||
3301427a | 1589 | aPreprocessor->Initialize(GetCurrentRun(), GetCurrentStartTime(), GetCurrentEndTime()); |
1590 | ||
1591 | Bool_t processDCS = aPreprocessor->ProcessDCS(); | |
d477ad88 | 1592 | |
651fdaab | 1593 | if (!processDCS) |
1594 | { | |
1d172743 | 1595 | Log(fCurrentDetector, "ProcessCurrentDetector -" |
1596 | " The preprocessor requested to skip the retrieval of DCS values"); | |
651fdaab | 1597 | } |
8b739301 | 1598 | else if (fTestMode & kSkipDCS) |
2c15234c | 1599 | { |
1d172743 | 1600 | Log(fCurrentDetector, "ProcessCurrentDetector - In TESTMODE: Skipping DCS processing"); |
9827400b | 1601 | } |
1602 | else if (fTestMode & kErrorDCS) | |
1603 | { | |
1d172743 | 1604 | Log(fCurrentDetector, "ProcessCurrentDetector - In TESTMODE: Simulating DCS error"); |
3d8bc902 | 1605 | UpdateShuttleStatus(AliShuttleStatus::kDCSStarted); |
9827400b | 1606 | UpdateShuttleStatus(AliShuttleStatus::kDCSError); |
1d172743 | 1607 | delete dcsMap; |
ffa25f20 | 1608 | return 0; |
2c15234c | 1609 | } else { |
3301427a | 1610 | |
1611 | UpdateShuttleStatus(AliShuttleStatus::kDCSStarted); | |
1612 | ||
1d172743 | 1613 | // Query DCS archive |
1614 | Int_t nServers = fConfig->GetNServers(fCurrentDetector); | |
a038aa70 | 1615 | |
1d172743 | 1616 | for (int iServ=0; iServ<nServers; iServ++) |
2c15234c | 1617 | { |
1d172743 | 1618 | |
1619 | TString host(fConfig->GetDCSHost(fCurrentDetector, iServ)); | |
1620 | Int_t port = fConfig->GetDCSPort(fCurrentDetector, iServ); | |
542b6cc8 | 1621 | Int_t multiSplit = fConfig->GetMultiSplit(fCurrentDetector, iServ); |
1622 | ||
1790d4b7 | 1623 | Log(fCurrentDetector, Form("ProcessCurrentDetector -" |
1624 | " Querying DCS Amanda server %s:%d (%d of %d)", | |
1625 | host.Data(), port, iServ+1, nServers)); | |
1d172743 | 1626 | |
1627 | TMap* aliasMap = 0; | |
1628 | TMap* dpMap = 0; | |
1629 | ||
1630 | if (fConfig->GetDCSAliases(fCurrentDetector, iServ)->GetEntries() > 0) | |
2c15234c | 1631 | { |
1d172743 | 1632 | aliasMap = GetValueSet(host, port, |
542b6cc8 | 1633 | fConfig->GetDCSAliases(fCurrentDetector, iServ), |
1634 | kAlias, multiSplit); | |
1d172743 | 1635 | if (!aliasMap) |
1636 | { | |
1637 | Log(fCurrentDetector, | |
1638 | Form("ProcessCurrentDetector -" | |
675f64cd | 1639 | " Error retrieving DCS aliases from server %s." |
1640 | " Sending mail to DCS experts!", host.Data())); | |
1d172743 | 1641 | UpdateShuttleStatus(AliShuttleStatus::kDCSError); |
675f64cd | 1642 | |
339adafa | 1643 | if (!SendMail(kDCSEMail)) |
fb40ead4 | 1644 | Log("SHUTTLE", Form("ProcessCurrentDetector - " |
95d4aaef | 1645 | "Could not send mail to DCS experts!")); |
675f64cd | 1646 | |
a038aa70 | 1647 | delete dcsMap; |
ffa25f20 | 1648 | return 0; |
1d172743 | 1649 | } |
2c15234c | 1650 | } |
a038aa70 | 1651 | |
1d172743 | 1652 | if (fConfig->GetDCSDataPoints(fCurrentDetector, iServ)->GetEntries() > 0) |
a038aa70 | 1653 | { |
1d172743 | 1654 | dpMap = GetValueSet(host, port, |
542b6cc8 | 1655 | fConfig->GetDCSDataPoints(fCurrentDetector, iServ), |
1656 | kDP, multiSplit); | |
1d172743 | 1657 | if (!dpMap) |
1658 | { | |
1659 | Log(fCurrentDetector, | |
1660 | Form("ProcessCurrentDetector -" | |
675f64cd | 1661 | " Error retrieving DCS data points from server %s." |
1662 | " Sending mail to DCS experts!", host.Data())); | |
1d172743 | 1663 | UpdateShuttleStatus(AliShuttleStatus::kDCSError); |
675f64cd | 1664 | |
339adafa | 1665 | if (!SendMail(kDCSEMail)) |
fb40ead4 | 1666 | Log("SHUTTLE", Form("ProcessCurrentDetector - " |
95d4aaef | 1667 | "Could not send mail to DCS experts!")); |
675f64cd | 1668 | |
1d172743 | 1669 | if (aliasMap) delete aliasMap; |
1670 | delete dcsMap; | |
ffa25f20 | 1671 | return 0; |
1d172743 | 1672 | } |
a038aa70 | 1673 | } |
1d172743 | 1674 | |
1675 | // merge aliasMap and dpMap into dcsMap | |
1676 | if(aliasMap) { | |
1677 | TIter iter(aliasMap); | |
a038aa70 | 1678 | TObjString* key = 0; |
1679 | while ((key = (TObjString*) iter.Next())) | |
1d172743 | 1680 | dcsMap->Add(key, aliasMap->GetValue(key->String())); |
1681 | ||
1682 | aliasMap->SetOwner(kFALSE); | |
1683 | delete aliasMap; | |
1684 | } | |
1685 | ||
1686 | if(dpMap) { | |
1687 | TIter iter(dpMap); | |
1688 | TObjString* key = 0; | |
1689 | while ((key = (TObjString*) iter.Next())) | |
1690 | dcsMap->Add(key, dpMap->GetValue(key->String())); | |
1691 | ||
1692 | dpMap->SetOwner(kFALSE); | |
1693 | delete dpMap; | |
a038aa70 | 1694 | } |
73abe331 | 1695 | } |
1696 | } | |
dc25836b | 1697 | |
b1d18693 | 1698 | // save map into file, to help debugging in case of preprocessor error |
fbc112e3 | 1699 | TFile* f = TFile::Open("DCSMap.root","recreate"); |
b1d18693 | 1700 | f->cd(); |
1701 | dcsMap->Write("DCSMap", TObject::kSingleKey); | |
1702 | f->Close(); | |
fbc112e3 | 1703 | delete f; |
b1d18693 | 1704 | |
2bb7b766 | 1705 | // DCS Archive DB processing successful. Call Preprocessor! |
85a80aa9 | 1706 | UpdateShuttleStatus(AliShuttleStatus::kPPStarted); |
a7160fe9 | 1707 | |
339adafa | 1708 | fFXSError = -1; // this variable is kTRUE after ::Process if an FXS error occured |
8da81210 | 1709 | |
a038aa70 | 1710 | UInt_t returnValue = aPreprocessor->Process(dcsMap); |
8da81210 | 1711 | |
339adafa | 1712 | if (fFXSError!=-1) { |
8da81210 | 1713 | UpdateShuttleStatus(AliShuttleStatus::kFXSError); |
339adafa | 1714 | SendMail(kFXSEMail, fFXSError); |
8da81210 | 1715 | dcsMap->DeleteAll(); |
1716 | delete dcsMap; | |
ffa25f20 | 1717 | return 0; |
8da81210 | 1718 | } |
b948db8d | 1719 | |
3301427a | 1720 | if (returnValue > 0) // Preprocessor error! |
1721 | { | |
c88ad5db | 1722 | Log(fCurrentDetector, Form("ProcessCurrentDetector - " |
1723 | "Preprocessor failed. Process returned %d.", returnValue)); | |
cb343cfd | 1724 | UpdateShuttleStatus(AliShuttleStatus::kPPError); |
a038aa70 | 1725 | dcsMap->DeleteAll(); |
1726 | delete dcsMap; | |
ffa25f20 | 1727 | return 0; |
9827400b | 1728 | } |
1729 | ||
1730 | // preprocessor ok! | |
1731 | UpdateShuttleStatus(AliShuttleStatus::kPPDone); | |
1732 | Log(fCurrentDetector, Form("ProcessCurrentDetector - %s preprocessor returned success", | |
1733 | fCurrentDetector.Data())); | |
b948db8d | 1734 | |
a038aa70 | 1735 | dcsMap->DeleteAll(); |
1736 | delete dcsMap; | |
b948db8d | 1737 | |
ffa25f20 | 1738 | return 1; |
2bb7b766 | 1739 | } |
1740 | ||
fbc112e3 | 1741 | //______________________________________________________________________________________________ |
1742 | void AliShuttle::CountOpenRuns() | |
1743 | { | |
1744 | // Query DAQ's Shuttle logbook and sends the number of open runs to ML | |
1745 | ||
1746 | // check connection, in case connect | |
1747 | if (!Connect(3)) | |
1748 | return; | |
1749 | ||
1750 | TString sqlQuery; | |
1751 | sqlQuery = Form("select count(*) from %s where shuttle_done=0", fConfig->GetShuttlelbTable()); | |
1752 | ||
1753 | TSQLResult* aResult = fServer[3]->Query(sqlQuery); | |
1754 | if (!aResult) { | |
1755 | AliError(Form("Can't execute query <%s>!", sqlQuery.Data())); | |
1756 | return; | |
1757 | } | |
1758 | ||
1759 | AliDebug(2,Form("Query = %s", sqlQuery.Data())); | |
1760 | ||
1761 | if (aResult->GetRowCount() == 0) { | |
1762 | AliError(Form("No result for query %s received", sqlQuery.Data())); | |
1763 | return; | |
1764 | } | |
1765 | ||
1766 | if (aResult->GetFieldCount() != 1) { | |
1767 | AliError(Form("Invalid field count for query %s received", sqlQuery.Data())); | |
1768 | return; | |
1769 | } | |
1770 | ||
1771 | TSQLRow* aRow = aResult->Next(); | |
1772 | if (!aRow) { | |
1773 | AliError(Form("Could not receive result of query %s", sqlQuery.Data())); | |
1774 | return; | |
1775 | } | |
1776 | ||
1777 | TString result(aRow->GetField(0), aRow->GetFieldLength(0)); | |
1778 | Int_t count = result.Atoi(); | |
1779 | ||
1780 | Log("SHUTTLE", Form("%d unprocessed runs", count)); | |
1781 | ||
1782 | delete aRow; | |
1783 | delete aResult; | |
1784 | ||
1785 | TMonaLisaValue mlStatus("SHUTTLE_openruns", count); | |
1786 | ||
1787 | TList mlList; | |
1788 | mlList.Add(&mlStatus); | |
1789 | ||
1790 | fMonaLisa->SendParameters(&mlList, "__PROCESSINGINFO__"); | |
1791 | } | |
1792 | ||
2bb7b766 | 1793 | //______________________________________________________________________________________________ |
1794 | Bool_t AliShuttle::QueryShuttleLogbook(const char* whereClause, | |
1795 | TObjArray& entries) | |
1796 | { | |
9827400b | 1797 | // Query DAQ's Shuttle logbook and fills detector status object. |
1798 | // Call QueryRunParameters to query DAQ logbook for run parameters. | |
1799 | // | |
2bb7b766 | 1800 | |
fc5a4708 | 1801 | entries.SetOwner(1); |
1802 | ||
2bb7b766 | 1803 | // check connection, in case connect |
fbc112e3 | 1804 | if (!Connect(3)) return kFALSE; |
2bb7b766 | 1805 | |
1806 | TString sqlQuery; | |
441b0e9c | 1807 | sqlQuery = Form("select * from %s %s order by run", fConfig->GetShuttlelbTable(), whereClause); |
2bb7b766 | 1808 | |
be48e3ea | 1809 | TSQLResult* aResult = fServer[3]->Query(sqlQuery); |
2bb7b766 | 1810 | if (!aResult) { |
1811 | AliError(Form("Can't execute query <%s>!", sqlQuery.Data())); | |
1812 | return kFALSE; | |
1813 | } | |
1814 | ||
fc5a4708 | 1815 | AliDebug(2,Form("Query = %s", sqlQuery.Data())); |
1816 | ||
2bb7b766 | 1817 | if(aResult->GetRowCount() == 0) { |
c88ad5db | 1818 | Log("SHUTTLE", "No entries in Shuttle Logbook match request"); |
9827400b | 1819 | delete aResult; |
1820 | return kTRUE; | |
2bb7b766 | 1821 | } |
1822 | ||
1823 | // TODO Check field count! | |
db99d43e | 1824 | const UInt_t nCols = 23; |
2bb7b766 | 1825 | if (aResult->GetFieldCount() != (Int_t) nCols) { |
c88ad5db | 1826 | Log("SHUTTLE", "Invalid SQL result field number!"); |
2bb7b766 | 1827 | delete aResult; |
1828 | return kFALSE; | |
1829 | } | |
1830 | ||
2bb7b766 | 1831 | TSQLRow* aRow; |
1832 | while ((aRow = aResult->Next())) { | |
1833 | TString runString(aRow->GetField(0), aRow->GetFieldLength(0)); | |
1834 | Int_t run = runString.Atoi(); | |
1835 | ||
eba76848 | 1836 | AliShuttleLogbookEntry *entry = QueryRunParameters(run); |
1837 | if (!entry) | |
1838 | continue; | |
2bb7b766 | 1839 | |
1840 | // loop on detectors | |
eba76848 | 1841 | for(UInt_t ii = 0; ii < nCols; ii++) |
1842 | entry->SetDetectorStatus(aResult->GetFieldName(ii), aRow->GetField(ii)); | |
2bb7b766 | 1843 | |
eba76848 | 1844 | entries.AddLast(entry); |
2bb7b766 | 1845 | delete aRow; |
1846 | } | |
1847 | ||
2bb7b766 | 1848 | delete aResult; |
1849 | return kTRUE; | |
1850 | } | |
1851 | ||
1852 | //______________________________________________________________________________________________ | |
eba76848 | 1853 | AliShuttleLogbookEntry* AliShuttle::QueryRunParameters(Int_t run) |
2bb7b766 | 1854 | { |
eba76848 | 1855 | // |
1856 | // Retrieve run parameters written in the DAQ logbook and sets them into AliShuttleLogbookEntry object | |
1857 | // | |
2bb7b766 | 1858 | |
1859 | // check connection, in case connect | |
be48e3ea | 1860 | if (!Connect(3)) |
eba76848 | 1861 | return 0; |
2bb7b766 | 1862 | |
1863 | TString sqlQuery; | |
2c15234c | 1864 | sqlQuery.Form("select * from %s where run=%d", fConfig->GetDAQlbTable(), run); |
2bb7b766 | 1865 | |
be48e3ea | 1866 | TSQLResult* aResult = fServer[3]->Query(sqlQuery); |
2bb7b766 | 1867 | if (!aResult) { |
c88ad5db | 1868 | Log("SHUTTLE", Form("Can't execute query <%s>!", sqlQuery.Data())); |
eba76848 | 1869 | return 0; |
2bb7b766 | 1870 | } |
1871 | ||
eba76848 | 1872 | if (aResult->GetRowCount() == 0) { |
2bb7b766 | 1873 | Log("SHUTTLE", Form("QueryRunParameters - No entry in DAQ Logbook for run %d. Skipping", run)); |
1874 | delete aResult; | |
eba76848 | 1875 | return 0; |
2bb7b766 | 1876 | } |
1877 | ||
eba76848 | 1878 | if (aResult->GetRowCount() > 1) { |
c88ad5db | 1879 | Log("SHUTTLE", Form("QueryRunParameters - UNEXPECTED: " |
1880 | "more than one entry in DAQ Logbook for run %d!", run)); | |
2bb7b766 | 1881 | delete aResult; |
eba76848 | 1882 | return 0; |
2bb7b766 | 1883 | } |
1884 | ||
eba76848 | 1885 | TSQLRow* aRow = aResult->Next(); |
1886 | if (!aRow) | |
1887 | { | |
c88ad5db | 1888 | Log("SHUTTLE", Form("QueryRunParameters - Could not retrieve row for run %d. Skipping", run)); |
eba76848 | 1889 | delete aResult; |
1890 | return 0; | |
1891 | } | |
2bb7b766 | 1892 | |
eba76848 | 1893 | AliShuttleLogbookEntry* entry = new AliShuttleLogbookEntry(run); |
2bb7b766 | 1894 | |
eba76848 | 1895 | for (Int_t ii = 0; ii < aResult->GetFieldCount(); ii++) |
1896 | entry->SetRunParameter(aResult->GetFieldName(ii), aRow->GetField(ii)); | |
2bb7b766 | 1897 | |
eba76848 | 1898 | UInt_t startTime = entry->GetStartTime(); |
1899 | UInt_t endTime = entry->GetEndTime(); | |
1900 | ||
ffa25f20 | 1901 | // the conditions under which runs are marked as done and not processed are not clear currently |
1902 | // for the moment no runs are marked as done | |
1abfbb60 | 1903 | // if (!startTime || !endTime || startTime > endTime) |
1904 | // { | |
1905 | // Log("SHUTTLE", | |
1906 | // Form("QueryRunParameters - Invalid parameters for Run %d: startTime = %d, endTime = %d. Skipping!", | |
1907 | // run, startTime, endTime)); | |
1908 | // | |
1909 | // Log("SHUTTLE", Form("Marking SHUTTLE done for run %d", run)); | |
1910 | // fLogbookEntry = entry; | |
1911 | // if (!UpdateShuttleLogbook("shuttle_done")) | |
1912 | // { | |
1913 | // AliError(Form("Could not update logbook for run %d !", run)); | |
1914 | // } | |
1915 | // fLogbookEntry = 0; | |
1916 | // | |
1917 | // delete entry; | |
1918 | // delete aRow; | |
1919 | // delete aResult; | |
1920 | // return 0; | |
1921 | // } | |
1922 | ||
ffa25f20 | 1923 | // if (!startTime) |
1924 | // { | |
1925 | // Log("SHUTTLE", | |
1926 | // Form("QueryRunParameters - Invalid parameters for Run %d: " | |
1927 | // "startTime = %d, endTime = %d. Skipping!", | |
1928 | // run, startTime, endTime)); | |
1929 | // | |
1930 | // Log("SHUTTLE", Form("Marking SHUTTLE done for run %d", run)); | |
1931 | // fLogbookEntry = entry; | |
1932 | // if (!UpdateShuttleLogbook("shuttle_ignored")) | |
1933 | // { | |
1934 | // AliError(Form("Could not update logbook for run %d !", run)); | |
1935 | // } | |
1936 | // fLogbookEntry = 0; | |
1937 | // | |
1938 | // delete entry; | |
1939 | // delete aRow; | |
1940 | // delete aResult; | |
1941 | // return 0; | |
1942 | // } | |
b0e53b15 | 1943 | |
1abfbb60 | 1944 | if (startTime && !endTime) |
1945 | { | |
1946 | // TODO Here we don't mark SHUTTLE done, because this may mean | |
1947 | //the run is still ongoing!! | |
1948 | Log("SHUTTLE", | |
1949 | Form("QueryRunParameters - Invalid parameters for Run %d: " | |
1950 | "startTime = %d, endTime = %d. Skipping (Shuttle won't be marked as DONE)!", | |
1951 | run, startTime, endTime)); | |
1952 | ||
1953 | //Log("SHUTTLE", Form("Marking SHUTTLE done for run %d", run)); | |
1954 | //fLogbookEntry = entry; | |
1955 | //if (!UpdateShuttleLogbook("shuttle_done")) | |
1956 | //{ | |
1957 | // AliError(Form("Could not update logbook for run %d !", run)); | |
1958 | //} | |
1959 | //fLogbookEntry = 0; | |
1960 | ||
1961 | delete entry; | |
1962 | delete aRow; | |
1963 | delete aResult; | |
1964 | return 0; | |
1965 | } | |
1966 | ||
1967 | if (startTime && endTime && (startTime > endTime)) | |
1968 | { | |
1969 | Log("SHUTTLE", | |
1970 | Form("QueryRunParameters - Invalid parameters for Run %d: " | |
1971 | "startTime = %d, endTime = %d. Skipping!", | |
1972 | run, startTime, endTime)); | |
1973 | ||
1974 | Log("SHUTTLE", Form("Marking SHUTTLE done for run %d", run)); | |
1975 | fLogbookEntry = entry; | |
ee6f7523 | 1976 | if (!UpdateShuttleLogbook("shuttle_ignored")) |
1abfbb60 | 1977 | { |
1978 | AliError(Form("Could not update logbook for run %d !", run)); | |
1979 | } | |
1980 | fLogbookEntry = 0; | |
1981 | ||
1982 | delete entry; | |
1983 | delete aRow; | |
1984 | delete aResult; | |
1985 | return 0; | |
1986 | } | |
1987 | ||
b0e53b15 | 1988 | TString totEventsStr = entry->GetRunParameter("totalEvents"); |
1989 | Int_t totEvents = totEventsStr.Atoi(); | |
1990 | if (totEvents < 1) | |
1991 | { | |
eba76848 | 1992 | Log("SHUTTLE", |
b0e53b15 | 1993 | Form("QueryRunParameters - Run %d has 0 events - Skipping!", run)); |
1994 | ||
1995 | Log("SHUTTLE", Form("Marking SHUTTLE done for run %d", run)); | |
1996 | fLogbookEntry = entry; | |
97e3c167 | 1997 | if (!UpdateShuttleLogbook("shuttle_ignored")) |
b0e53b15 | 1998 | { |
1999 | AliError(Form("Could not update logbook for run %d !", run)); | |
2000 | } | |
2001 | fLogbookEntry = 0; | |
2002 | ||
eba76848 | 2003 | delete entry; |
2bb7b766 | 2004 | delete aRow; |
eba76848 | 2005 | delete aResult; |
2006 | return 0; | |
2bb7b766 | 2007 | } |
2008 | ||
eba76848 | 2009 | delete aRow; |
2bb7b766 | 2010 | delete aResult; |
eba76848 | 2011 | |
2012 | return entry; | |
2bb7b766 | 2013 | } |
2014 | ||
a038aa70 | 2015 | //______________________________________________________________________________________________ |
2016 | TMap* AliShuttle::GetValueSet(const char* host, Int_t port, const TSeqCollection* entries, | |
542b6cc8 | 2017 | DCSType type, Int_t multiSplit) |
a038aa70 | 2018 | { |
2019 | // Retrieve all "entry" data points from the DCS server | |
2020 | // host, port: TSocket connection parameters | |
2021 | // entries: list of name of the alias or data point | |
2022 | // type: kAlias or kDP | |
2023 | // returns TMap of values, 0 when failure | |
542b6cc8 | 2024 | |
2025 | AliDCSClient client(host, port, fTimeout, fRetries, multiSplit); | |
b41b252a | 2026 | |
a038aa70 | 2027 | TMap* result = 0; |
b41b252a | 2028 | if (type == kAlias) |
a038aa70 | 2029 | { |
b41b252a | 2030 | result = client.GetAliasValues(entries, GetCurrentStartTime(), |
2031 | GetCurrentEndTime()); | |
2032 | } | |
2033 | else if (type == kDP) | |
2034 | { | |
2035 | result = client.GetDPValues(entries, GetCurrentStartTime(), | |
2036 | GetCurrentEndTime()); | |
2037 | } | |
a038aa70 | 2038 | |
b41b252a | 2039 | if (result == 0) |
2040 | { | |
2041 | Log(fCurrentDetector.Data(), Form("GetValueSet - Can't get entries! Reason: %s", | |
1790d4b7 | 2042 | client.GetErrorString(client.GetResultErrorCode()))); |
2043 | if (client.GetResultErrorCode() == AliDCSClient::fgkServerError) | |
2044 | Log(fCurrentDetector.Data(), Form("GetValueSet - Server error code: %s", | |
2045 | client.GetServerError().Data())); | |
a038aa70 | 2046 | |
b41b252a | 2047 | return 0; |
a038aa70 | 2048 | } |
b41b252a | 2049 | |
a038aa70 | 2050 | return result; |
2051 | } | |
b41b252a | 2052 | |
b948db8d | 2053 | //______________________________________________________________________________________________ |
57f50b3c | 2054 | const char* AliShuttle::GetFile(Int_t system, const char* detector, |
2055 | const char* id, const char* source) | |
b948db8d | 2056 | { |
9827400b | 2057 | // Get calibration file from file exchange servers |
2058 | // First queris the FXS database for the file name, using the run, detector, id and source info | |
2059 | // then calls RetrieveFile(filename) for actual copy to local disk | |
2060 | // run: current run being processed (given by Logbook entry fLogbookEntry) | |
2061 | // detector: the Preprocessor name | |
2062 | // id: provided as a parameter by the Preprocessor | |
2063 | // source: provided by the Preprocessor through GetFileSources function | |
2064 | ||
2065 | // check if test mode should simulate a FXS error | |
2066 | if (fTestMode & kErrorFXSFiles) | |
2067 | { | |
2068 | Log(detector, Form("GetFile - In TESTMODE - Simulating error while connecting to %s FXS", GetSystemName(system))); | |
2069 | return 0; | |
2070 | } | |
2071 | ||
57f50b3c | 2072 | // check connection, in case connect |
9d733021 | 2073 | if (!Connect(system)) |
eba76848 | 2074 | { |
9d733021 | 2075 | Log(detector, Form("GetFile - Couldn't connect to %s FXS database", GetSystemName(system))); |
339adafa | 2076 | fFXSError = system; |
57f50b3c | 2077 | return 0; |
2078 | } | |
2079 | ||
2080 | // Query preparation | |
9d733021 | 2081 | TString sourceName(source); |
d386d623 | 2082 | Int_t nFields = 3; |
2083 | TString sqlQueryStart = Form("select filePath,size,fileChecksum from %s where", | |
2084 | fConfig->GetFXSdbTable(system)); | |
2085 | TString whereClause = Form("run=%d and detector=\"%s\" and fileId=\"%s\"", | |
2086 | GetCurrentRun(), detector, id); | |
2087 | ||
9d733021 | 2088 | if (system == kDAQ) |
2089 | { | |
d386d623 | 2090 | whereClause += Form(" and DAQsource=\"%s\"", source); |
57f50b3c | 2091 | } |
9d733021 | 2092 | else if (system == kDCS) |
eba76848 | 2093 | { |
9d733021 | 2094 | sourceName="none"; |
57f50b3c | 2095 | } |
9d733021 | 2096 | else if (system == kHLT) |
9e080f92 | 2097 | { |
d386d623 | 2098 | whereClause += Form(" and DDLnumbers=\"%s\"", source); |
9e080f92 | 2099 | } |
2100 | ||
9e080f92 | 2101 | TString sqlQuery = Form("%s %s", sqlQueryStart.Data(), whereClause.Data()); |
2102 | ||
2103 | AliDebug(2, Form("SQL query: \n%s",sqlQuery.Data())); | |
2104 | ||
2105 | // Query execution | |
2106 | TSQLResult* aResult = 0; | |
9d733021 | 2107 | aResult = dynamic_cast<TSQLResult*> (fServer[system]->Query(sqlQuery)); |
9e080f92 | 2108 | if (!aResult) { |
8da81210 | 2109 | Log(detector, Form("GetFile - Can't execute SQL query to %s database for: id = %s, source = %s", |
9d733021 | 2110 | GetSystemName(system), id, sourceName.Data())); |
339adafa | 2111 | fFXSError = system; |
9e080f92 | 2112 | return 0; |
2113 | } | |
2114 | ||
8da81210 | 2115 | if (aResult->GetRowCount() == 0) |
9e080f92 | 2116 | { |
2117 | Log(detector, | |
8da81210 | 2118 | Form("GetFile - No entry in %s FXS db for: id = %s, source = %s", |
9d733021 | 2119 | GetSystemName(system), id, sourceName.Data())); |
9e080f92 | 2120 | delete aResult; |
2121 | return 0; | |
2122 | } | |
2bb7b766 | 2123 | |
9e080f92 | 2124 | if (aResult->GetRowCount() > 1) { |
2125 | Log(detector, | |
8da81210 | 2126 | Form("GetFile - More than one entry in %s FXS db for: id = %s, source = %s", |
9d733021 | 2127 | GetSystemName(system), id, sourceName.Data())); |
339adafa | 2128 | fFXSError = system; |
9e080f92 | 2129 | delete aResult; |
2130 | return 0; | |
2131 | } | |
2132 | ||
9d733021 | 2133 | if (aResult->GetFieldCount() != nFields) { |
9e080f92 | 2134 | Log(detector, |
9d733021 | 2135 | Form("GetFileName - Wrong field count in %s FXS db for: id = %s, source = %s", |
2136 | GetSystemName(system), id, sourceName.Data())); | |
339adafa | 2137 | fFXSError = system; |
9e080f92 | 2138 | delete aResult; |
2139 | return 0; | |
2140 | } | |
2141 | ||
2142 | TSQLRow* aRow = dynamic_cast<TSQLRow*> (aResult->Next()); | |
2143 | ||
2144 | if (!aRow){ | |
8da81210 | 2145 | Log(detector, Form("GetFile - Empty set result in %s FXS db from query: id = %s, source = %s", |
9d733021 | 2146 | GetSystemName(system), id, sourceName.Data())); |
339adafa | 2147 | fFXSError = system; |
9e080f92 | 2148 | delete aResult; |
2149 | return 0; | |
2150 | } | |
2151 | ||
2152 | TString filePath(aRow->GetField(0), aRow->GetFieldLength(0)); | |
2153 | TString fileSize(aRow->GetField(1), aRow->GetFieldLength(1)); | |
d386d623 | 2154 | TString fileChecksum(aRow->GetField(2), aRow->GetFieldLength(2)); |
9e080f92 | 2155 | |
2156 | delete aResult; | |
2157 | delete aRow; | |
2158 | ||
d386d623 | 2159 | AliDebug(2, Form("filePath = %s; size = %s, fileChecksum = %s", |
2160 | filePath.Data(), fileSize.Data(), fileChecksum.Data())); | |
9e080f92 | 2161 | |
9e080f92 | 2162 | // retrieved file is renamed to make it unique |
675f64cd | 2163 | TString localFileName = Form("%s/%s_%d_process/%s_%s_%d_%s_%s.shuttle", |
2164 | GetShuttleTempDir(), detector, GetCurrentRun(), | |
d524ade6 | 2165 | GetSystemName(system), detector, GetCurrentRun(), |
2166 | id, sourceName.Data()); | |
9d733021 | 2167 | |
9e080f92 | 2168 | |
9d733021 | 2169 | // file retrieval from FXS |
4b95672b | 2170 | UInt_t nRetries = 0; |
2171 | UInt_t maxRetries = 3; | |
2172 | Bool_t result = kFALSE; | |
2173 | ||
2174 | // copy!! if successful TSystem::Exec returns 0 | |
8da81210 | 2175 | while (nRetries++ < maxRetries) { |
4b95672b | 2176 | AliDebug(2, Form("Trying to copy file. Retry # %d", nRetries)); |
2177 | result = RetrieveFile(system, filePath.Data(), localFileName.Data()); | |
8da81210 | 2178 | if (!result) |
4b95672b | 2179 | { |
8da81210 | 2180 | Log(detector, Form("GetFile - Copy of file %s from %s FXS failed", |
9d733021 | 2181 | filePath.Data(), GetSystemName(system))); |
4b95672b | 2182 | continue; |
4f0749a8 | 2183 | } |
9e080f92 | 2184 | |
c98417a1 | 2185 | if (fileSize.Length()>0) |
2186 | { | |
2187 | // compare filesize of local file with the one stored in the FXS DB | |
926cbc0e | 2188 | Long_t size = -1; |
2189 | Int_t sizeComp = gSystem->GetPathInfo(localFileName.Data(), 0, &size, 0, 0); | |
c98417a1 | 2190 | |
926cbc0e | 2191 | if (sizeComp != 0 || size != fileSize.Atoi()) |
c98417a1 | 2192 | { |
8da81210 | 2193 | Log(detector, Form("GetFile - size of file %s does not match with local copy!", |
c98417a1 | 2194 | filePath.Data())); |
2195 | result = kFALSE; | |
2196 | continue; | |
2197 | } | |
2198 | ||
2199 | } else { | |
2200 | Log(fCurrentDetector, Form("GetFile - size of file %s not set in %s database, skipping comparison", | |
2201 | filePath.Data(), GetSystemName(system))); | |
2202 | } | |
2203 | ||
d386d623 | 2204 | if (fileChecksum.Length()>0) |
4b95672b | 2205 | { |
2206 | // compare md5sum of local file with the one stored in the FXS DB | |
95d4aaef | 2207 | if(fileChecksum.Contains(' ')) fileChecksum.Resize(fileChecksum.First(' ')); |
339adafa | 2208 | Int_t md5Comp = gSystem->Exec(Form("md5sum %s |grep %s > /dev/null 2> /dev/null", |
d524ade6 | 2209 | localFileName.Data(), fileChecksum.Data())); |
9e080f92 | 2210 | |
4b95672b | 2211 | if (md5Comp != 0) |
2212 | { | |
8da81210 | 2213 | Log(detector, Form("GetFile - md5sum of file %s does not match with local copy!", |
4b95672b | 2214 | filePath.Data())); |
2215 | result = kFALSE; | |
2216 | continue; | |
2217 | } | |
d386d623 | 2218 | } else { |
2219 | Log(fCurrentDetector, Form("GetFile - md5sum of file %s not set in %s database, skipping comparison", | |
2220 | filePath.Data(), GetSystemName(system))); | |
9d733021 | 2221 | } |
4b95672b | 2222 | if (result) break; |
9e080f92 | 2223 | } |
2224 | ||
8da81210 | 2225 | if (!result) |
2226 | { | |
339adafa | 2227 | fFXSError = system; |
8da81210 | 2228 | return 0; |
2229 | } | |
4b95672b | 2230 | |
9d733021 | 2231 | fFXSCalled[system]=kTRUE; |
2232 | TObjString *fileParams = new TObjString(Form("%s#!?!#%s", id, sourceName.Data())); | |
2233 | fFXSlist[system].Add(fileParams); | |
9e080f92 | 2234 | |
675f64cd | 2235 | static TString staticLocalFileName; |
2236 | staticLocalFileName.Form("%s", localFileName.Data()); | |
2237 | ||
c88ad5db | 2238 | Log(fCurrentDetector, Form("GetFile - Retrieved file with id %s and " |
2239 | "source %s from %s to %s", id, source, | |
d524ade6 | 2240 | GetSystemName(system), localFileName.Data())); |
675f64cd | 2241 | |
d524ade6 | 2242 | return staticLocalFileName.Data(); |
2bb7b766 | 2243 | } |
2244 | ||
2245 | //______________________________________________________________________________________________ | |
9d733021 | 2246 | Bool_t AliShuttle::RetrieveFile(UInt_t system, const char* fxsFileName, const char* localFileName) |
9e080f92 | 2247 | { |
9827400b | 2248 | // |
2249 | // Copies file from FXS to local Shuttle machine | |
2250 | // | |
2bb7b766 | 2251 | |
9e080f92 | 2252 | // check temp directory: trying to cd to temp; if it does not exist, create it |
d524ade6 | 2253 | AliDebug(2, Form("Copy file %s from %s FXS into %s", |
2254 | GetSystemName(system), fxsFileName, localFileName)); | |
2255 | ||
2256 | TString tmpDir(localFileName); | |
2257 | ||
2258 | tmpDir = tmpDir(0,tmpDir.Last('/')); | |
9e080f92 | 2259 | |
d524ade6 | 2260 | Int_t noDir = gSystem->GetPathInfo(tmpDir.Data(), 0, (Long64_t*) 0, 0, 0); |
2261 | if (noDir) // temp dir does not exists! | |
2262 | { | |
2263 | if (gSystem->mkdir(tmpDir.Data(), 1)) | |
2264 | { | |
2265 | Log(fCurrentDetector.Data(), "RetrieveFile - could not make temp directory!!"); | |
9e080f92 | 2266 | return kFALSE; |
2267 | } | |
9e080f92 | 2268 | } |
2269 | ||
339adafa | 2270 | TString command = Form("scp -oPort=%d -2 %s@%s:%s/%s %s", |
9d733021 | 2271 | fConfig->GetFXSPort(system), |
2272 | fConfig->GetFXSUser(system), | |
2273 | fConfig->GetFXSHost(system), | |
339adafa | 2274 | fConfig->GetFXSBaseFolder(system), |
9d733021 | 2275 | fxsFileName, |
9e080f92 | 2276 | localFileName); |
2277 | ||
2278 | AliDebug(2, Form("%s",command.Data())); | |
2279 | ||
4b95672b | 2280 | Bool_t result = (gSystem->Exec(command.Data()) == 0); |
9e080f92 | 2281 | |
4b95672b | 2282 | return result; |
9e080f92 | 2283 | } |
2284 | ||
2285 | //______________________________________________________________________________________________ | |
9d733021 | 2286 | TList* AliShuttle::GetFileSources(Int_t system, const char* detector, const char* id) |
2287 | { | |
9827400b | 2288 | // |
2289 | // Get sources producing the condition file Id from file exchange servers | |
4a33bdd9 | 2290 | // if id is NULL all sources are returned (distinct) |
9827400b | 2291 | // |
1bcd28db | 2292 | |
8884d71e | 2293 | if (id) |
2294 | { | |
2295 | Log(detector, Form("GetFileSources - Querying %s FXS for files with id %s produced by %s", GetSystemName(system), id, detector)); | |
2296 | } else { | |
2297 | Log(detector, Form("GetFileSources - Querying %s FXS for files produced by %s", GetSystemName(system), detector)); | |
2298 | } | |
9827400b | 2299 | |
2300 | // check if test mode should simulate a FXS error | |
2301 | if (fTestMode & kErrorFXSSources) | |
2302 | { | |
2303 | Log(detector, Form("GetFileSources - In TESTMODE - Simulating error while connecting to %s FXS", GetSystemName(system))); | |
2304 | return 0; | |
2305 | } | |
2306 | ||
9d733021 | 2307 | if (system == kDCS) |
2308 | { | |
c88ad5db | 2309 | Log(detector, "GetFileSources - WARNING: DCS system has only one source of data!"); |
6297b37d | 2310 | TList *list = new TList(); |
2311 | list->SetOwner(1); | |
2312 | list->Add(new TObjString(" ")); | |
2313 | return list; | |
9d733021 | 2314 | } |
9e080f92 | 2315 | |
2316 | // check connection, in case connect | |
9d733021 | 2317 | if (!Connect(system)) |
2318 | { | |
4a33bdd9 | 2319 | Log(detector, Form("GetFileSources - Couldn't connect to %s FXS database", GetSystemName(system))); |
339adafa | 2320 | fFXSError = system; |
9d733021 | 2321 | return NULL; |
9e080f92 | 2322 | } |
2323 | ||
9d733021 | 2324 | TString sourceName = 0; |
2325 | if (system == kDAQ) | |
2326 | { | |
2327 | sourceName = "DAQsource"; | |
2328 | } else if (system == kHLT) | |
2329 | { | |
2330 | sourceName = "DDLnumbers"; | |
2331 | } | |
2332 | ||
4a33bdd9 | 2333 | TString sqlQueryStart = Form("select distinct %s from %s where", sourceName.Data(), fConfig->GetFXSdbTable(system)); |
2334 | TString whereClause = Form("run=%d and detector=\"%s\"", | |
2335 | GetCurrentRun(), detector); | |
2336 | if (id) | |
2337 | whereClause += Form(" and fileId=\"%s\"", id); | |
9e080f92 | 2338 | TString sqlQuery = Form("%s %s", sqlQueryStart.Data(), whereClause.Data()); |
2339 | ||
2340 | AliDebug(2, Form("SQL query: \n%s",sqlQuery.Data())); | |
2341 | ||
2342 | // Query execution | |
2343 | TSQLResult* aResult; | |
9d733021 | 2344 | aResult = fServer[system]->Query(sqlQuery); |
9e080f92 | 2345 | if (!aResult) { |
9d733021 | 2346 | Log(detector, Form("GetFileSources - Can't execute SQL query to %s database for id: %s", |
2347 | GetSystemName(system), id)); | |
339adafa | 2348 | fFXSError = system; |
9e080f92 | 2349 | return 0; |
2350 | } | |
2351 | ||
86aa42c3 | 2352 | TList *list = new TList(); |
2353 | list->SetOwner(1); | |
2354 | ||
9d733021 | 2355 | if (aResult->GetRowCount() == 0) |
2356 | { | |
9e080f92 | 2357 | Log(detector, |
9d733021 | 2358 | Form("GetFileSources - No entry in %s FXS table for id: %s", GetSystemName(system), id)); |
9e080f92 | 2359 | delete aResult; |
86aa42c3 | 2360 | return list; |
9e080f92 | 2361 | } |
2362 | ||
1bcd28db | 2363 | Log(detector, Form("GetFileSources - Found %d sources", aResult->GetRowCount())); |
9e080f92 | 2364 | |
1bcd28db | 2365 | TSQLRow* aRow; |
9d733021 | 2366 | while ((aRow = aResult->Next())) |
2367 | { | |
9e080f92 | 2368 | |
9d733021 | 2369 | TString source(aRow->GetField(0), aRow->GetFieldLength(0)); |
2370 | AliDebug(2, Form("%s = %s", sourceName.Data(), source.Data())); | |
2371 | list->Add(new TObjString(source)); | |
9e080f92 | 2372 | delete aRow; |
2373 | } | |
9d733021 | 2374 | |
9e080f92 | 2375 | delete aResult; |
2376 | ||
2377 | return list; | |
2bb7b766 | 2378 | } |
2379 | ||
4a33bdd9 | 2380 | //______________________________________________________________________________________________ |
2381 | TList* AliShuttle::GetFileIDs(Int_t system, const char* detector, const char* source) | |
2382 | { | |
2383 | // | |
2384 | // Get all ids of condition files produced by a given source from file exchange servers | |
2385 | // | |
2386 | ||
1bcd28db | 2387 | Log(detector, Form("GetFileIDs - Retrieving ids with source %s with %s", source, GetSystemName(system))); |
2388 | ||
4a33bdd9 | 2389 | // check if test mode should simulate a FXS error |
2390 | if (fTestMode & kErrorFXSSources) | |
2391 | { | |
2392 | Log(detector, Form("GetFileIDs - In TESTMODE - Simulating error while connecting to %s FXS", GetSystemName(system))); | |
2393 | return 0; | |
2394 | } | |
2395 | ||
2396 | // check connection, in case connect | |
2397 | if (!Connect(system)) | |
2398 | { | |
2399 | Log(detector, Form("GetFileIDs - Couldn't connect to %s FXS database", GetSystemName(system))); | |
2400 | return NULL; | |
2401 | } | |
2402 | ||
2403 | TString sourceName = 0; | |
2404 | if (system == kDAQ) | |
2405 | { | |
2406 | sourceName = "DAQsource"; | |
2407 | } else if (system == kHLT) | |
2408 | { | |
2409 | sourceName = "DDLnumbers"; | |
2410 | } | |
2411 | ||
2412 | TString sqlQueryStart = Form("select fileId from %s where", fConfig->GetFXSdbTable(system)); | |
2413 | TString whereClause = Form("run=%d and detector=\"%s\"", | |
2414 | GetCurrentRun(), detector); | |
2415 | if (sourceName.Length() > 0 && source) | |
2416 | whereClause += Form(" and %s=\"%s\"", sourceName.Data(), source); | |
2417 | TString sqlQuery = Form("%s %s", sqlQueryStart.Data(), whereClause.Data()); | |
2418 | ||
2419 | AliDebug(2, Form("SQL query: \n%s",sqlQuery.Data())); | |
2420 | ||
2421 | // Query execution | |
2422 | TSQLResult* aResult; | |
2423 | aResult = fServer[system]->Query(sqlQuery); | |
2424 | if (!aResult) { | |
2425 | Log(detector, Form("GetFileIDs - Can't execute SQL query to %s database for source: %s", | |
2426 | GetSystemName(system), source)); | |
2427 | return 0; | |
2428 | } | |
2429 | ||
2430 | TList *list = new TList(); | |
2431 | list->SetOwner(1); | |
2432 | ||
2433 | if (aResult->GetRowCount() == 0) | |
2434 | { | |
2435 | Log(detector, | |
2436 | Form("GetFileIDs - No entry in %s FXS table for source: %s", GetSystemName(system), source)); | |
2437 | delete aResult; | |
2438 | return list; | |
2439 | } | |
2440 | ||
1bcd28db | 2441 | Log(detector, Form("GetFileIDs - Found %d ids", aResult->GetRowCount())); |
2442 | ||
4a33bdd9 | 2443 | TSQLRow* aRow; |
2444 | ||
2445 | while ((aRow = aResult->Next())) | |
2446 | { | |
2447 | ||
2448 | TString id(aRow->GetField(0), aRow->GetFieldLength(0)); | |
2449 | AliDebug(2, Form("fileId = %s", id.Data())); | |
2450 | list->Add(new TObjString(id)); | |
2451 | delete aRow; | |
2452 | } | |
2453 | ||
2454 | delete aResult; | |
2455 | ||
2456 | return list; | |
2457 | } | |
2458 | ||
2bb7b766 | 2459 | //______________________________________________________________________________________________ |
9d733021 | 2460 | Bool_t AliShuttle::Connect(Int_t system) |
2bb7b766 | 2461 | { |
9827400b | 2462 | // Connect to MySQL Server of the system's FXS MySQL databases |
2463 | // DAQ Logbook, Shuttle Logbook and DAQ FXS db are on the same host | |
2464 | // | |
57f50b3c | 2465 | |
9d733021 | 2466 | // check connection: if already connected return |
2467 | if(fServer[system] && fServer[system]->IsConnected()) return kTRUE; | |
57f50b3c | 2468 | |
9d733021 | 2469 | TString dbHost, dbUser, dbPass, dbName; |
57f50b3c | 2470 | |
9d733021 | 2471 | if (system < 3) // FXS db servers |
2472 | { | |
2473 | dbHost = Form("mysql://%s:%d", fConfig->GetFXSdbHost(system), fConfig->GetFXSdbPort(system)); | |
2474 | dbUser = fConfig->GetFXSdbUser(system); | |
2475 | dbPass = fConfig->GetFXSdbPass(system); | |
2476 | dbName = fConfig->GetFXSdbName(system); | |
2477 | } else { // Run & Shuttle logbook servers | |
2478 | // TODO Will the Shuttle logbook server be the same as the Run logbook server ??? | |
2479 | dbHost = Form("mysql://%s:%d", fConfig->GetDAQlbHost(), fConfig->GetDAQlbPort()); | |
2480 | dbUser = fConfig->GetDAQlbUser(); | |
2481 | dbPass = fConfig->GetDAQlbPass(); | |
2482 | dbName = fConfig->GetDAQlbDB(); | |
2483 | } | |
57f50b3c | 2484 | |
9d733021 | 2485 | fServer[system] = TSQLServer::Connect(dbHost.Data(), dbUser.Data(), dbPass.Data()); |
2486 | if (!fServer[system] || !fServer[system]->IsConnected()) { | |
2487 | if(system < 3) | |
2488 | { | |
2489 | AliError(Form("Can't establish connection to FXS database for %s", | |
2490 | AliShuttleInterface::GetSystemName(system))); | |
2491 | } else { | |
2492 | AliError("Can't establish connection to Run logbook."); | |
57f50b3c | 2493 | } |
9d733021 | 2494 | if(fServer[system]) delete fServer[system]; |
2495 | return kFALSE; | |
2bb7b766 | 2496 | } |
57f50b3c | 2497 | |
9d733021 | 2498 | // Get tables |
2499 | TSQLResult* aResult=0; | |
2500 | switch(system){ | |
2501 | case kDAQ: | |
2502 | aResult = fServer[kDAQ]->GetTables(dbName.Data()); | |
2503 | break; | |
2504 | case kDCS: | |
2505 | aResult = fServer[kDCS]->GetTables(dbName.Data()); | |
2506 | break; | |
2507 | case kHLT: | |
2508 | aResult = fServer[kHLT]->GetTables(dbName.Data()); | |
2509 | break; | |
2510 | default: | |
2511 | aResult = fServer[3]->GetTables(dbName.Data()); | |
2512 | break; | |
2513 | } | |
2514 | ||
2515 | delete aResult; | |
2bb7b766 | 2516 | return kTRUE; |
2517 | } | |
57f50b3c | 2518 | |
9e080f92 | 2519 | //______________________________________________________________________________________________ |
9d733021 | 2520 | Bool_t AliShuttle::UpdateTable() |
9e080f92 | 2521 | { |
9827400b | 2522 | // |
2523 | // Update FXS table filling time_processed field in all rows corresponding to current run and detector | |
2524 | // | |
9e080f92 | 2525 | |
9d733021 | 2526 | Bool_t result = kTRUE; |
9e080f92 | 2527 | |
9d733021 | 2528 | for (UInt_t system=0; system<3; system++) |
2529 | { | |
2530 | if(!fFXSCalled[system]) continue; | |
9e080f92 | 2531 | |
9d733021 | 2532 | // check connection, in case connect |
2533 | if (!Connect(system)) | |
2534 | { | |
2535 | Log(fCurrentDetector, Form("UpdateTable - Couldn't connect to %s FXS database", GetSystemName(system))); | |
2536 | result = kFALSE; | |
2537 | continue; | |
9e080f92 | 2538 | } |
9e080f92 | 2539 | |
9d733021 | 2540 | TTimeStamp now; // now |
2541 | ||
2542 | // Loop on FXS list entries | |
2543 | TIter iter(&fFXSlist[system]); | |
2544 | TObjString *aFXSentry=0; | |
2545 | while ((aFXSentry = dynamic_cast<TObjString*> (iter.Next()))) | |
2546 | { | |
2547 | TString aFXSentrystr = aFXSentry->String(); | |
2548 | TObjArray *aFXSarray = aFXSentrystr.Tokenize("#!?!#"); | |
2549 | if (!aFXSarray || aFXSarray->GetEntries() != 2 ) | |
2550 | { | |
2551 | Log(fCurrentDetector, Form("UpdateTable - error updating %s FXS entry. Check string: <%s>", | |
2552 | GetSystemName(system), aFXSentrystr.Data())); | |
2553 | if(aFXSarray) delete aFXSarray; | |
2554 | result = kFALSE; | |
2555 | continue; | |
2556 | } | |
2557 | const char* fileId = ((TObjString*) aFXSarray->At(0))->GetName(); | |
2558 | const char* source = ((TObjString*) aFXSarray->At(1))->GetName(); | |
2559 | ||
2560 | TString whereClause; | |
2561 | if (system == kDAQ) | |
2562 | { | |
2563 | whereClause = Form("where run=%d and detector=\"%s\" and fileId=\"%s\" and DAQsource=\"%s\";", | |
2564 | GetCurrentRun(), fCurrentDetector.Data(), fileId, source); | |
2565 | } | |
2566 | else if (system == kDCS) | |
2567 | { | |
2568 | whereClause = Form("where run=%d and detector=\"%s\" and fileId=\"%s\";", | |
2569 | GetCurrentRun(), fCurrentDetector.Data(), fileId); | |
2570 | } | |
2571 | else if (system == kHLT) | |
2572 | { | |
2573 | whereClause = Form("where run=%d and detector=\"%s\" and fileId=\"%s\" and DDLnumbers=\"%s\";", | |
2574 | GetCurrentRun(), fCurrentDetector.Data(), fileId, source); | |
2575 | } | |
2576 | ||
2577 | delete aFXSarray; | |
9e080f92 | 2578 | |
9d733021 | 2579 | TString sqlQuery = Form("update %s set time_processed=%d %s", fConfig->GetFXSdbTable(system), |
2580 | now.GetSec(), whereClause.Data()); | |
9e080f92 | 2581 | |
9d733021 | 2582 | AliDebug(2, Form("SQL query: \n%s",sqlQuery.Data())); |
9e080f92 | 2583 | |
9d733021 | 2584 | // Query execution |
2585 | TSQLResult* aResult; | |
2586 | aResult = dynamic_cast<TSQLResult*> (fServer[system]->Query(sqlQuery)); | |
2587 | if (!aResult) | |
2588 | { | |
2589 | Log(fCurrentDetector, Form("UpdateTable - %s db: can't execute SQL query <%s>", | |
2590 | GetSystemName(system), sqlQuery.Data())); | |
2591 | result = kFALSE; | |
2592 | continue; | |
2593 | } | |
2594 | delete aResult; | |
9e080f92 | 2595 | } |
9e080f92 | 2596 | } |
2597 | ||
9d733021 | 2598 | return result; |
9e080f92 | 2599 | } |
57f50b3c | 2600 | |
3301427a | 2601 | //______________________________________________________________________________________________ |
2602 | Bool_t AliShuttle::UpdateTableFailCase() | |
2603 | { | |
9827400b | 2604 | // Update FXS table filling time_processed field in all rows corresponding to current run and detector |
2605 | // this is called in case the preprocessor is declared failed for the current run, because | |
2606 | // the fields are updated only in case of success | |
3301427a | 2607 | |
2608 | Bool_t result = kTRUE; | |
2609 | ||
2610 | for (UInt_t system=0; system<3; system++) | |
2611 | { | |
2612 | // check connection, in case connect | |
2613 | if (!Connect(system)) | |
2614 | { | |
2615 | Log(fCurrentDetector, Form("UpdateTableFailCase - Couldn't connect to %s FXS database", | |
2616 | GetSystemName(system))); | |
2617 | result = kFALSE; | |
2618 | continue; | |
2619 | } | |
2620 | ||
2621 | TTimeStamp now; // now | |
2622 | ||
2623 | // Loop on FXS list entries | |
2624 | ||
2625 | TString whereClause = Form("where run=%d and detector=\"%s\";", | |
2626 | GetCurrentRun(), fCurrentDetector.Data()); | |
2627 | ||
2628 | ||
2629 | TString sqlQuery = Form("update %s set time_processed=%d %s", fConfig->GetFXSdbTable(system), | |
2630 | now.GetSec(), whereClause.Data()); | |
2631 | ||
2632 | AliDebug(2, Form("SQL query: \n%s",sqlQuery.Data())); | |
2633 | ||
2634 | // Query execution | |
2635 | TSQLResult* aResult; | |
2636 | aResult = dynamic_cast<TSQLResult*> (fServer[system]->Query(sqlQuery)); | |
2637 | if (!aResult) | |
2638 | { | |
2639 | Log(fCurrentDetector, Form("UpdateTableFailCase - %s db: can't execute SQL query <%s>", | |
2640 | GetSystemName(system), sqlQuery.Data())); | |
2641 | result = kFALSE; | |
2642 | continue; | |
2643 | } | |
2644 | delete aResult; | |
2645 | } | |
2646 | ||
2647 | return result; | |
2648 | } | |
2649 | ||
2bb7b766 | 2650 | //______________________________________________________________________________________________ |
2651 | Bool_t AliShuttle::UpdateShuttleLogbook(const char* detector, const char* status) | |
2652 | { | |
e7f62f16 | 2653 | // |
2654 | // Update Shuttle logbook filling detector or shuttle_done column | |
2655 | // ex. of usage: UpdateShuttleLogbook("PHOS", "DONE") or UpdateShuttleLogbook("shuttle_done") | |
2656 | // | |
57f50b3c | 2657 | |
2bb7b766 | 2658 | // check connection, in case connect |
be48e3ea | 2659 | if(!Connect(3)){ |
2bb7b766 | 2660 | Log("SHUTTLE", "UpdateShuttleLogbook - Couldn't connect to DAQ Logbook."); |
2661 | return kFALSE; | |
57f50b3c | 2662 | } |
2663 | ||
2bb7b766 | 2664 | TString detName(detector); |
2665 | TString setClause; | |
ee6f7523 | 2666 | if (detName == "shuttle_done" || detName == "shuttle_ignored") |
e7f62f16 | 2667 | { |
2bb7b766 | 2668 | setClause = "set shuttle_done=1"; |
e7f62f16 | 2669 | |
ee6f7523 | 2670 | if (detName == "shuttle_done") |
b0e53b15 | 2671 | { |
2672 | // Send the information to ML | |
2673 | TMonaLisaText mlStatus("SHUTTLE_status", "Done"); | |
e7f62f16 | 2674 | |
b0e53b15 | 2675 | TList mlList; |
2676 | mlList.Add(&mlStatus); | |
2677 | ||
ee6f7523 | 2678 | TString mlID; |
2679 | mlID.Form("%d", GetCurrentRun()); | |
2680 | fMonaLisa->SendParameters(&mlList, mlID); | |
b0e53b15 | 2681 | } |
2bb7b766 | 2682 | } else { |
2bb7b766 | 2683 | TString statusStr(status); |
2684 | if(statusStr.Contains("done", TString::kIgnoreCase) || | |
2685 | statusStr.Contains("failed", TString::kIgnoreCase)){ | |
eba76848 | 2686 | setClause = Form("set %s=\"%s\"", detector, status); |
2bb7b766 | 2687 | } else { |
2688 | Log("SHUTTLE", | |
2689 | Form("UpdateShuttleLogbook - Invalid status <%s> for detector %s", | |
2690 | status, detector)); | |
2691 | return kFALSE; | |
2692 | } | |
2693 | } | |
57f50b3c | 2694 | |
2bb7b766 | 2695 | TString whereClause = Form("where run=%d", GetCurrentRun()); |
2696 | ||
441b0e9c | 2697 | TString sqlQuery = Form("update %s %s %s", |
2698 | fConfig->GetShuttlelbTable(), setClause.Data(), whereClause.Data()); | |
57f50b3c | 2699 | |
2bb7b766 | 2700 | AliDebug(2, Form("SQL query: \n%s",sqlQuery.Data())); |
2701 | ||
2702 | // Query execution | |
2703 | TSQLResult* aResult; | |
be48e3ea | 2704 | aResult = dynamic_cast<TSQLResult*> (fServer[3]->Query(sqlQuery)); |
2bb7b766 | 2705 | if (!aResult) { |
2706 | Log("SHUTTLE", Form("UpdateShuttleLogbook - Can't execute query <%s>", sqlQuery.Data())); | |
2707 | return kFALSE; | |
57f50b3c | 2708 | } |
2bb7b766 | 2709 | delete aResult; |
57f50b3c | 2710 | |
2711 | return kTRUE; | |
2712 | } | |
2713 | ||
2714 | //______________________________________________________________________________________________ | |
2bb7b766 | 2715 | Int_t AliShuttle::GetCurrentRun() const |
2716 | { | |
9827400b | 2717 | // |
2718 | // Get current run from logbook entry | |
2719 | // | |
57f50b3c | 2720 | |
2bb7b766 | 2721 | return fLogbookEntry ? fLogbookEntry->GetRun() : -1; |
57f50b3c | 2722 | } |
2723 | ||
2724 | //______________________________________________________________________________________________ | |
2bb7b766 | 2725 | UInt_t AliShuttle::GetCurrentStartTime() const |
2726 | { | |
9827400b | 2727 | // |
2728 | // get current start time | |
2729 | // | |
57f50b3c | 2730 | |
2bb7b766 | 2731 | return fLogbookEntry ? fLogbookEntry->GetStartTime() : 0; |
57f50b3c | 2732 | } |
2733 | ||
2734 | //______________________________________________________________________________________________ | |
2bb7b766 | 2735 | UInt_t AliShuttle::GetCurrentEndTime() const |
2736 | { | |
9827400b | 2737 | // |
2738 | // get current end time from logbook entry | |
2739 | // | |
57f50b3c | 2740 | |
2bb7b766 | 2741 | return fLogbookEntry ? fLogbookEntry->GetEndTime() : 0; |
57f50b3c | 2742 | } |
2743 | ||
675f64cd | 2744 | //______________________________________________________________________________________________ |
2745 | UInt_t AliShuttle::GetCurrentYear() const | |
2746 | { | |
2747 | // | |
2748 | // Get current year from logbook entry | |
2749 | // | |
2750 | ||
2751 | if (!fLogbookEntry) return 0; | |
2752 | ||
2753 | TTimeStamp startTime(GetCurrentStartTime()); | |
2754 | TString year = Form("%d",startTime.GetDate()); | |
2755 | year = year(0,4); | |
2756 | ||
2757 | return year.Atoi(); | |
2758 | } | |
2759 | ||
2760 | //______________________________________________________________________________________________ | |
2761 | const char* AliShuttle::GetLHCPeriod() const | |
2762 | { | |
2763 | // | |
2764 | // Get current LHC period from logbook entry | |
2765 | // | |
2766 | ||
2767 | if (!fLogbookEntry) return 0; | |
2768 | ||
2769 | return fLogbookEntry->GetRunParameter("LHCperiod"); | |
2770 | } | |
2771 | ||
b948db8d | 2772 | //______________________________________________________________________________________________ |
2773 | void AliShuttle::Log(const char* detector, const char* message) | |
2774 | { | |
9827400b | 2775 | // |
2776 | // Fill log string with a message | |
2777 | // | |
b948db8d | 2778 | |
7d4cf768 | 2779 | TString logRunDir = GetShuttleLogDir(); |
2780 | if (GetCurrentRun() >=0) | |
2781 | logRunDir += Form("/%d", GetCurrentRun()); | |
2782 | ||
2783 | void* dir = gSystem->OpenDirectory(logRunDir.Data()); | |
84090f85 | 2784 | if (dir == NULL) { |
7d4cf768 | 2785 | if (gSystem->mkdir(logRunDir.Data(), kTRUE)) { |
36c99a6a | 2786 | AliError(Form("Can't open directory <%s>", GetShuttleLogDir())); |
84090f85 | 2787 | return; |
2788 | } | |
b948db8d | 2789 | |
84090f85 | 2790 | } else { |
2791 | gSystem->FreeDirectory(dir); | |
2792 | } | |
b948db8d | 2793 | |
cb343cfd | 2794 | TString toLog = Form("%s (%d): %s - ", TTimeStamp(time(0)).AsString("s"), getpid(), detector); |
e7f62f16 | 2795 | if (GetCurrentRun() >= 0) |
2796 | toLog += Form("run %d - ", GetCurrentRun()); | |
2bb7b766 | 2797 | toLog += Form("%s", message); |
2798 | ||
84090f85 | 2799 | AliInfo(toLog.Data()); |
ffa29e93 | 2800 | |
2801 | // if we redirect the log output already to the file, leave here | |
2802 | if (fOutputRedirected && strcmp(detector, "SHUTTLE") != 0) | |
2803 | return; | |
b948db8d | 2804 | |
ffa29e93 | 2805 | TString fileName = GetLogFileName(detector); |
e7f62f16 | 2806 | |
84090f85 | 2807 | gSystem->ExpandPathName(fileName); |
2808 | ||
2809 | ofstream logFile; | |
2810 | logFile.open(fileName, ofstream::out | ofstream::app); | |
2811 | ||
2812 | if (!logFile.is_open()) { | |
2813 | AliError(Form("Could not open file %s", fileName.Data())); | |
2814 | return; | |
2815 | } | |
7bfb2090 | 2816 | |
84090f85 | 2817 | logFile << toLog.Data() << "\n"; |
b948db8d | 2818 | |
84090f85 | 2819 | logFile.close(); |
b948db8d | 2820 | } |
2bb7b766 | 2821 | |
ffa29e93 | 2822 | //______________________________________________________________________________________________ |
2823 | TString AliShuttle::GetLogFileName(const char* detector) const | |
2824 | { | |
2825 | // | |
2826 | // returns the name of the log file for a given sub detector | |
2827 | // | |
2828 | ||
2829 | TString fileName; | |
2830 | ||
2831 | if (GetCurrentRun() >= 0) | |
7d4cf768 | 2832 | { |
2833 | fileName.Form("%s/%d/%s_%d.log", GetShuttleLogDir(), GetCurrentRun(), | |
2834 | detector, GetCurrentRun()); | |
2835 | } else { | |
ffa29e93 | 2836 | fileName.Form("%s/%s.log", GetShuttleLogDir(), detector); |
7d4cf768 | 2837 | } |
ffa29e93 | 2838 | |
2839 | return fileName; | |
2840 | } | |
2841 | ||
ee6f7523 | 2842 | //______________________________________________________________________________________________ |
2843 | void AliShuttle::SendAlive() | |
2844 | { | |
2845 | // sends alive message to ML | |
2846 | ||
2847 | TMonaLisaText mlStatus("SHUTTLE_status", "Alive"); | |
2848 | ||
2849 | TList mlList; | |
2850 | mlList.Add(&mlStatus); | |
2851 | ||
2852 | fMonaLisa->SendParameters(&mlList, "__PROCESSINGINFO__"); | |
2853 | } | |
2854 | ||
2bb7b766 | 2855 | //______________________________________________________________________________________________ |
2856 | Bool_t AliShuttle::Collect(Int_t run) | |
2857 | { | |
9827400b | 2858 | // |
2859 | // Collects conditions data for all UNPROCESSED run written to DAQ LogBook in case of run = -1 (default) | |
2860 | // If a dedicated run is given this run is processed | |
2861 | // | |
2862 | // In operational mode, this is the Shuttle function triggered by the EOR signal. | |
2863 | // | |
2bb7b766 | 2864 | |
eba76848 | 2865 | if (run == -1) |
2866 | Log("SHUTTLE","Collect - Shuttle called. Collecting conditions data for unprocessed runs"); | |
2867 | else | |
2868 | Log("SHUTTLE", Form("Collect - Shuttle called. Collecting conditions data for run %d", run)); | |
cb343cfd | 2869 | |
2870 | SetLastAction("Starting"); | |
2bb7b766 | 2871 | |
ee6f7523 | 2872 | // create ML instance |
2873 | if (!fMonaLisa) | |
2874 | fMonaLisa = new TMonaLisaWriter(fConfig->GetMonitorHost(), fConfig->GetMonitorTable()); | |
2875 | ||
ee6f7523 | 2876 | SendAlive(); |
fbc112e3 | 2877 | CountOpenRuns(); |
ee6f7523 | 2878 | |
2bb7b766 | 2879 | TString whereClause("where shuttle_done=0"); |
eba76848 | 2880 | if (run != -1) |
2881 | whereClause += Form(" and run=%d", run); | |
2bb7b766 | 2882 | |
2883 | TObjArray shuttleLogbookEntries; | |
be48e3ea | 2884 | if (!QueryShuttleLogbook(whereClause, shuttleLogbookEntries)) |
2885 | { | |
cb343cfd | 2886 | Log("SHUTTLE", "Collect - Can't retrieve entries from Shuttle logbook"); |
2bb7b766 | 2887 | return kFALSE; |
2888 | } | |
2889 | ||
9e080f92 | 2890 | if (shuttleLogbookEntries.GetEntries() == 0) |
2891 | { | |
2892 | if (run == -1) | |
2893 | Log("SHUTTLE","Collect - Found no UNPROCESSED runs in Shuttle logbook"); | |
2894 | else | |
2895 | Log("SHUTTLE", Form("Collect - Run %d is already DONE " | |
2896 | "or it does not exist in Shuttle logbook", run)); | |
2897 | return kTRUE; | |
2898 | } | |
2899 | ||
be48e3ea | 2900 | for (UInt_t iDet=0; iDet<NDetectors(); iDet++) |
2901 | fFirstUnprocessed[iDet] = kTRUE; | |
2902 | ||
fc5a4708 | 2903 | if (run != -1) |
be48e3ea | 2904 | { |
2905 | // query Shuttle logbook for earlier runs, check if some detectors are unprocessed, | |
2906 | // flag them into fFirstUnprocessed array | |
2907 | TString whereClause(Form("where shuttle_done=0 and run < %d", run)); | |
2908 | TObjArray tmpLogbookEntries; | |
2909 | if (!QueryShuttleLogbook(whereClause, tmpLogbookEntries)) | |
2910 | { | |
2911 | Log("SHUTTLE", "Collect - Can't retrieve entries from Shuttle logbook"); | |
2912 | return kFALSE; | |
2913 | } | |
2914 | ||
2915 | TIter iter(&tmpLogbookEntries); | |
2916 | AliShuttleLogbookEntry* anEntry = 0; | |
2917 | while ((anEntry = dynamic_cast<AliShuttleLogbookEntry*> (iter.Next()))) | |
2918 | { | |
2919 | for (UInt_t iDet=0; iDet<NDetectors(); iDet++) | |
2920 | { | |
2921 | if (anEntry->GetDetectorStatus(iDet) == AliShuttleLogbookEntry::kUnprocessed) | |
2922 | { | |
2923 | AliDebug(2, Form("Run %d: setting %s as \"not first time unprocessed\"", | |
2924 | anEntry->GetRun(), GetDetName(iDet))); | |
2925 | fFirstUnprocessed[iDet] = kFALSE; | |
2926 | } | |
2927 | } | |
2928 | ||
2929 | } | |
2930 | ||
2931 | } | |
2932 | ||
2933 | if (!RetrieveConditionsData(shuttleLogbookEntries)) | |
2934 | { | |
cb343cfd | 2935 | Log("SHUTTLE", "Collect - Process of at least one run failed"); |
a3ca69fe | 2936 | CountOpenRuns(); |
2bb7b766 | 2937 | return kFALSE; |
2938 | } | |
2939 | ||
36c99a6a | 2940 | Log("SHUTTLE", "Collect - Requested run(s) successfully processed"); |
a3ca69fe | 2941 | CountOpenRuns(); |
eba76848 | 2942 | return kTRUE; |
2bb7b766 | 2943 | } |
2944 | ||
2bb7b766 | 2945 | //______________________________________________________________________________________________ |
2946 | Bool_t AliShuttle::RetrieveConditionsData(const TObjArray& dateEntries) | |
2947 | { | |
9827400b | 2948 | // |
2949 | // Retrieve conditions data for all runs that aren't processed yet | |
2950 | // | |
2bb7b766 | 2951 | |
2952 | Bool_t hasError = kFALSE; | |
2953 | ||
2954 | TIter iter(&dateEntries); | |
2955 | AliShuttleLogbookEntry* anEntry; | |
2956 | ||
2957 | while ((anEntry = (AliShuttleLogbookEntry*) iter.Next())){ | |
2958 | if (!Process(anEntry)){ | |
2959 | hasError = kTRUE; | |
2960 | } | |
4b95672b | 2961 | |
2962 | // clean SHUTTLE temp directory | |
d524ade6 | 2963 | //TString filename = Form("%s/*.shuttle", GetShuttleTempDir()); |
2964 | //RemoveFile(filename.Data()); | |
2bb7b766 | 2965 | } |
2966 | ||
2967 | return hasError == kFALSE; | |
2968 | } | |
cb343cfd | 2969 | |
2970 | //______________________________________________________________________________________________ | |
2971 | ULong_t AliShuttle::GetTimeOfLastAction() const | |
2972 | { | |
9827400b | 2973 | // |
2974 | // Gets time of last action | |
2975 | // | |
2976 | ||
cb343cfd | 2977 | ULong_t tmp; |
36c99a6a | 2978 | |
cb343cfd | 2979 | fMonitoringMutex->Lock(); |
be48e3ea | 2980 | |
cb343cfd | 2981 | tmp = fLastActionTime; |
36c99a6a | 2982 | |
cb343cfd | 2983 | fMonitoringMutex->UnLock(); |
36c99a6a | 2984 | |
cb343cfd | 2985 | return tmp; |
2986 | } | |
2987 | ||
2988 | //______________________________________________________________________________________________ | |
2989 | const TString AliShuttle::GetLastAction() const | |
2990 | { | |
9827400b | 2991 | // |
cb343cfd | 2992 | // returns a string description of the last action |
9827400b | 2993 | // |
cb343cfd | 2994 | |
2995 | TString tmp; | |
36c99a6a | 2996 | |
cb343cfd | 2997 | fMonitoringMutex->Lock(); |
2998 | ||
2999 | tmp = fLastAction; | |
3000 | ||
3001 | fMonitoringMutex->UnLock(); | |
3002 | ||
36c99a6a | 3003 | return tmp; |
cb343cfd | 3004 | } |
3005 | ||
3006 | //______________________________________________________________________________________________ | |
3007 | void AliShuttle::SetLastAction(const char* action) | |
3008 | { | |
9827400b | 3009 | // |
cb343cfd | 3010 | // updates the monitoring variables |
9827400b | 3011 | // |
36c99a6a | 3012 | |
cb343cfd | 3013 | fMonitoringMutex->Lock(); |
36c99a6a | 3014 | |
cb343cfd | 3015 | fLastAction = action; |
3016 | fLastActionTime = time(0); | |
3017 | ||
3018 | fMonitoringMutex->UnLock(); | |
3019 | } | |
eba76848 | 3020 | |
3021 | //______________________________________________________________________________________________ | |
3022 | const char* AliShuttle::GetRunParameter(const char* param) | |
3023 | { | |
9827400b | 3024 | // |
3025 | // returns run parameter read from DAQ logbook | |
3026 | // | |
eba76848 | 3027 | |
3028 | if(!fLogbookEntry) { | |
3029 | AliError("No logbook entry!"); | |
3030 | return 0; | |
3031 | } | |
3032 | ||
3033 | return fLogbookEntry->GetRunParameter(param); | |
3034 | } | |
57c1a579 | 3035 | |
d386d623 | 3036 | //______________________________________________________________________________________________ |
9827400b | 3037 | AliCDBEntry* AliShuttle::GetFromOCDB(const char* detector, const AliCDBPath& path) |
d386d623 | 3038 | { |
9827400b | 3039 | // |
3040 | // returns object from OCDB valid for current run | |
3041 | // | |
d386d623 | 3042 | |
9827400b | 3043 | if (fTestMode & kErrorOCDB) |
3044 | { | |
3045 | Log(detector, "GetFromOCDB - In TESTMODE - Simulating error with OCDB"); | |
3046 | return 0; | |
3047 | } | |
3048 | ||
d386d623 | 3049 | AliCDBStorage *sto = AliCDBManager::Instance()->GetStorage(fgkMainCDB); |
3050 | if (!sto) | |
3051 | { | |
9827400b | 3052 | Log(detector, "GetFromOCDB - Cannot activate main OCDB for query!"); |
d386d623 | 3053 | return 0; |
3054 | } | |
3055 | ||
3056 | return dynamic_cast<AliCDBEntry*> (sto->Get(path, GetCurrentRun())); | |
3057 | } | |
3058 | ||
57c1a579 | 3059 | //______________________________________________________________________________________________ |
339adafa | 3060 | Bool_t AliShuttle::SendMail(EMailTarget target, Int_t system) |
57c1a579 | 3061 | { |
9827400b | 3062 | // |
3063 | // sends a mail to the subdetector expert in case of preprocessor error | |
3064 | // | |
3065 | ||
3066 | if (fTestMode != kNone) | |
3067 | return kTRUE; | |
fb40ead4 | 3068 | |
926cbc0e | 3069 | if (!fConfig->SendMail()) |
3070 | return kTRUE; | |
57c1a579 | 3071 | |
339adafa | 3072 | if (target == kDCSEMail || target == kFXSEMail) { |
3073 | if (!fFirstProcessing) | |
3074 | return kTRUE; | |
36c99a6a | 3075 | } |
3076 | ||
fbc112e3 | 3077 | void* dir = gSystem->OpenDirectory(GetShuttleLogDir()); |
3078 | if (dir == NULL) | |
3079 | { | |
3080 | if (gSystem->mkdir(GetShuttleLogDir(), kTRUE)) | |
3081 | { | |
3082 | Log("SHUTTLE", Form("SendMail - Can't open directory <%s>", GetShuttleLogDir())); | |
3083 | return kFALSE; | |
3084 | } | |
3085 | ||
3086 | } else { | |
3087 | gSystem->FreeDirectory(dir); | |
3088 | } | |
3089 | ||
339adafa | 3090 | // det experts in to |
3091 | TString to=""; | |
3092 | TIter *iterExperts; | |
3093 | if (target == kDCSEMail) { | |
3094 | iterExperts = new TIter(fConfig->GetAdmins(AliShuttleConfig::kAmanda)); | |
3095 | } | |
3096 | else if (target == kFXSEMail) { | |
3097 | iterExperts = new TIter(fConfig->GetAdmins(system)); | |
3098 | } | |
3099 | else { | |
3100 | iterExperts = new TIter(fConfig->GetResponsibles(fCurrentDetector)); | |
3101 | } | |
3102 | TObjString *anExpert=0; | |
3103 | while ((anExpert = (TObjString*) iterExperts->Next())) | |
4508ab8b | 3104 | { |
339adafa | 3105 | to += Form("%s,", anExpert->GetName()); |
3106 | } | |
3107 | delete iterExperts; | |
3108 | if (to.Length() > 0) | |
3109 | to.Remove(to.Length()-1); | |
3110 | AliDebug(2, Form("to: %s",to.Data())); | |
4508ab8b | 3111 | |
339adafa | 3112 | if (to.IsNull()) { |
3113 | Log("SHUTTLE", Form("List of %d responsibles not set!", (Int_t) target)); | |
3114 | return kFALSE; | |
3115 | } | |
3116 | ||
3117 | // SHUTTLE responsibles in cc | |
fb40ead4 | 3118 | TString cc=""; |
3119 | TIter iterAdmins(fConfig->GetAdmins(AliShuttleConfig::kGlobal)); | |
3120 | TObjString *anAdmin=0; | |
3121 | while ((anAdmin = (TObjString*) iterAdmins.Next())) | |
3122 | { | |
3123 | cc += Form("%s,", anAdmin->GetName()); | |
3124 | } | |
3125 | if (cc.Length() > 0) | |
c19963db | 3126 | cc.Remove(cc.Length()-1); |
fb40ead4 | 3127 | AliDebug(2, Form("cc: %s",to.Data())); |
57c1a579 | 3128 | |
339adafa | 3129 | // mail body |
675f64cd | 3130 | TString bodyFileName; |
3131 | bodyFileName.Form("%s/mail.body", GetShuttleLogDir()); | |
3132 | gSystem->ExpandPathName(bodyFileName); | |
3133 | ||
3134 | ofstream mailBody; | |
3135 | mailBody.open(bodyFileName, ofstream::out); | |
3136 | ||
3137 | if (!mailBody.is_open()) | |
3138 | { | |
339adafa | 3139 | Log("SHUTTLE", Form("Could not open mail body file %s", bodyFileName.Data())); |
675f64cd | 3140 | return kFALSE; |
3141 | } | |
3142 | ||
675f64cd | 3143 | |
339adafa | 3144 | TString subject; |
3145 | TString body; | |
675f64cd | 3146 | |
339adafa | 3147 | if (target == kDCSEMail){ |
3148 | subject = Form("Retrieval of data points for %s FAILED in run %d !", | |
3149 | fCurrentDetector.Data(), GetCurrentRun()); | |
3150 | AliDebug(2, Form("subject: %s", subject.Data())); | |
3151 | ||
3152 | body = Form("Dear DCS experts, \n\n"); | |
3153 | body += Form("SHUTTLE couldn\'t retrieve the data points for detector %s " | |
3154 | "in run %d!!\n\n", fCurrentDetector.Data(), GetCurrentRun()); | |
fb40ead4 | 3155 | } |
339adafa | 3156 | else if (target == kFXSEMail){ |
3157 | subject = Form("FXS communication for %s FAILED in run %d !", | |
675f64cd | 3158 | fCurrentDetector.Data(), GetCurrentRun()); |
339adafa | 3159 | AliDebug(2, Form("subject: %s", subject.Data())); |
3160 | TString sys; | |
3161 | if (system == kDAQ) sys="DAQ"; | |
3162 | else if (system == kDCS) sys="DCS"; | |
3163 | else if (system == kHLT) sys="HLT"; | |
3164 | else return kFALSE; | |
9c0e2d64 | 3165 | body = Form("Dear %s FXS experts, \n\n",sys.Data()); |
339adafa | 3166 | body += Form("SHUTTLE couldn\'t retrieve data from the FXS for detector %s " |
9c0e2d64 | 3167 | "in run %d!!\n\n", fCurrentDetector.Data(), GetCurrentRun()); |
339adafa | 3168 | } |
3169 | else { | |
3170 | subject = Form("%s Shuttle preprocessor FAILED in run %d (run type = %s)!", | |
3171 | fCurrentDetector.Data(), GetCurrentRun(), GetRunType()); | |
3172 | AliDebug(2, Form("subject: %s", subject.Data())); | |
3173 | ||
3174 | body = Form("Dear %s expert(s), \n\n", fCurrentDetector.Data()); | |
3175 | body += Form("SHUTTLE just detected that your preprocessor " | |
3176 | "failed processing run %d (run type = %s)!!\n\n", | |
3177 | GetCurrentRun(), GetRunType()); | |
3178 | } | |
675f64cd | 3179 | |
7d4cf768 | 3180 | body += Form("Please check %s status on the SHUTTLE monitoring page: \n\n", |
3181 | fCurrentDetector.Data()); | |
b0e53b15 | 3182 | if (fConfig->GetRunMode() == AliShuttleConfig::kTest) |
3183 | { | |
3184 | body += Form("\thttp://pcalimonitor.cern.ch:8889/shuttle.jsp?time=168 \n\n"); | |
3185 | } else { | |
339adafa | 3186 | body += Form("\thttp://pcalimonitor.cern.ch/shuttle.jsp?instance=PROD&time=168 \n\n"); |
b0e53b15 | 3187 | } |
339adafa | 3188 | |
3189 | ||
7d4cf768 | 3190 | TString logFolder = "logs"; |
3191 | if (fConfig->GetRunMode() == AliShuttleConfig::kProd) | |
3192 | logFolder += "_PROD"; | |
3193 | ||
3194 | ||
675f64cd | 3195 | body += Form("Find the %s log for the current run on \n\n" |
7d4cf768 | 3196 | "\thttp://pcalishuttle01.cern.ch:8880/%s/%d/%s_%d.log \n\n", |
3197 | fCurrentDetector.Data(), logFolder.Data(), GetCurrentRun(), | |
3198 | fCurrentDetector.Data(), GetCurrentRun()); | |
3199 | body += Form("The last 10 lines of %s log file are following:\n\n", fCurrentDetector.Data()); | |
675f64cd | 3200 | |
3201 | AliDebug(2, Form("Body begin: %s", body.Data())); | |
3202 | ||
3203 | mailBody << body.Data(); | |
3204 | mailBody.close(); | |
3205 | mailBody.open(bodyFileName, ofstream::out | ofstream::app); | |
3206 | ||
339adafa | 3207 | TString logFileName = Form("%s/%d/%s_%d.log", GetShuttleLogDir(), |
3208 | GetCurrentRun(), fCurrentDetector.Data(), GetCurrentRun()); | |
675f64cd | 3209 | TString tailCommand = Form("tail -n 10 %s >> %s", logFileName.Data(), bodyFileName.Data()); |
3210 | if (gSystem->Exec(tailCommand.Data())) | |
3211 | { | |
3212 | mailBody << Form("%s log file not found ...\n\n", fCurrentDetector.Data()); | |
3213 | } | |
3214 | ||
3215 | TString endBody = Form("------------------------------------------------------\n\n"); | |
36c99a6a | 3216 | endBody += Form("In case of problems please contact the SHUTTLE core team.\n\n"); |
3217 | endBody += "Please do not answer this message directly, it is automatically generated.\n\n"; | |
546242fb | 3218 | endBody += "Greetings,\n\n \t\t\tthe SHUTTLE\n"; |
57c1a579 | 3219 | |
909732f7 | 3220 | AliDebug(2, Form("Body end: %s", endBody.Data())); |
57c1a579 | 3221 | |
3222 | mailBody << endBody.Data(); | |
3223 | ||
3224 | mailBody.close(); | |
3225 | ||
3226 | // send mail! | |
3227 | TString mailCommand = Form("mail -s \"%s\" -c %s %s < %s", | |
3228 | subject.Data(), | |
3229 | cc.Data(), | |
3230 | to.Data(), | |
3231 | bodyFileName.Data()); | |
909732f7 | 3232 | AliDebug(2, Form("mail command: %s", mailCommand.Data())); |
57c1a579 | 3233 | |
3234 | Bool_t result = gSystem->Exec(mailCommand.Data()); | |
3235 | ||
3236 | return result == 0; | |
3237 | } | |
d386d623 | 3238 | |
441b0e9c | 3239 | //______________________________________________________________________________________________ |
9827400b | 3240 | const char* AliShuttle::GetRunType() |
441b0e9c | 3241 | { |
9827400b | 3242 | // |
3243 | // returns run type read from "run type" logbook | |
3244 | // | |
441b0e9c | 3245 | |
3246 | if(!fLogbookEntry) { | |
3247 | AliError("No logbook entry!"); | |
3248 | return 0; | |
3249 | } | |
3250 | ||
9827400b | 3251 | return fLogbookEntry->GetRunType(); |
441b0e9c | 3252 | } |
3253 | ||
4859271b | 3254 | //______________________________________________________________________________________________ |
3255 | Bool_t AliShuttle::GetHLTStatus() | |
3256 | { | |
3257 | // Return HLT status (ON=1 OFF=0) | |
af76b20d | 3258 | // Converts the HLT status from the mode string read in the run logbook (not just a bool) |
4859271b | 3259 | |
3260 | if(!fLogbookEntry) { | |
3261 | AliError("No logbook entry!"); | |
3262 | return 0; | |
3263 | } | |
3264 | ||
af76b20d | 3265 | // TODO implement when HLTMode is inserted in run logbook |
3266 | TString hltMode = fLogbookEntry->GetRunParameter("HLTMode"); | |
3267 | TSubString firstChar = hltMode(0,1); | |
3268 | AliDebug(2,Form("First char = %s ",firstChar.Data())); | |
3269 | if (firstChar == "A") { | |
3270 | return kFALSE; | |
3271 | } | |
3272 | else if ((firstChar == "B") || (firstChar == "C") || (firstChar == "D") || (firstChar == "E")) { | |
3273 | return kTRUE; | |
3274 | } | |
3275 | else { | |
3276 | Log("SHUTTLE","Unexpected HLT mode! Returning 0...."); | |
3277 | return kFALSE; | |
3278 | } | |
4859271b | 3279 | } |
d386d623 | 3280 | //______________________________________________________________________________________________ |
3281 | void AliShuttle::SetShuttleTempDir(const char* tmpDir) | |
3282 | { | |
9827400b | 3283 | // |
3284 | // sets Shuttle temp directory | |
3285 | // | |
d386d623 | 3286 | |
3287 | fgkShuttleTempDir = gSystem->ExpandPathName(tmpDir); | |
3288 | } | |
3289 | ||
3290 | //______________________________________________________________________________________________ | |
3291 | void AliShuttle::SetShuttleLogDir(const char* logDir) | |
3292 | { | |
9827400b | 3293 | // |
3294 | // sets Shuttle log directory | |
3295 | // | |
d386d623 | 3296 | |
3297 | fgkShuttleLogDir = gSystem->ExpandPathName(logDir); | |
3298 | } |