]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MONITOR/AliOnlineRecoTrigger.cxx
Using large-file extension version of fopen.
[u/mrichter/AliRoot.git] / MONITOR / AliOnlineRecoTrigger.cxx
CommitLineData
c989b443 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"
bef53f4a 21#ifdef ALI_DIM
c989b443 22#include "SORNotifier.h"
23#endif
24
25ClassImp(TerminateSignalHandler)
26ClassImp(AliOnlineRecoTrigger)
27
28//______________________________________________________________________________________________
29Bool_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//______________________________________________________________________________________________
40AliOnlineRecoTrigger::AliOnlineRecoTrigger():
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//______________________________________________________________________________________________
57AliOnlineRecoTrigger::~AliOnlineRecoTrigger()
58{
59 // destructor
60
61 gSystem->RemoveSignalHandler(fQuitSignalHandler);
62 gSystem->RemoveSignalHandler(fInterruptSignalHandler);
63
64 delete fQuitSignalHandler;
65 fQuitSignalHandler = 0;
66
67 delete fInterruptSignalHandler;
68 fInterruptSignalHandler = 0;
69}
70
71//______________________________________________________________________________________________
72Bool_t AliOnlineRecoTrigger::Notify() {
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//______________________________________________________________________________________________
89void AliOnlineRecoTrigger::Terminate() {
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//______________________________________________________________________________________________
100Int_t AliOnlineRecoTrigger::Run() {
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
bef53f4a 109#ifdef ALI_DIM
c989b443 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;
bef53f4a 128#ifdef ALI_DIM
c989b443 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}