]> git.uio.no Git - u/mrichter/AliRoot.git/blame - RAW/AliRawReaderDateOnline.cxx
Test for Coverity
[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>
3617024b 31#include <cstdlib>
3b98a4d4 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
a3c2f91e 41Bool_t AliRawReaderDateOnline::fgNoSleep = kTRUE;
42
36a7d3c6 43AliRawReaderDateOnline::AliRawReaderDateOnline(
3b98a4d4 44#ifdef ALI_DATE
c0f9fd2d 45 const char* filename
3b98a4d4 46#else
c0f9fd2d 47 const char* /* filename */
3b98a4d4 48#endif
c0f9fd2d 49 , const Char_t** customTable) :
e5705501 50 AliRawReaderDate((void*)NULL),
c0f9fd2d 51 fTable(customTable),
e5705501 52 fStop(kFALSE)
3b98a4d4 53{
54
55// Constructor
56// Initialize the DATE monitoring libs
57
58#ifdef ALI_DATE
59
b2d2e1ea 60
61 // Removal of the selection of physics events
62 // Requested by Filimon and FMD experts
63 // fSelectEventType = PHYSICS_EVENT;
00665a00 64
3b98a4d4 65 int status;
66
67 /* define data source : this is argument 1 */
36a7d3c6 68 status=monitorSetDataSource( (char* )filename );
3b98a4d4 69 if (status!=0) {
70 AliFatal(Form("monitorSetDataSource() failed : %s",monitorDecodeError(status)));
71 }
72
73 /* declare monitoring program */
74 status=monitorDeclareMp( __FILE__ );
75 if (status!=0) {
76 AliFatal(Form("monitorDeclareMp() failed : %s",monitorDecodeError(status)));
77 }
78
79 /* define wait event timeout - 1s max */
80 monitorSetNowait();
81 monitorSetNoWaitNetworkTimeout(1000);
a077ccfa 82
c0f9fd2d 83 if (!fTable) {
84 const Char_t* table[] = {"ALL", "few", "*", "*",
85 "EOR", "yes","*", "*",
86 NULL, NULL, NULL, NULL};
87 monitorDeclareTableExtended(const_cast<char**>(table));
88 }
89 else {
90 AliInfo("Custom monitoring table:");
91 Int_t index = 0;
92 while (fTable[index] != NULL) {
93 AliInfo(Form("%s %s %s %s",fTable[index],fTable[index+1],fTable[index+2],fTable[index+3]));
94 index += 4;
95 }
96 monitorDeclareTableExtended(const_cast<char**>(fTable));
97 }
e5705501 98 // install SIGUSR1 handler to allow clean end-of-events loop
99 gSystem->AddSignalHandler(new AliRawReaderDateIntHandler(this));
100
3b98a4d4 101#else
102 Fatal("AliRawReaderDateOnline", "this class was compiled without DATE");
103#endif
104}
105
36a7d3c6 106Bool_t AliRawReaderDateOnline::NextEvent()
3b98a4d4 107{
108// wait and get the next event
109// from shared memory
110
111#ifdef ALI_DATE
112
e5705501 113 // Stop on SIGUSR1
114 if (fStop) {
115 AliInfo("Raw-data reading stopped by SIGUSR1");
dae597de 116 if (fEvent) free(fEvent);
117 fEvent = NULL;
e5705501 118 return kFALSE;
119 }
120
36a7d3c6 121 // Event already loaded no need take a new one
122 if (AliRawReaderDate::NextEvent()) return kTRUE;
123
3b98a4d4 124 if (fEvent) free(fEvent);
36a7d3c6 125 fEvent = NULL;
3b98a4d4 126
127 while (1) {
128 /* get next event (blocking call until timeout) */
36a7d3c6 129 int status=monitorGetEventDynamic((void**)&fEvent);
3b98a4d4 130
00665a00 131 if (status==MON_ERR_EOF) {
3b98a4d4 132 AliInfo("End of File detected");
36a7d3c6 133 Reset();
134 fEvent = NULL;
3b98a4d4 135 return kFALSE; /* end of monitoring file has been reached */
136 }
137
138 if (status!=0) {
139 AliError(Form("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status)));
36a7d3c6 140 Reset();
141 fEvent = NULL;
3b98a4d4 142 return kFALSE;
143 }
144
145 /* retry if got no event */
36a7d3c6 146 if (fEvent==NULL) {
a3c2f91e 147 if (fgNoSleep) gSystem->ProcessEvents();
3b98a4d4 148 continue;
149 }
36a7d3c6 150
151 eventTypeType eventT=fEvent->eventType;
3b98a4d4 152 /* exit when last event received, no need to wait for TERM signal */
153 if (eventT==END_OF_RUN) {
154 AliInfo("EOR event detected");
36a7d3c6 155 Reset();
e933e49f 156 free(fEvent);
36a7d3c6 157 fEvent = NULL;
3b98a4d4 158 return kFALSE;
159 }
36a7d3c6 160
00665a00 161 if (!IsEventSelected()) {
e933e49f 162 free(fEvent);
dae597de 163 fEvent = NULL;
a3c2f91e 164 if (fgNoSleep) gSystem->ProcessEvents();
3b98a4d4 165 continue;
166 }
167
00665a00 168 AliInfo(Form("Run #%lu, event size: %lu, BC:0x%x, Orbit:0x%x, Period:0x%x",
36a7d3c6 169 (unsigned long)fEvent->eventRunNb,
170 (unsigned long)fEvent->eventSize,
171 EVENT_ID_GET_BUNCH_CROSSING(fEvent->eventId),
172 EVENT_ID_GET_ORBIT(fEvent->eventId),
173 EVENT_ID_GET_PERIOD(fEvent->eventId)
3b98a4d4 174 ));
36a7d3c6 175 break;
3b98a4d4 176 }
177
36a7d3c6 178 fEventNumber++;
179 Reset();
3b98a4d4 180
36a7d3c6 181 return kTRUE;
3b98a4d4 182
36a7d3c6 183}
184
185#else
3b98a4d4 186 return kFALSE;
187}
36a7d3c6 188#endif
3b98a4d4 189
36a7d3c6 190AliRawReaderDateOnline::~AliRawReaderDateOnline()
191{
192// Destructor
193// Free the last event in shared memory
3b98a4d4 194
36a7d3c6 195#ifdef ALI_DATE
196 if (fEvent) free(fEvent);
197#endif
198}
20e6c4f4 199
200void AliRawReaderDateOnline::SelectEvents(Int_t type,
201 ULong64_t triggerMask,
202 const char *triggerExpr)
203{
204 // Select event by using DATE monitoring
205 // library
206#ifdef ALI_DATE
207 const Char_t* table[] = {"ALL", "no", "*", "*",
a077ccfa 208 "PHY", "yes","*", "*",
7d5998b9 209 "EOR", "yes","*", "*",
a077ccfa 210 NULL, NULL, NULL, NULL};
20e6c4f4 211 TString trSelection;
212 for (Int_t i = 0; i < 50; i++) {
213 if (triggerMask & (1ull << i)) {
48b5e3f8 214 if (!trSelection.IsNull()) trSelection += "&";
ad352b4a 215 trSelection += Form("%d",i);
20e6c4f4 216 }
217 }
218 table[7] = trSelection.Data();
219
5dc76fce 220 monitorLogout();
20e6c4f4 221 monitorDeclareTableExtended(const_cast<char**>(table));
222
223#endif
224 AliRawReader::SelectEvents(type,triggerMask,triggerExpr);
225}
e5705501 226
227//______________________________________________________________________________
228void AliRawReaderDateOnline::Stop()
229{
230 // Stop the event loop (called on SIGUSR1)
231
232 fStop = kTRUE;
233}