Adding interruption handler to the DATE online raw-data reader. Will be used by the...
[u/mrichter/AliRoot.git] / RAW / AliRawReaderDateOnline.cxx
CommitLineData
3b98a4d4 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///
18/// This is a class for reading raw data from a date monitoring libraries.
19/// It supports two modes - event taken from shared memory via DATE monitoring
20/// libs, or an emulation mode when the events are taken from a DATE file using
21/// the same monitoring libs.
22/// The constructor requires an argument:
23///
24/// : - events are taken from shared memory
25/// or
26/// <DATE_filename> - events are taken from date file
27///
28/// Cvetan Cheshkov 1/04/2008
29///////////////////////////////////////////////////////////////////////////////
e5705501 30#include <TSystem.h>
3b98a4d4 31
32#include "AliRawReaderDateOnline.h"
36a7d3c6 33#include "AliLog.h"
34#ifdef ALI_DATE
35#include "event.h"
36#include "monitor.h"
37#endif
3b98a4d4 38
39ClassImp(AliRawReaderDateOnline)
40
36a7d3c6 41AliRawReaderDateOnline::AliRawReaderDateOnline(
3b98a4d4 42#ifdef ALI_DATE
43 const char* filename
44#else
45 const char* /* filename */
46#endif
47 ) :
e5705501 48 AliRawReaderDate((void*)NULL),
49 fStop(kFALSE)
3b98a4d4 50{
51
52// Constructor
53// Initialize the DATE monitoring libs
54
55#ifdef ALI_DATE
56
b2d2e1ea 57
58 // Removal of the selection of physics events
59 // Requested by Filimon and FMD experts
60 // fSelectEventType = PHYSICS_EVENT;
00665a00 61
3b98a4d4 62 int status;
63
64 /* define data source : this is argument 1 */
36a7d3c6 65 status=monitorSetDataSource( (char* )filename );
3b98a4d4 66 if (status!=0) {
67 AliFatal(Form("monitorSetDataSource() failed : %s",monitorDecodeError(status)));
68 }
69
70 /* declare monitoring program */
71 status=monitorDeclareMp( __FILE__ );
72 if (status!=0) {
73 AliFatal(Form("monitorDeclareMp() failed : %s",monitorDecodeError(status)));
74 }
75
76 /* define wait event timeout - 1s max */
77 monitorSetNowait();
78 monitorSetNoWaitNetworkTimeout(1000);
a077ccfa 79
80 const Char_t* table[] = {"ALL", "yes", "*", "*",
81 "EOR", "all","*", "*",
82 NULL, NULL, NULL, NULL};
83 monitorDeclareTableExtended(const_cast<char**>(table));
84
e5705501 85 // install SIGUSR1 handler to allow clean end-of-events loop
86 gSystem->AddSignalHandler(new AliRawReaderDateIntHandler(this));
87
3b98a4d4 88#else
89 Fatal("AliRawReaderDateOnline", "this class was compiled without DATE");
90#endif
91}
92
36a7d3c6 93Bool_t AliRawReaderDateOnline::NextEvent()
3b98a4d4 94{
95// wait and get the next event
96// from shared memory
97
98#ifdef ALI_DATE
99
e5705501 100 // Stop on SIGUSR1
101 if (fStop) {
102 AliInfo("Raw-data reading stopped by SIGUSR1");
103 return kFALSE;
104 }
105
36a7d3c6 106 // Event already loaded no need take a new one
107 if (AliRawReaderDate::NextEvent()) return kTRUE;
108
3b98a4d4 109 if (fEvent) free(fEvent);
36a7d3c6 110 fEvent = NULL;
3b98a4d4 111
112 while (1) {
113 /* get next event (blocking call until timeout) */
36a7d3c6 114 int status=monitorGetEventDynamic((void**)&fEvent);
3b98a4d4 115
00665a00 116 if (status==MON_ERR_EOF) {
3b98a4d4 117 AliInfo("End of File detected");
36a7d3c6 118 Reset();
119 fEvent = NULL;
3b98a4d4 120 return kFALSE; /* end of monitoring file has been reached */
121 }
122
123 if (status!=0) {
124 AliError(Form("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status)));
36a7d3c6 125 Reset();
126 fEvent = NULL;
3b98a4d4 127 return kFALSE;
128 }
129
130 /* retry if got no event */
36a7d3c6 131 if (fEvent==NULL) {
3b98a4d4 132 continue;
133 }
36a7d3c6 134
135 eventTypeType eventT=fEvent->eventType;
3b98a4d4 136 /* exit when last event received, no need to wait for TERM signal */
137 if (eventT==END_OF_RUN) {
138 AliInfo("EOR event detected");
36a7d3c6 139 Reset();
e933e49f 140 free(fEvent);
36a7d3c6 141 fEvent = NULL;
3b98a4d4 142 return kFALSE;
143 }
36a7d3c6 144
00665a00 145 if (!IsEventSelected()) {
e933e49f 146 free(fEvent);
3b98a4d4 147 continue;
148 }
149
00665a00 150 AliInfo(Form("Run #%lu, event size: %lu, BC:0x%x, Orbit:0x%x, Period:0x%x",
36a7d3c6 151 (unsigned long)fEvent->eventRunNb,
152 (unsigned long)fEvent->eventSize,
153 EVENT_ID_GET_BUNCH_CROSSING(fEvent->eventId),
154 EVENT_ID_GET_ORBIT(fEvent->eventId),
155 EVENT_ID_GET_PERIOD(fEvent->eventId)
3b98a4d4 156 ));
36a7d3c6 157 break;
3b98a4d4 158 }
159
36a7d3c6 160 fEventNumber++;
161 Reset();
3b98a4d4 162
36a7d3c6 163 return kTRUE;
3b98a4d4 164
36a7d3c6 165}
166
167#else
3b98a4d4 168 return kFALSE;
169}
36a7d3c6 170#endif
3b98a4d4 171
36a7d3c6 172AliRawReaderDateOnline::~AliRawReaderDateOnline()
173{
174// Destructor
175// Free the last event in shared memory
3b98a4d4 176
36a7d3c6 177#ifdef ALI_DATE
178 if (fEvent) free(fEvent);
179#endif
180}
20e6c4f4 181
182void AliRawReaderDateOnline::SelectEvents(Int_t type,
183 ULong64_t triggerMask,
184 const char *triggerExpr)
185{
186 // Select event by using DATE monitoring
187 // library
188#ifdef ALI_DATE
189 const Char_t* table[] = {"ALL", "no", "*", "*",
a077ccfa 190 "PHY", "yes","*", "*",
191 "EOR", "all","*", "*",
192 NULL, NULL, NULL, NULL};
20e6c4f4 193 TString trSelection;
194 for (Int_t i = 0; i < 50; i++) {
195 if (triggerMask & (1ull << i)) {
48b5e3f8 196 if (!trSelection.IsNull()) trSelection += "&";
20e6c4f4 197 trSelection += Form("%d",i+1);
198 }
199 }
200 table[7] = trSelection.Data();
201
202 monitorDeclareTableExtended(const_cast<char**>(table));
203
204#endif
205 AliRawReader::SelectEvents(type,triggerMask,triggerExpr);
206}
e5705501 207
208//______________________________________________________________________________
209void AliRawReaderDateOnline::Stop()
210{
211 // Stop the event loop (called on SIGUSR1)
212
213 fStop = kTRUE;
214}