]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RAW/AliRawReaderDateOnline.cxx
More flexible map flag than only for high and low gain (David)
[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
31 #include "AliRawReaderDateOnline.h"
32 #include "AliLog.h"
33 #ifdef ALI_DATE
34 #include "event.h"
35 #include "monitor.h"
36 #endif
37
38 ClassImp(AliRawReaderDateOnline)
39
40 AliRawReaderDateOnline::AliRawReaderDateOnline(
41 #ifdef ALI_DATE
42                                    const char* filename
43 #else
44                                    const char* /* filename */
45 #endif
46                                    ) :
47   AliRawReaderDate((void*)NULL)
48 {
49
50 // Constructor
51 // Initialize the DATE monitoring libs
52
53 #ifdef ALI_DATE
54
55   int status;
56
57   /* define data source : this is argument 1 */  
58   status=monitorSetDataSource( (char* )filename );
59   if (status!=0) {
60     AliFatal(Form("monitorSetDataSource() failed : %s",monitorDecodeError(status)));
61   }
62
63   /* declare monitoring program */
64   status=monitorDeclareMp( __FILE__ );
65   if (status!=0) {
66     AliFatal(Form("monitorDeclareMp() failed : %s",monitorDecodeError(status)));
67   }
68
69   /* define wait event timeout - 1s max */
70   monitorSetNowait();
71   monitorSetNoWaitNetworkTimeout(1000);
72   
73 #else
74   Fatal("AliRawReaderDateOnline", "this class was compiled without DATE");
75 #endif
76 }
77
78 Bool_t AliRawReaderDateOnline::NextEvent()
79 {
80 // wait and get the next event
81 // from shared memory
82
83 #ifdef ALI_DATE
84
85   // Event already loaded no need take a new one
86   if (AliRawReaderDate::NextEvent()) return kTRUE;
87
88   if (fEvent) free(fEvent);
89   fEvent = NULL;
90
91   while (1) {
92     /* get next event (blocking call until timeout) */
93     int status=monitorGetEventDynamic((void**)&fEvent);
94
95     if ((unsigned int)status==MON_ERR_EOF) {
96       AliInfo("End of File detected");
97       Reset();
98       fEvent = NULL;
99       return kFALSE; /* end of monitoring file has been reached */
100     }
101     
102     if (status!=0) {
103       AliError(Form("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status)));
104       Reset();
105       fEvent = NULL;
106       return kFALSE;
107     }
108     
109     /* retry if got no event */
110     if (fEvent==NULL) {
111       continue;
112     }
113     
114     eventTypeType eventT=fEvent->eventType;
115     /* exit when last event received, no need to wait for TERM signal */
116     if (eventT==END_OF_RUN) {
117       AliInfo("EOR event detected");
118       Reset();
119       fEvent = NULL;
120       return kFALSE;
121     }
122     
123     if (eventT!=PHYSICS_EVENT) {
124       continue;
125     }
126
127     AliInfo(Form("Run #%lu, event size: %lu, BC:%u, Orbit:%u, Period:%u",
128                  (unsigned long)fEvent->eventRunNb,
129                  (unsigned long)fEvent->eventSize,
130                  EVENT_ID_GET_BUNCH_CROSSING(fEvent->eventId),
131                  EVENT_ID_GET_ORBIT(fEvent->eventId),
132                  EVENT_ID_GET_PERIOD(fEvent->eventId)
133                  ));
134     break;
135   }
136
137   fEventNumber++;
138   Reset();
139
140   return kTRUE;
141
142 }
143
144 #else
145   return kFALSE;
146 }
147 #endif
148
149 AliRawReaderDateOnline::~AliRawReaderDateOnline()
150 {
151 // Destructor
152 // Free the last event in shared memory
153
154 #ifdef ALI_DATE
155   if (fEvent) free(fEvent);
156 #endif
157 }