]> git.uio.no Git - u/mrichter/AliRoot.git/blob - SHUTTLE/AliShuttleTrigger.cxx
nextMessage removed from client
[u/mrichter/AliRoot.git] / SHUTTLE / AliShuttleTrigger.cxx
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.12  2006/10/20 15:22:59  jgrosseo
19  o) Adding time out to the execution of the preprocessors: The Shuttle forks and the parent process monitors the child
20  o) Merging Collect, CollectAll, CollectNew function
21  o) Removing implementation of empty copy constructors (declaration still there!)
22
23  Revision 1.11  2006/10/02 16:38:39  jgrosseo
24  update (alberto):
25  fixed memory leaks
26  storing of objects that failed to be stored to the grid before
27  interfacing of shuttle status table in daq system
28
29  Revision 1.10  2006/08/15 10:50:00  jgrosseo
30  effc++ corrections (alberto)
31
32  Revision 1.9  2006/08/08 14:19:29  jgrosseo
33  Update to shuttle classes (Alberto)
34
35  - Possibility to set the full object's path in the Preprocessor's and
36  Shuttle's  Store functions
37  - Possibility to extend the object's run validity in the same classes
38  ("startValidity" and "validityInfinite" parameters)
39  - Implementation of the StoreReferenceData function to store reference
40  data in a dedicated CDB storage.
41
42  Revision 1.8  2006/07/21 07:37:20  jgrosseo
43  last run is stored after each run
44
45  Revision 1.7  2006/07/20 09:54:40  jgrosseo
46  introducing status management: The processing per subdetector is divided into several steps,
47  after each step the status is stored on disk. If the system crashes in any of the steps the Shuttle
48  can keep track of the number of failures and skips further processing after a certain threshold is
49  exceeded. These thresholds can be configured in LDAP.
50
51  Revision 1.6  2006/07/19 10:09:55  jgrosseo
52  new configuration, accesst to DAQ FES (Alberto)
53
54  Revision 1.5  2006/07/10 13:01:41  jgrosseo
55  enhanced storing of last sucessfully processed run (alberto)
56
57  Revision 1.4  2006/07/04 14:59:57  jgrosseo
58  revision of AliDCSValue: Removed wrapper classes, reduced storage size per value by factor 2
59
60  Revision 1.3  2006/06/12 09:11:16  jgrosseo
61  coding conventions (Alberto)
62
63  Revision 1.2  2006/06/06 14:26:40  jgrosseo
64  o) removed files that were moved to STEER
65  o) shuttle updated to follow the new interface (Alberto)
66
67  Revision 1.1  2006/03/07 07:52:34  hristov
68  New version (B.Yordanov)
69
70  Revision 1.5  2005/11/21 09:03:48  byordano
71  one more print added
72
73  Revision 1.4  2005/11/20 10:12:37  byordano
74  comments added to AliShuttleTrigger
75
76  */
77
78
79 // 
80 // This class is to deal with DAQ LogBook and DAQ "end of run" notification.
81 // It has severeal two modes:
82 //      1) synchronized - Collect()
83 //      2) asynchronized - Run() - starts listening for DAQ "end of run"
84 //              notification by DIM service.
85 //
86
87 #include "AliShuttleTrigger.h"
88
89 #include <TSystem.h>
90
91 #include "AliLog.h"
92 #include "AliShuttleConfig.h"
93 #include "AliShuttle.h"
94 #include "DATENotifier.h"
95
96 ClassImp(TerminateSignalHandler)
97 ClassImp(AliShuttleTrigger)
98
99 //______________________________________________________________________________________________
100 Bool_t TerminateSignalHandler::Notify()
101 {
102 // Sentd terminate command to the Shuttle trigger
103
104         AliInfo("Terminate signal received ...");
105         fTrigger->Terminate();
106
107         return kTRUE;
108 }
109
110 //______________________________________________________________________________________________
111 AliShuttleTrigger::AliShuttleTrigger(const AliShuttleConfig* config,
112                 UInt_t timeout, Int_t retries):
113         fConfig(config), fShuttle(NULL),
114         fNotified(kFALSE), fTerminate(kFALSE),
115         fMutex(), fCondition(&fMutex),
116         fQuitSignalHandler(0),
117         fInterruptSignalHandler(0)
118 {
119         //
120         // config - pointer to the AliShuttleConfig object which represents
121         // the configuration
122         // mainStorage - pointer to AliCDBStorage for the undelying CDBStorage
123         // localStorage (local) CDB storage to be used if mainStorage is unavailable
124         //
125
126         fShuttle = new AliShuttle(config, timeout, retries);
127
128         TerminateSignalHandler* fQuitSignalHandler = new TerminateSignalHandler(this, kSigQuit);
129         TerminateSignalHandler* fInterruptSignalHandler = new TerminateSignalHandler(this, kSigInterrupt);
130
131         gSystem->AddSignalHandler(fQuitSignalHandler);
132         gSystem->AddSignalHandler(fInterruptSignalHandler);
133
134 }
135
136 //______________________________________________________________________________________________
137 AliShuttleTrigger::~AliShuttleTrigger() 
138 {
139   // destructor
140
141         gSystem->RemoveSignalHandler(fQuitSignalHandler);
142         gSystem->RemoveSignalHandler(fInterruptSignalHandler);
143
144         delete fShuttle;
145
146   delete fQuitSignalHandler;
147   fQuitSignalHandler = 0;
148
149   delete fInterruptSignalHandler;
150   fInterruptSignalHandler = 0;
151 }
152
153 //______________________________________________________________________________________________
154 Bool_t AliShuttleTrigger::Notify() {
155         //
156         // Trigger Collect() methods in asynchronized (listen) mode.
157         // Usually called automaticly by DATENotifier on "end of run" 
158         // notification event.
159         //
160
161         fMutex.Lock();
162
163         fNotified = kTRUE;
164         fCondition.Signal();
165
166         fMutex.UnLock();
167
168         return kTRUE;
169 }
170
171 //______________________________________________________________________________________________
172 void AliShuttleTrigger::Terminate() {
173         //
174         // Stop triggers listen mode and exist from Run()
175         // Usually called automaticly by TerminateSignalHandler.
176         //
177
178         fTerminate = kTRUE;
179         fCondition.Signal();
180 }
181
182 //______________________________________________________________________________________________
183 void AliShuttleTrigger::Run() {
184         //
185         // AliShuttleTrigger main loop for asynchronized (listen) mode.
186         // It spawns DIM service listener and waits for DAQ "end of run"
187         // notification. Calls Collect() on notification.
188         //
189
190         fTerminate = kFALSE;
191
192         DATENotifier* notifier = new DATENotifier(this, "/DATE/LOGBOOK/UPDATE");
193
194         while (1) {
195         
196                 fMutex.Lock();
197
198                 while (!(fNotified || fTerminate)) {
199                         fCondition.Wait();
200                 }
201
202                 fNotified = kFALSE;
203                 
204                 fMutex.UnLock();
205
206                 if (fTerminate) {
207                         AliInfo("Terminated.");
208                         break;          
209                 }
210         
211                 Collect();
212         }
213
214         delete notifier;
215 }
216
217 //______________________________________________________________________________________________
218 Bool_t AliShuttleTrigger::Collect(Int_t run)
219 {
220         //
221         // this function creates a thread that runs the shuttle
222         // then it checks if the shuttle is still running by checking the monitoring functions of the shuttle
223         //
224
225   return fShuttle->Collect(run);
226 }