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