]> git.uio.no Git - u/mrichter/AliRoot.git/blame_incremental - SHUTTLE/AliShuttleTrigger.cxx
several bugfixes
[u/mrichter/AliRoot.git] / SHUTTLE / AliShuttleTrigger.cxx
... / ...
CommitLineData
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$
18 Revision 1.15 2007/12/10 18:29:23 acolla
19 Some log added to the listen mode
20
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
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
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
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
50 Revision 1.10 2006/08/15 10:50:00 jgrosseo
51 effc++ corrections (alberto)
52
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
63 Revision 1.8 2006/07/21 07:37:20 jgrosseo
64 last run is stored after each run
65
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
72 Revision 1.6 2006/07/19 10:09:55 jgrosseo
73 new configuration, accesst to DAQ FES (Alberto)
74
75 Revision 1.5 2006/07/10 13:01:41 jgrosseo
76 enhanced storing of last sucessfully processed run (alberto)
77
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
81 Revision 1.3 2006/06/12 09:11:16 jgrosseo
82 coding conventions (Alberto)
83
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
88 Revision 1.1 2006/03/07 07:52:34 hristov
89 New version (B.Yordanov)
90
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:
103// 1) synchronized - Collect()
104// 2) asynchronized - Run() - starts listening for DAQ "end of run"
105// notification by DIM service.
106//
107
108#include "AliShuttleTrigger.h"
109
110#include <TSystem.h>
111
112#include "AliLog.h"
113#include "AliShuttleConfig.h"
114#include "AliShuttle.h"
115#include "DATENotifier.h"
116
117ClassImp(TerminateSignalHandler)
118ClassImp(AliShuttleTrigger)
119
120//______________________________________________________________________________________________
121Bool_t TerminateSignalHandler::Notify()
122{
123// Sentd terminate command to the Shuttle trigger
124
125 AliInfo("Terminate signal received ...");
126 fTrigger->Terminate();
127
128 return kTRUE;
129}
130
131//______________________________________________________________________________________________
132AliShuttleTrigger::AliShuttleTrigger(const AliShuttleConfig* config,
133 UInt_t timeout, Int_t retries):
134 fConfig(config), fShuttle(NULL),
135 fNotified(kFALSE), fTerminate(kFALSE),
136 fMutex(), fCondition(&fMutex),
137 fQuitSignalHandler(0),
138 fInterruptSignalHandler(0)
139{
140 //
141 // config - pointer to the AliShuttleConfig object which represents
142 // the configuration
143 // mainStorage - pointer to AliCDBStorage for the undelying CDBStorage
144 // localStorage (local) CDB storage to be used if mainStorage is unavailable
145 //
146
147 if (!fConfig->IsValid()) AliFatal("********** !!!!! Invalid configuration !!!!! **********");
148 fShuttle = new AliShuttle(config, timeout, retries);
149
150 TerminateSignalHandler* fQuitSignalHandler = new TerminateSignalHandler(this, kSigQuit);
151 TerminateSignalHandler* fInterruptSignalHandler = new TerminateSignalHandler(this, kSigInterrupt);
152
153 gSystem->AddSignalHandler(fQuitSignalHandler);
154 gSystem->AddSignalHandler(fInterruptSignalHandler);
155
156}
157
158//______________________________________________________________________________________________
159AliShuttleTrigger::~AliShuttleTrigger()
160{
161 // destructor
162
163 gSystem->RemoveSignalHandler(fQuitSignalHandler);
164 gSystem->RemoveSignalHandler(fInterruptSignalHandler);
165
166 delete fShuttle;
167
168 delete fQuitSignalHandler;
169 fQuitSignalHandler = 0;
170
171 delete fInterruptSignalHandler;
172 fInterruptSignalHandler = 0;
173}
174
175//______________________________________________________________________________________________
176Bool_t AliShuttleTrigger::Notify() {
177 //
178 // Trigger Collect() methods in asynchronized (listen) mode.
179 // Usually called automaticly by DATENotifier on "end of run"
180 // notification event.
181 //
182
183 fMutex.Lock();
184
185 fNotified = kTRUE;
186 fCondition.Signal();
187
188 fMutex.UnLock();
189
190 return kTRUE;
191}
192
193//______________________________________________________________________________________________
194void AliShuttleTrigger::Terminate() {
195 //
196 // Stop triggers listen mode and exist from Run()
197 // Usually called automaticly by TerminateSignalHandler.
198 //
199
200 fTerminate = kTRUE;
201 fCondition.Signal();
202}
203
204//______________________________________________________________________________________________
205void AliShuttleTrigger::Run() {
206 //
207 // AliShuttleTrigger main loop for asynchronized (listen) mode.
208 // It spawns DIM service listener and waits for DAQ "end of run"
209 // notification. Calls Collect() on notification.
210 //
211
212 fTerminate = kFALSE;
213
214 DATENotifier* notifier = new DATENotifier(this, "/DATE/LOGBOOK/UPDATE");
215
216 Int_t nTry=0;
217 Int_t nMaxTry = fConfig->GetMaxRetries()+1;
218 Int_t received=0;
219
220 AliInfo("Listening for ECS trigger");
221
222 while (1) {
223
224 fMutex.Lock();
225
226 while (!(fNotified || fTerminate)) {
227 received=fCondition.TimedWaitRelative(1000*fConfig->GetTriggerWait());
228 if (received==1) break; // 1 = timeout
229 }
230
231 fNotified = kFALSE;
232
233 fMutex.UnLock();
234
235 if (fTerminate) {
236 AliInfo("Terminated.");
237 break;
238 }
239
240 if (received == 0)
241 {
242 AliInfo("Trigger from ECS received!");
243 } else if (received == 1) {
244 AliInfo(Form("Timeout (%d s) waiting for trigger. "
245 "Starting collection of new runs!",
246 fConfig->GetTriggerWait()));
247 } else {
248 AliInfo("Error receiving trigger from ECS!");
249 break;
250 }
251
252 nTry++;
253 AliInfo(Form("Received %d triggers so far", nTry));
254
255 if (fConfig->GetRunMode() == AliShuttleConfig::kTest)
256 {
257 if(nTry>=nMaxTry)
258 {
259 AliInfo(Form("Collect() ran more than %d times -> Exiting!",
260 nMaxTry));
261 break;
262 }
263 }
264
265 Collect();
266 }
267
268 delete notifier;
269}
270
271//______________________________________________________________________________________________
272Bool_t AliShuttleTrigger::Collect(Int_t run)
273{
274 //
275 // this function creates a thread that runs the shuttle
276 // then it checks if the shuttle is still running by checking the monitoring functions of the shuttle
277 //
278
279 return fShuttle->Collect(run);
280}