1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 Revision 1.9 2006/08/08 14:19:29 jgrosseo
19 Update to shuttle classes (Alberto)
21 - Possibility to set the full object's path in the Preprocessor's and
22 Shuttle's Store functions
23 - Possibility to extend the object's run validity in the same classes
24 ("startValidity" and "validityInfinite" parameters)
25 - Implementation of the StoreReferenceData function to store reference
26 data in a dedicated CDB storage.
28 Revision 1.8 2006/07/21 07:37:20 jgrosseo
29 last run is stored after each run
31 Revision 1.7 2006/07/20 09:54:40 jgrosseo
32 introducing status management: The processing per subdetector is divided into several steps,
33 after each step the status is stored on disk. If the system crashes in any of the steps the Shuttle
34 can keep track of the number of failures and skips further processing after a certain threshold is
35 exceeded. These thresholds can be configured in LDAP.
37 Revision 1.6 2006/07/19 10:09:55 jgrosseo
38 new configuration, accesst to DAQ FES (Alberto)
40 Revision 1.5 2006/07/10 13:01:41 jgrosseo
41 enhanced storing of last sucessfully processed run (alberto)
43 Revision 1.4 2006/07/04 14:59:57 jgrosseo
44 revision of AliDCSValue: Removed wrapper classes, reduced storage size per value by factor 2
46 Revision 1.3 2006/06/12 09:11:16 jgrosseo
47 coding conventions (Alberto)
49 Revision 1.2 2006/06/06 14:26:40 jgrosseo
50 o) removed files that were moved to STEER
51 o) shuttle updated to follow the new interface (Alberto)
53 Revision 1.1 2006/03/07 07:52:34 hristov
54 New version (B.Yordanov)
56 Revision 1.5 2005/11/21 09:03:48 byordano
59 Revision 1.4 2005/11/20 10:12:37 byordano
60 comments added to AliShuttleTrigger
66 // This class is to deal with DAQ LogBook and DAQ "end of run" notification.
67 // It has severeal two modes:
68 // 1) syncrhnized - Collect(), CollectNew() and CollectAll methods
69 // 2) asynchronized - Run() - starts listening for DAQ "end of run"
70 // notification by DIM service.
73 #include "AliShuttleTrigger.h"
75 #include <TSQLServer.h>
76 #include <TSQLResult.h>
78 #include <TObjArray.h>
82 #include "AliCDBManager.h"
83 #include "AliCDBStorage.h"
84 #include "AliCDBEntry.h"
86 #include "AliDCSValue.h"
87 #include "AliShuttleConfig.h"
88 #include "AliShuttle.h"
89 #include "DATENotifier.h"
91 ClassImp(TerminateSignalHandler)
93 //______________________________________________________________________
94 TerminateSignalHandler::TerminateSignalHandler(const TerminateSignalHandler& /*other*/):
95 TSignalHandler(), fTrigger()
97 // copy constructor (not implemented)
101 //______________________________________________________________________
102 TerminateSignalHandler &TerminateSignalHandler::operator=(const TerminateSignalHandler& /*other*/)
104 // assignment operator (not implemented)
109 //______________________________________________________________________________________________
110 Bool_t TerminateSignalHandler::Notify()
112 // Sentd terminate command to the Shuttle trigger
114 AliInfo("Terminate signal received ...");
115 fTrigger->Terminate();
120 //______________________________________________________________________________________________
121 //______________________________________________________________________________________________
123 ClassImp(AliShuttleTrigger)
125 //______________________________________________________________________________________________
126 AliShuttleTrigger::AliShuttleTrigger(const AliShuttleConfig* config,
127 UInt_t timeout, Int_t retries):
128 fConfig(config), fShuttle(NULL),
129 fNotified(kFALSE), fTerminate(kFALSE), fLastRun(0),
130 fMutex(), fCondition(&fMutex),
131 fQuitSignalHandler(this, kSigQuit),
132 fInterruptSignalHandler(this, kSigInterrupt)
135 // config - pointer to the AliShuttleConfig object which represents
137 // mainStorage - pointer to AliCDBStorage for the undelying CDBStorage
138 // localStorage (local) CDB storage to be used if mainStorage is unavailable
141 fShuttle = new AliShuttle(config, timeout, retries);
143 gSystem->AddSignalHandler(&fQuitSignalHandler);
144 gSystem->AddSignalHandler(&fInterruptSignalHandler);
149 //______________________________________________________________________
150 AliShuttleTrigger::AliShuttleTrigger(const AliShuttleTrigger& /*other*/):
151 TObject(), fConfig(), fShuttle(NULL),
152 fNotified(kFALSE), fTerminate(kFALSE), fLastRun(0),
153 fMutex(), fCondition(&fMutex),
154 fQuitSignalHandler(this, kSigQuit),
155 fInterruptSignalHandler(this, kSigInterrupt)
158 // copy constructor (not implemented)
162 //______________________________________________________________________
163 AliShuttleTrigger &AliShuttleTrigger::operator=(const AliShuttleTrigger& /*other*/)
165 // assignment operator (not implemented)
174 //______________________________________________________________________________________________
175 AliShuttleTrigger::~AliShuttleTrigger()
179 gSystem->RemoveSignalHandler(&fQuitSignalHandler);
180 gSystem->RemoveSignalHandler(&fInterruptSignalHandler);
185 //______________________________________________________________________________________________
186 Bool_t AliShuttleTrigger::Notify() {
188 // Trigger CollectNew() methods in asynchronized (listen) mode.
189 // Usually called automaticly by DATENotifier on "end of run"
190 // notification event.
203 //______________________________________________________________________________________________
204 void AliShuttleTrigger::Terminate() {
206 // Stop triggers listen mode and exist from Run()
207 // Usually called automaticly by TerminateSignalHandler.
214 //______________________________________________________________________________________________
215 void AliShuttleTrigger::Run() {
217 // AliShuttleTrigger main loop for asynchronized (listen) mode.
218 // It spawns DIM service listener and waits for DAQ "end of run"
219 // notification. Calls CollectNew() on notification.
224 DATENotifier* notifier = new DATENotifier(this, "/DATE/LOGBOOK/UPDATE");
230 while (!(fNotified || fTerminate)) {
239 AliInfo("Terminated.");
249 //______________________________________________________________________________________________
250 Bool_t AliShuttleTrigger::RetrieveDATEEntries(const char* whereClause,
253 // Retrieve start time and end time for all runs in the DAQ logbook
254 // that aren't processed yet
257 sqlQuery = Form("select run, time_start, time_end from logbook %s order by run",
261 TString logbookHost=Form("mysql://%s", fConfig->GetDAQlbHost());
263 aServer = TSQLServer::Connect(logbookHost,
264 fConfig->GetDAQlbUser(),
265 fConfig->GetDAQlbPass());
267 AliError("Can't establish connection to DAQ log book DB!");
271 aServer->GetTables("REFSYSLOG");
274 aResult = aServer->Query(sqlQuery);
276 AliError(Form("Can't execute query <%s>!", sqlQuery.Data()));
281 if (aResult->GetFieldCount() != 3) {
282 AliError("Invalid SQL result field number!");
289 while ((aRow = aResult->Next())) {
290 TString runString(aRow->GetField(0), aRow->GetFieldLength(0));
291 Int_t run = runString.Atoi();
293 TString startTimeString(aRow->GetField(1),
294 aRow->GetFieldLength(1));
295 Int_t startTime = startTimeString.Atoi();
297 AliWarning(Form("Zero StartTime for run <%d>!", run));
298 AliWarning("Going to skip this run!");
302 TString endTimeString(aRow->GetField(2),
303 aRow->GetFieldLength(2));
304 Int_t endTime = endTimeString.Atoi();
306 AliWarning(Form("Zero EndTime for run <%d>!", run));
307 AliWarning("Going to skip this run!");
311 if (startTime > endTime) {
312 AliWarning(Form("StartTime bigger than EndTime for run <%d>", run));
313 AliWarning("Going to skip this run!");
317 entries.AddLast(new AliShuttleTriggerDATEEntry(run, startTime, endTime));
331 //______________________________________________________________________________________________
332 Bool_t AliShuttleTrigger::RetrieveConditionsData(const TObjArray& dateEntries, Bool_t updateLastRun)
334 // Retrieve conditions data for all runs that aren't processed yet
336 Bool_t hasError = kFALSE;
338 TIter iter(&dateEntries);
339 AliShuttleTriggerDATEEntry* anEntry;
341 while ((anEntry = (AliShuttleTriggerDATEEntry*) iter.Next()))
343 if (!fShuttle->Process(anEntry->GetRun(),
344 anEntry->GetStartTime(),
345 anEntry->GetEndTime()))
350 if (!hasError && updateLastRun && fLastRun < anEntry->GetRun())
352 fLastRun = anEntry->GetRun();
357 return hasError == kFALSE;
360 //______________________________________________________________________________________________
361 Bool_t AliShuttleTrigger::ReadLastRun()
363 // reads the last processed run from local CDB
365 AliCDBEntry* cdbEntry = AliCDBManager::Instance()->GetStorage(AliShuttle::GetLocalCDB())
366 ->Get("/SHUTTLE/SYSTEM/LASTRUN", 0);
370 TObject* anObject = cdbEntry->GetObject();
371 if (anObject == NULL || anObject->IsA() != AliDCSValue::Class())
373 AliError("Invalid last run object stored to CDB!");
376 AliDCSValue* dcsValue = (AliDCSValue*) anObject;
377 fLastRun = dcsValue->GetInt();
383 AliFatal("No last run number stored. Please set first. Aborting");
387 AliInfo(Form("Last run number <%d>", fLastRun));
392 //______________________________________________________________________________________________
393 Bool_t AliShuttleTrigger::WriteLastRun()
395 // writes the last succesfully processed run to local CDB
397 AliDCSValue lastRunObj(fLastRun, 0);
398 AliCDBMetaData metaData;
399 AliCDBId cdbID(AliCDBPath("SHUTTLE", "SYSTEM", "LASTRUN"), 0, 0);
401 UInt_t result = AliCDBManager::Instance()->GetStorage(AliShuttle::GetLocalCDB())
402 ->Put(&lastRunObj, cdbID, &metaData);
405 AliError("Can't store last run to CDB!");
412 //______________________________________________________________________________________________
413 Bool_t AliShuttleTrigger::SetNewLastRun(Int_t run)
415 // sets a new run manually, use with caution!
417 fShuttle->Log("SHUTTLE", Form("Setting last run manually to %d", run));
420 return WriteLastRun();
423 //______________________________________________________________________________________________
424 Bool_t AliShuttleTrigger::Collect(Int_t run)
427 // Collects conditions date for the given run.
430 AliInfo(Form("Collecting conditions data for run <%d> ...", run));
432 TString whereClause("where run = ");
435 TObjArray dateEntries;
436 if (!RetrieveDATEEntries(whereClause, dateEntries)) {
437 AliError("Can't retrieve entries from DAQ log book.");
441 if (!dateEntries.GetEntriesFast()) {
442 AliError(Form("There isn't entry for run <%d> in DAQ log book!",
447 if (dateEntries.GetEntriesFast() > 1) {
448 AliError(Form("There is more than one entry for run <%d> in DAQ log book", run));
452 if (!RetrieveConditionsData(dateEntries, kFALSE)) {
453 AliError("An error occured during conditions data retrieval!");
460 //______________________________________________________________________________________________
461 Bool_t AliShuttleTrigger::CollectNew()
464 // Collects conditions data for all new run written to DAQ LogBook.
467 AliInfo("Collecting conditions data for new runs ...");
471 AliError("Retrieving of last run failed");
475 TString whereClause("where run > ");
476 whereClause += fLastRun;
478 TObjArray dateEntries;
479 if (!RetrieveDATEEntries(whereClause, dateEntries)) {
480 AliError("Can't retrieve entries from DAQ log book.");
484 if (!RetrieveConditionsData(dateEntries, kTRUE)) {
485 AliError("Process of at least one run failed!");
492 //______________________________________________________________________________________________
493 Bool_t AliShuttleTrigger::CollectAll()
496 // Collects conditions data for all run written in DAQ LogBook.
501 AliError("Retrieving of last run failed");
505 AliInfo("Collecting conditions data for all runs ...");
507 TObjArray dateEntries;
508 if (!RetrieveDATEEntries("", dateEntries)) {
509 AliError("Can't retrieve entries from DAQ log book.");
513 if (!RetrieveConditionsData(dateEntries, kTRUE)) {
514 AliError("An error occured during conditions data retrieval!");