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.2 2006/06/06 14:26:40 jgrosseo
19 o) removed files that were moved to STEER
20 o) shuttle updated to follow the new interface (Alberto)
22 Revision 1.1 2006/03/07 07:52:34 hristov
23 New version (B.Yordanov)
25 Revision 1.5 2005/11/21 09:03:48 byordano
28 Revision 1.4 2005/11/20 10:12:37 byordano
29 comments added to AliShuttleTrigger
35 // This class is to deal with DAQ LogBook and DAQ "end of run" notification.
36 // It has severeal two modes:
37 // 1) syncrhnized - Collect(), CollectNew() and CollectAll methods
38 // 2) asynchronized - Run() - starts listening for DAQ "end of run"
39 // notification by DIM service.
42 #include "AliShuttleTrigger.h"
44 #include <TSQLServer.h>
45 #include <TSQLResult.h>
47 #include <TObjArray.h>
51 #include "AliCDBManager.h"
52 #include "AliCDBStorage.h"
53 #include "AliCDBEntry.h"
55 #include "AliSimpleValue.h"
56 #include "AliShuttleConfig.h"
57 #include "AliShuttle.h"
58 #include "DATENotifier.h"
60 ClassImp(TerminateSignalHandler)
62 //______________________________________________________________________
63 TerminateSignalHandler::TerminateSignalHandler(const TerminateSignalHandler& /*other*/):
66 // copy constructor (not implemented)
70 //______________________________________________________________________
71 TerminateSignalHandler &TerminateSignalHandler::operator=(const TerminateSignalHandler& /*other*/)
73 // assignment operator (not implemented)
78 //______________________________________________________________________________________________
79 Bool_t TerminateSignalHandler::Notify()
81 // Sentd terminate command to the Shuttle trigger
83 AliInfo("Terminate signal received ...");
84 fTrigger->Terminate();
89 //______________________________________________________________________________________________
90 //______________________________________________________________________________________________
92 ClassImp(AliShuttleTrigger)
94 //______________________________________________________________________________________________
95 AliShuttleTrigger::AliShuttleTrigger(const AliShuttleConfig* config,
96 UInt_t timeout, Int_t retries):
97 fConfig(config), fShuttle(NULL),
98 fNotified(kFALSE), fTerminate(kFALSE), fCondition(&fMutex),
99 fQuitSignalHandler(this, kSigQuit),
100 fInterruptSignalHandler(this, kSigInterrupt)
103 // config - pointer to the AliShuttleConfig object which represents
105 // mainStorage - pointer to AliCDBStorage for the undelying CDBStorage
106 // localStorage (local) CDB storage to be used if mainStorage is unavailable
109 fShuttle = new AliShuttle(config, timeout, retries);
111 gSystem->AddSignalHandler(&fQuitSignalHandler);
112 gSystem->AddSignalHandler(&fInterruptSignalHandler);
117 //______________________________________________________________________
118 AliShuttleTrigger::AliShuttleTrigger(const AliShuttleTrigger& /*other*/):
121 // copy constructor (not implemented)
125 //______________________________________________________________________
126 AliShuttleTrigger &AliShuttleTrigger::operator=(const AliShuttleTrigger& /*other*/)
128 // assignment operator (not implemented)
137 //______________________________________________________________________________________________
138 AliShuttleTrigger::~AliShuttleTrigger()
142 gSystem->RemoveSignalHandler(&fQuitSignalHandler);
143 gSystem->RemoveSignalHandler(&fInterruptSignalHandler);
148 //______________________________________________________________________________________________
149 Bool_t AliShuttleTrigger::Notify() {
151 // Trigger CollectNew() methods in asynchronized (listen) mode.
152 // Usually called automaticly by DATENotifier on "end of run"
153 // notification event.
166 //______________________________________________________________________________________________
167 void AliShuttleTrigger::Terminate() {
169 // Stop triggers listen mode and exist from Run()
170 // Usually called automaticly by TerminateSignalHandler.
177 //______________________________________________________________________________________________
178 void AliShuttleTrigger::Run() {
180 // AliShuttleTrigger main loop for asynchronized (listen) mode.
181 // It spawns DIM service listener and waits for DAQ "end of run"
182 // notification. Calls CollectNew() on notification.
187 DATENotifier* notifier = new DATENotifier(this, "/DATE/LOGBOOK/UPDATE");
193 while (!(fNotified || fTerminate)) {
202 AliInfo("Terminated.");
212 //______________________________________________________________________________________________
213 Bool_t AliShuttleTrigger::RetrieveDATEEntries(const char* whereClause,
214 TObjArray& entries, Int_t& lastRun)
216 // Retrieve start time and end time for all runs in the DAQ logbook
217 // that aren't processed yet
220 sqlQuery += "select run, time_start, time_end from logbook ";
221 sqlQuery += whereClause;
222 sqlQuery += " order by run";
225 TString logbookHost="mysql://";
226 logbookHost+=fConfig->GetDAQLogBookHost();
228 aServer = TSQLServer::Connect(logbookHost,
229 fConfig->GetDAQLogBookUser(),
230 fConfig->GetDAQLogBookPassword());
232 AliError("Can't establish connection to DAQ log book DB!");
236 aServer->GetTables("REFSYSLOG");
239 aResult = aServer->Query(sqlQuery);
241 AliError(Form("Can't execute query <%s>!", sqlQuery.Data()));
246 if (aResult->GetFieldCount() != 3) {
247 AliError("Invalid SQL result field number!");
256 while ((aRow = aResult->Next())) {
257 TString runString(aRow->GetField(0), aRow->GetFieldLength(0));
258 Int_t run = runString.Atoi();
260 TString startTimeString(aRow->GetField(1),
261 aRow->GetFieldLength(1));
262 Int_t startTime = startTimeString.Atoi();
264 AliWarning(Form("Zero StartTime for run <%d>!", run));
265 AliWarning("Going to skip this run!");
269 TString endTimeString(aRow->GetField(2),
270 aRow->GetFieldLength(2));
271 Int_t endTime = endTimeString.Atoi();
273 AliWarning(Form("Zero EndTime for run <%d>!", run));
274 AliWarning("Going to skip this run!");
278 if (startTime > endTime) {
279 AliWarning(Form("StartTime bigger than EndTime for run <%d>", run));
280 AliWarning("Going to skip this run!");
284 entries.AddLast(new AliShuttleTriggerDATEEntry(run, startTime, endTime));
301 //______________________________________________________________________________________________
302 Bool_t AliShuttleTrigger::RetrieveConditionsData(const TObjArray& dateEntries)
304 // Retrieve conditions data for all runs that aren't processed yet
306 Bool_t hasError = kFALSE;
308 TIter iter(&dateEntries);
309 AliShuttleTriggerDATEEntry* anEntry;
310 while ((anEntry = (AliShuttleTriggerDATEEntry*) iter.Next())) {
311 if(!fShuttle->Process(anEntry->GetRun(),
312 anEntry->GetStartTime(),
313 anEntry->GetEndTime())) {
321 //______________________________________________________________________________________________
322 Bool_t AliShuttleTrigger::Collect(Int_t run)
325 // Collects conditions date for the given run.
328 AliInfo(Form("Collecting conditions data for run <%d> ...", run));
330 TString whereClause("where run = ");
334 TObjArray dateEntries;
335 if (!RetrieveDATEEntries(whereClause, dateEntries, lastRun)) {
336 AliError("Can't retrieve entries from DAQ log book.");
340 if (!dateEntries.GetEntriesFast()) {
341 AliError(Form("There isn't entry for run <%d> in DAQ log book!",
346 if (dateEntries.GetEntriesFast() > 1) {
347 AliError(Form("There is more than one entry for run <%d> in DAQ log book", run));
351 if (!RetrieveConditionsData(dateEntries)) {
352 AliError("An error occured during conditions data retrieval!");
359 //______________________________________________________________________________________________
360 Bool_t AliShuttleTrigger::CollectNew()
363 // Collects conditions data for all new run written to DAQ LogBook.
366 AliInfo("Collecting conditions data for new runs ...");
370 AliCDBEntry* cdbEntry = AliCDBManager::Instance()->GetStorage(AliShuttle::GetLocalURI())
371 ->Get("/SHUTTLE/SYSTEM/LASTRUN", 0);
373 TObject* anObject = cdbEntry->GetObject();
374 if (anObject == NULL ||
375 anObject->IsA() != AliSimpleValue::Class()) {
376 AliError("Invalid last run object stored to CDB!");
379 AliSimpleValue* simpleValue = (AliSimpleValue*) anObject;
380 lastRun = simpleValue->GetInt();
383 AliWarning("There isn't last run stored! Starting from run 21200");
387 AliInfo(Form("Last run number <%d>", lastRun));
389 TString whereClause("where run > ");
390 whereClause += lastRun;
393 TObjArray dateEntries;
394 if (!RetrieveDATEEntries(whereClause, dateEntries, newLastRun)) {
395 AliError("Can't retrieve entries from DAQ log book.");
399 if (newLastRun > lastRun) {
400 AliSimpleValue lastRunObj(newLastRun);
401 AliCDBMetaData metaData;
402 AliCDBId cdbID(AliCDBPath("SHUTTLE", "SYSTEM", "LASTRUN"), 0, 0);
404 UInt_t result = AliCDBManager::Instance()->GetStorage(AliShuttle::GetLocalURI())
405 ->Put(&lastRunObj, cdbID, &metaData);
408 AliError("Can't store last run to CDB!");
413 if (!RetrieveConditionsData(dateEntries)) {
414 AliError("An error occured during conditions data retrieval!");
421 //______________________________________________________________________________________________
422 Bool_t AliShuttleTrigger::CollectAll()
425 // Collects conditions data for all run written in DAQ LogBook.
428 AliInfo("Collecting conditions data for all runs ...");
431 TObjArray dateEntries;
432 if (!RetrieveDATEEntries("", dateEntries, lastRun)) {
433 AliError("Can't retrieve entries from DAQ log book.");
437 if (!RetrieveConditionsData(dateEntries)) {
438 AliError("An error occured during conditions data retrieval!");