]> git.uio.no Git - u/mrichter/AliRoot.git/blame - RAW/AliRawReaderDateOnline.cxx
Optimisation
[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
d2a137c1 80 const Char_t* table[] = {"ALL", "few", "*", "*",
7d5998b9 81 "EOR", "yes","*", "*",
a077ccfa 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");
dae597de 103 if (fEvent) free(fEvent);
104 fEvent = NULL;
e5705501 105 return kFALSE;
106 }
107
36a7d3c6 108 // Event already loaded no need take a new one
109 if (AliRawReaderDate::NextEvent()) return kTRUE;
110
3b98a4d4 111 if (fEvent) free(fEvent);
36a7d3c6 112 fEvent = NULL;
3b98a4d4 113
114 while (1) {
115 /* get next event (blocking call until timeout) */
36a7d3c6 116 int status=monitorGetEventDynamic((void**)&fEvent);
3b98a4d4 117
00665a00 118 if (status==MON_ERR_EOF) {
3b98a4d4 119 AliInfo("End of File detected");
36a7d3c6 120 Reset();
121 fEvent = NULL;
3b98a4d4 122 return kFALSE; /* end of monitoring file has been reached */
123 }
124
125 if (status!=0) {
126 AliError(Form("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status)));
36a7d3c6 127 Reset();
128 fEvent = NULL;
3b98a4d4 129 return kFALSE;
130 }
131
132 /* retry if got no event */
36a7d3c6 133 if (fEvent==NULL) {
3b98a4d4 134 continue;
135 }
36a7d3c6 136
137 eventTypeType eventT=fEvent->eventType;
3b98a4d4 138 /* exit when last event received, no need to wait for TERM signal */
139 if (eventT==END_OF_RUN) {
140 AliInfo("EOR event detected");
36a7d3c6 141 Reset();
e933e49f 142 free(fEvent);
36a7d3c6 143 fEvent = NULL;
3b98a4d4 144 return kFALSE;
145 }
36a7d3c6 146
00665a00 147 if (!IsEventSelected()) {
e933e49f 148 free(fEvent);
dae597de 149 fEvent = NULL;
3b98a4d4 150 continue;
151 }
152
00665a00 153 AliInfo(Form("Run #%lu, event size: %lu, BC:0x%x, Orbit:0x%x, Period:0x%x",
36a7d3c6 154 (unsigned long)fEvent->eventRunNb,
155 (unsigned long)fEvent->eventSize,
156 EVENT_ID_GET_BUNCH_CROSSING(fEvent->eventId),
157 EVENT_ID_GET_ORBIT(fEvent->eventId),
158 EVENT_ID_GET_PERIOD(fEvent->eventId)
3b98a4d4 159 ));
36a7d3c6 160 break;
3b98a4d4 161 }
162
36a7d3c6 163 fEventNumber++;
164 Reset();
3b98a4d4 165
36a7d3c6 166 return kTRUE;
3b98a4d4 167
36a7d3c6 168}
169
170#else
3b98a4d4 171 return kFALSE;
172}
36a7d3c6 173#endif
3b98a4d4 174
36a7d3c6 175AliRawReaderDateOnline::~AliRawReaderDateOnline()
176{
177// Destructor
178// Free the last event in shared memory
3b98a4d4 179
36a7d3c6 180#ifdef ALI_DATE
181 if (fEvent) free(fEvent);
182#endif
183}
20e6c4f4 184
185void AliRawReaderDateOnline::SelectEvents(Int_t type,
186 ULong64_t triggerMask,
187 const char *triggerExpr)
188{
189 // Select event by using DATE monitoring
190 // library
191#ifdef ALI_DATE
192 const Char_t* table[] = {"ALL", "no", "*", "*",
a077ccfa 193 "PHY", "yes","*", "*",
7d5998b9 194 "EOR", "yes","*", "*",
a077ccfa 195 NULL, NULL, NULL, NULL};
20e6c4f4 196 TString trSelection;
197 for (Int_t i = 0; i < 50; i++) {
198 if (triggerMask & (1ull << i)) {
48b5e3f8 199 if (!trSelection.IsNull()) trSelection += "&";
ad352b4a 200 trSelection += Form("%d",i);
20e6c4f4 201 }
202 }
203 table[7] = trSelection.Data();
204
5dc76fce 205 monitorLogout();
20e6c4f4 206 monitorDeclareTableExtended(const_cast<char**>(table));
207
208#endif
209 AliRawReader::SelectEvents(type,triggerMask,triggerExpr);
210}
e5705501 211
212//______________________________________________________________________________
213void AliRawReaderDateOnline::Stop()
214{
215 // Stop the event loop (called on SIGUSR1)
216
217 fStop = kTRUE;
218}