AliRoot Core  v5-06-30 (35d6c57)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliOnlineRecoTrigger.cxx
Go to the documentation of this file.
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 #include "AliOnlineRecoTrigger.h"
17 
18 #include <TSystem.h>
19 
20 #include "AliLog.h"
21 #ifdef ALI_DIM
22 #include "SORNotifier.h"
23 #endif
24 
27 
28 //______________________________________________________________________________________________
29 Bool_t TerminateSignalHandler::Notify()
30 {
31 // Sentd terminate command to the Shuttle trigger
32 
33  AliInfo("Terminate signal received ...");
34  fTrigger->Terminate();
35 
36  return kTRUE;
37 }
38 
39 //______________________________________________________________________________________________
41  fNotified(kFALSE), fTerminate(kFALSE),
42  fMutex(), fCondition(&fMutex),
43  fQuitSignalHandler(0),
44  fInterruptSignalHandler(0)
45 {
46  // Default constructor
47  //
48 
49  fQuitSignalHandler = new TerminateSignalHandler(this, kSigQuit);
50  fInterruptSignalHandler = new TerminateSignalHandler(this, kSigInterrupt);
51 
52  gSystem->AddSignalHandler(fQuitSignalHandler);
53  gSystem->AddSignalHandler(fInterruptSignalHandler);
54 }
55 
56 //______________________________________________________________________________________________
58 {
59  // destructor
60 
61  gSystem->RemoveSignalHandler(fQuitSignalHandler);
62  gSystem->RemoveSignalHandler(fInterruptSignalHandler);
63 
64  delete fQuitSignalHandler;
66 
69 }
70 
71 //______________________________________________________________________________________________
73  //
74  // The method is called automaticly by SORNotifier on "start of run"
75  // notification event from ECS
76  //
77 
78  fMutex.Lock();
79 
80  fNotified = kTRUE;
81  fCondition.Signal();
82 
83  fMutex.UnLock();
84 
85  return kTRUE;
86 }
87 
88 //______________________________________________________________________________________________
90  //
91  // Stop triggers listen mode and exist from Run()
92  // Usually called automaticly by TerminateSignalHandler.
93  //
94 
95  fTerminate = kTRUE;
96  fCondition.Signal();
97 }
98 
99 //______________________________________________________________________________________________
101  //
102  // AliOnlineRecoTrigger main loop for asynchronized (listen) mode.
103  // It spawns DIM service listener and waits for DAQ "start of run"
104  // notification.
105  //
106 
107  fTerminate = kFALSE;
108 
109 #ifdef ALI_DIM
110  SORNotifier* notifier = new SORNotifier(this);
111 #endif
112  Int_t received=0;
113 
114  AliInfo("Listening for ECS SOR trigger");
115 
116  fMutex.Lock();
117 
118  while (!(fNotified || fTerminate)) {
119  received=fCondition.TimedWaitRelative(1000*86400); //wait 24h
120  if (received==1) break; // 1 = timeout
121  }
122 
123  fNotified = kFALSE;
124 
125  fMutex.UnLock();
126 
127  Int_t run = -1;
128 #ifdef ALI_DIM
129  run = notifier->GetRun();
130  delete notifier;
131 #endif
132 
133  if (fTerminate) {
134  AliInfo("Terminated.");
135  return -1;
136  }
137 
138  if (received == 0)
139  {
140  AliInfo("Trigger from ECS received!");
141  if (run < 0) {
142  AliError("Invalid run number received!");
143  return -1;
144  }
145  return run;
146  } else if (received == 1) {
147  AliWarning("Timeout waiting for trigger!");
148  return -1;
149  } else {
150  AliError("Error receiving trigger from ECS!");
151  return -1;
152  }
153 }
ClassImp(TerminateSignalHandler) ClassImp(AliOnlineRecoTrigger) Bool_t TerminateSignalHandler
TerminateSignalHandler * fQuitSignalHandler
TerminateSignalHandler * fInterruptSignalHandler
int GetRun() const
Definition: SORNotifier.h:30