]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RAW/AliRawReaderDateOnline.cxx
Bug fix: AliHLTComponent::ConfigureFromArgumentString
[u/mrichter/AliRoot.git] / RAW / AliRawReaderDateOnline.cxx
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 #include <TSystem.h>
31 #include <cstdlib>
32 #include "AliRawReaderDateOnline.h"
33 #include "AliLog.h"
34 #ifdef ALI_DATE
35 #include "event.h"
36 #include "monitor.h"
37 #endif
38
39 ClassImp(AliRawReaderDateOnline)
40
41 Bool_t AliRawReaderDateOnline::fgNoSleep = kTRUE;
42
43 AliRawReaderDateOnline::AliRawReaderDateOnline(
44 #ifdef ALI_DATE
45                                      const char* filename
46 #else
47                                      const char* /* filename */
48 #endif
49                                    , const Char_t** customTable) :
50   AliRawReaderDate((void*)NULL),
51   fTable(customTable),
52   fStop(kFALSE)
53 {
54
55 // Constructor
56 // Initialize the DATE monitoring libs
57
58 #ifdef ALI_DATE
59
60
61   //  Removal of the selection of physics events
62   //  Requested by Filimon and FMD experts
63   //  fSelectEventType = PHYSICS_EVENT;
64
65   int status;
66
67   /* define data source : this is argument 1 */  
68   status=monitorSetDataSource( (char* )filename );
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);
82
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   }
98   // install SIGUSR1 handler to allow clean end-of-events loop
99   gSystem->AddSignalHandler(new AliRawReaderDateIntHandler(this));
100
101 #else
102   Fatal("AliRawReaderDateOnline", "this class was compiled without DATE");
103 #endif
104 }
105
106 Bool_t AliRawReaderDateOnline::NextEvent()
107 {
108 // wait and get the next event
109 // from shared memory
110
111 #ifdef ALI_DATE
112
113   // Stop on SIGUSR1
114   if (fStop) {
115     AliInfo("Raw-data reading stopped by SIGUSR1");
116     if (fEvent) free(fEvent);
117     fEvent = NULL;
118     return kFALSE;
119   }
120
121   // Event already loaded no need take a new one
122   if (AliRawReaderDate::NextEvent()) return kTRUE;
123
124   if (fEvent) free(fEvent);
125   fEvent = NULL;
126
127   while (1) {
128     /* get next event (blocking call until timeout) */
129     int status=monitorGetEventDynamic((void**)&fEvent);
130
131     if (status==MON_ERR_EOF) {
132       AliInfo("End of File detected");
133       Reset();
134       fEvent = NULL;
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)));
140       Reset();
141       fEvent = NULL;
142       return kFALSE;
143     }
144     
145     /* retry if got no event */
146     if (fEvent==NULL) {
147       if (fgNoSleep) gSystem->ProcessEvents();
148       continue;
149     }
150     
151     eventTypeType eventT=fEvent->eventType;
152     /* exit when last event received, no need to wait for TERM signal */
153     if (eventT==END_OF_RUN) {
154       AliInfo("EOR event detected");
155       Reset();
156       free(fEvent);
157       fEvent = NULL;
158       return kFALSE;
159     }
160     
161     if (!IsEventSelected()) {
162       free(fEvent);
163       fEvent = NULL;
164       if (fgNoSleep) gSystem->ProcessEvents();
165       continue;
166     }
167
168     AliInfo(Form("Run #%lu, event size: %lu, BC:0x%x, Orbit:0x%x, Period:0x%x",
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)
174                  ));
175     break;
176   }
177
178   fEventNumber++;
179   Reset();
180
181   return kTRUE;
182
183 }
184
185 #else
186   return kFALSE;
187 }
188 #endif
189
190 AliRawReaderDateOnline::~AliRawReaderDateOnline()
191 {
192 // Destructor
193 // Free the last event in shared memory
194
195 #ifdef ALI_DATE
196   if (fEvent) free(fEvent);
197 #endif
198 }
199
200 void 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", "*", "*",
208                             "PHY", "yes","*", "*",
209                             "EOR", "yes","*", "*",
210                             NULL, NULL, NULL, NULL};
211   TString trSelection;
212   for (Int_t i = 0; i < 50; i++) {
213     if (triggerMask & (1ull << i)) {
214         if (!trSelection.IsNull()) trSelection += "&";
215         trSelection += Form("%d",i);
216     }
217   }
218   table[7] = trSelection.Data();
219
220   monitorLogout();
221   monitorDeclareTableExtended(const_cast<char**>(table));
222   
223 #endif
224   AliRawReader::SelectEvents(type,triggerMask,triggerExpr);
225 }
226
227 //______________________________________________________________________________
228 void AliRawReaderDateOnline::Stop()
229 {
230   // Stop the event loop (called on SIGUSR1)
231
232   fStop = kTRUE; 
233 }