]> git.uio.no Git - u/mrichter/AliRoot.git/blame - SHUTTLE/AliShuttleTrigger.cxx
Warning fixed.
[u/mrichter/AliRoot.git] / SHUTTLE / AliShuttleTrigger.cxx
CommitLineData
d477ad88 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
16/*
17 $Log$
1abfbb60 18 Revision 1.15 2007/12/10 18:29:23 acolla
19 Some log added to the listen mode
20
6a926ad4 21 Revision 1.14 2007/12/07 19:14:36 acolla
22 in AliShuttleTrigger:
23
24 Added automatic collection of new runs on a regular time basis (settable from the configuration)
25
26 in AliShuttleConfig: new members
27
28 - triggerWait: time to wait for DIM trigger (s) before starting automatic collection of new runs
29 - mode: run mode (test, prod) -> used to build log folder (logs or logs_PROD)
30
31 in AliShuttle:
32
33 - logs now stored in logs/#RUN/DET_#RUN.log
34
7d4cf768 35 Revision 1.13 2006/11/16 16:16:48 jgrosseo
36 introducing strict run ordering flag
37 removed giving preprocessor name to preprocessor, they have to know their name themselves ;-)
38
be48e3ea 39 Revision 1.12 2006/10/20 15:22:59 jgrosseo
40 o) Adding time out to the execution of the preprocessors: The Shuttle forks and the parent process monitors the child
41 o) Merging Collect, CollectAll, CollectNew function
42 o) Removing implementation of empty copy constructors (declaration still there!)
43
cb343cfd 44 Revision 1.11 2006/10/02 16:38:39 jgrosseo
45 update (alberto):
46 fixed memory leaks
47 storing of objects that failed to be stored to the grid before
48 interfacing of shuttle status table in daq system
49
2bb7b766 50 Revision 1.10 2006/08/15 10:50:00 jgrosseo
51 effc++ corrections (alberto)
52
4f0ab988 53 Revision 1.9 2006/08/08 14:19:29 jgrosseo
54 Update to shuttle classes (Alberto)
55
56 - Possibility to set the full object's path in the Preprocessor's and
57 Shuttle's Store functions
58 - Possibility to extend the object's run validity in the same classes
59 ("startValidity" and "validityInfinite" parameters)
60 - Implementation of the StoreReferenceData function to store reference
61 data in a dedicated CDB storage.
62
84090f85 63 Revision 1.8 2006/07/21 07:37:20 jgrosseo
64 last run is stored after each run
65
7bfb2090 66 Revision 1.7 2006/07/20 09:54:40 jgrosseo
67 introducing status management: The processing per subdetector is divided into several steps,
68 after each step the status is stored on disk. If the system crashes in any of the steps the Shuttle
69 can keep track of the number of failures and skips further processing after a certain threshold is
70 exceeded. These thresholds can be configured in LDAP.
71
5164a766 72 Revision 1.6 2006/07/19 10:09:55 jgrosseo
73 new configuration, accesst to DAQ FES (Alberto)
74
57f50b3c 75 Revision 1.5 2006/07/10 13:01:41 jgrosseo
76 enhanced storing of last sucessfully processed run (alberto)
77
a7160fe9 78 Revision 1.4 2006/07/04 14:59:57 jgrosseo
79 revision of AliDCSValue: Removed wrapper classes, reduced storage size per value by factor 2
80
45a493ce 81 Revision 1.3 2006/06/12 09:11:16 jgrosseo
82 coding conventions (Alberto)
83
58bc3020 84 Revision 1.2 2006/06/06 14:26:40 jgrosseo
85 o) removed files that were moved to STEER
86 o) shuttle updated to follow the new interface (Alberto)
87
b948db8d 88 Revision 1.1 2006/03/07 07:52:34 hristov
89 New version (B.Yordanov)
90
d477ad88 91 Revision 1.5 2005/11/21 09:03:48 byordano
92 one more print added
93
94 Revision 1.4 2005/11/20 10:12:37 byordano
95 comments added to AliShuttleTrigger
96
97 */
98
99
100//
101// This class is to deal with DAQ LogBook and DAQ "end of run" notification.
102// It has severeal two modes:
cb343cfd 103// 1) synchronized - Collect()
b948db8d 104// 2) asynchronized - Run() - starts listening for DAQ "end of run"
d477ad88 105// notification by DIM service.
106//
107
108#include "AliShuttleTrigger.h"
109
d477ad88 110#include <TSystem.h>
cb343cfd 111
d477ad88 112#include "AliLog.h"
d477ad88 113#include "AliShuttleConfig.h"
114#include "AliShuttle.h"
115#include "DATENotifier.h"
116
117ClassImp(TerminateSignalHandler)
cb343cfd 118ClassImp(AliShuttleTrigger)
58bc3020 119
b948db8d 120//______________________________________________________________________________________________
cb343cfd 121Bool_t TerminateSignalHandler::Notify()
58bc3020 122{
123// Sentd terminate command to the Shuttle trigger
d477ad88 124
125 AliInfo("Terminate signal received ...");
126 fTrigger->Terminate();
127
128 return kTRUE;
129}
130
b948db8d 131//______________________________________________________________________________________________
ff3781ad 132AliShuttleTrigger::AliShuttleTrigger(const AliShuttleConfig* config):
b948db8d 133 fConfig(config), fShuttle(NULL),
2bb7b766 134 fNotified(kFALSE), fTerminate(kFALSE),
4f0ab988 135 fMutex(), fCondition(&fMutex),
cb343cfd 136 fQuitSignalHandler(0),
137 fInterruptSignalHandler(0)
d477ad88 138{
139 //
140 // config - pointer to the AliShuttleConfig object which represents
141 // the configuration
b948db8d 142 // mainStorage - pointer to AliCDBStorage for the undelying CDBStorage
143 // localStorage (local) CDB storage to be used if mainStorage is unavailable
d477ad88 144 //
145
7d4cf768 146 if (!fConfig->IsValid()) AliFatal("********** !!!!! Invalid configuration !!!!! **********");
ff3781ad 147 UInt_t timeout = fConfig->GetDCSTimeOut();
148 Int_t retries = fConfig->GetDCSRetries();
b948db8d 149 fShuttle = new AliShuttle(config, timeout, retries);
d477ad88 150
28a94b8e 151 fQuitSignalHandler = new TerminateSignalHandler(this, kSigQuit);
152 fInterruptSignalHandler = new TerminateSignalHandler(this, kSigInterrupt);
58bc3020 153
cb343cfd 154 gSystem->AddSignalHandler(fQuitSignalHandler);
155 gSystem->AddSignalHandler(fInterruptSignalHandler);
58bc3020 156
157}
158
b948db8d 159//______________________________________________________________________________________________
58bc3020 160AliShuttleTrigger::~AliShuttleTrigger()
161{
cb343cfd 162 // destructor
d477ad88 163
cb343cfd 164 gSystem->RemoveSignalHandler(fQuitSignalHandler);
165 gSystem->RemoveSignalHandler(fInterruptSignalHandler);
d477ad88 166
167 delete fShuttle;
cb343cfd 168
169 delete fQuitSignalHandler;
170 fQuitSignalHandler = 0;
171
172 delete fInterruptSignalHandler;
173 fInterruptSignalHandler = 0;
d477ad88 174}
175
b948db8d 176//______________________________________________________________________________________________
d477ad88 177Bool_t AliShuttleTrigger::Notify() {
178 //
cb343cfd 179 // Trigger Collect() methods in asynchronized (listen) mode.
d477ad88 180 // Usually called automaticly by DATENotifier on "end of run"
181 // notification event.
182 //
183
184 fMutex.Lock();
185
186 fNotified = kTRUE;
187 fCondition.Signal();
188
189 fMutex.UnLock();
190
191 return kTRUE;
192}
193
b948db8d 194//______________________________________________________________________________________________
d477ad88 195void AliShuttleTrigger::Terminate() {
196 //
197 // Stop triggers listen mode and exist from Run()
198 // Usually called automaticly by TerminateSignalHandler.
199 //
200
201 fTerminate = kTRUE;
202 fCondition.Signal();
203}
204
b948db8d 205//______________________________________________________________________________________________
d477ad88 206void AliShuttleTrigger::Run() {
207 //
208 // AliShuttleTrigger main loop for asynchronized (listen) mode.
209 // It spawns DIM service listener and waits for DAQ "end of run"
cb343cfd 210 // notification. Calls Collect() on notification.
d477ad88 211 //
212
213 fTerminate = kFALSE;
214
4a5d9e0d 215 DATENotifier* notifier = new DATENotifier(this, "/LOGBOOK/SUBSCRIBE/ECS_EOR");
d477ad88 216
6a926ad4 217 Int_t nTry=0;
218 Int_t nMaxTry = fConfig->GetMaxRetries()+1;
219 Int_t received=0;
220
221 AliInfo("Listening for ECS trigger");
7d4cf768 222
d477ad88 223 while (1) {
224
225 fMutex.Lock();
226
227 while (!(fNotified || fTerminate)) {
6a926ad4 228 received=fCondition.TimedWaitRelative(1000*fConfig->GetTriggerWait());
229 if (received==1) break; // 1 = timeout
d477ad88 230 }
231
232 fNotified = kFALSE;
233
234 fMutex.UnLock();
235
236 if (fTerminate) {
237 AliInfo("Terminated.");
238 break;
239 }
7d4cf768 240
6a926ad4 241 if (received == 0)
242 {
243 AliInfo("Trigger from ECS received!");
244 } else if (received == 1) {
245 AliInfo(Form("Timeout (%d s) waiting for trigger. "
246 "Starting collection of new runs!",
247 fConfig->GetTriggerWait()));
248 } else {
249 AliInfo("Error receiving trigger from ECS!");
250 break;
251 }
252
1abfbb60 253 nTry++;
254 AliInfo(Form("Received %d triggers so far", nTry));
255
6a926ad4 256 if (fConfig->GetRunMode() == AliShuttleConfig::kTest)
257 {
6a926ad4 258 if(nTry>=nMaxTry)
259 {
260 AliInfo(Form("Collect() ran more than %d times -> Exiting!",
261 nMaxTry));
262 break;
263 }
264 }
d477ad88 265
cb343cfd 266 Collect();
d477ad88 267 }
268
269 delete notifier;
270}
271
b948db8d 272//______________________________________________________________________________________________
a7160fe9 273Bool_t AliShuttleTrigger::Collect(Int_t run)
58bc3020 274{
d477ad88 275 //
cb343cfd 276 // this function creates a thread that runs the shuttle
277 // then it checks if the shuttle is still running by checking the monitoring functions of the shuttle
d477ad88 278 //
279
cb343cfd 280 return fShuttle->Collect(run);
d477ad88 281}