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