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