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