]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RAW/AliRawReaderDateOnline.cxx
addapt array of histograms for different SM combinations to new EMCAL SM
[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
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                                    ) :
48   AliRawReaderDate((void*)NULL),
49   fStop(kFALSE)
50 {
51
52 // Constructor
53 // Initialize the DATE monitoring libs
54
55 #ifdef ALI_DATE
56
57
58   //  Removal of the selection of physics events
59   //  Requested by Filimon and FMD experts
60   //  fSelectEventType = PHYSICS_EVENT;
61
62   int status;
63
64   /* define data source : this is argument 1 */  
65   status=monitorSetDataSource( (char* )filename );
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);
79
80   const Char_t* table[]  = {"ALL", "few", "*", "*",
81                             "EOR", "yes","*", "*",
82                             NULL, NULL, NULL, NULL};
83   monitorDeclareTableExtended(const_cast<char**>(table));
84
85   // install SIGUSR1 handler to allow clean end-of-events loop
86   gSystem->AddSignalHandler(new AliRawReaderDateIntHandler(this));
87
88 #else
89   Fatal("AliRawReaderDateOnline", "this class was compiled without DATE");
90 #endif
91 }
92
93 Bool_t AliRawReaderDateOnline::NextEvent()
94 {
95 // wait and get the next event
96 // from shared memory
97
98 #ifdef ALI_DATE
99
100   // Stop on SIGUSR1
101   if (fStop) {
102     AliInfo("Raw-data reading stopped by SIGUSR1");
103     if (fEvent) free(fEvent);
104     fEvent = NULL;
105     return kFALSE;
106   }
107
108   // Event already loaded no need take a new one
109   if (AliRawReaderDate::NextEvent()) return kTRUE;
110
111   if (fEvent) free(fEvent);
112   fEvent = NULL;
113
114   while (1) {
115     /* get next event (blocking call until timeout) */
116     int status=monitorGetEventDynamic((void**)&fEvent);
117
118     if (status==MON_ERR_EOF) {
119       AliInfo("End of File detected");
120       Reset();
121       fEvent = NULL;
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)));
127       Reset();
128       fEvent = NULL;
129       return kFALSE;
130     }
131     
132     /* retry if got no event */
133     if (fEvent==NULL) {
134       continue;
135     }
136     
137     eventTypeType eventT=fEvent->eventType;
138     /* exit when last event received, no need to wait for TERM signal */
139     if (eventT==END_OF_RUN) {
140       AliInfo("EOR event detected");
141       Reset();
142       free(fEvent);
143       fEvent = NULL;
144       return kFALSE;
145     }
146     
147     if (!IsEventSelected()) {
148       free(fEvent);
149       fEvent = NULL;
150       continue;
151     }
152
153     AliInfo(Form("Run #%lu, event size: %lu, BC:0x%x, Orbit:0x%x, Period:0x%x",
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)
159                  ));
160     break;
161   }
162
163   fEventNumber++;
164   Reset();
165
166   return kTRUE;
167
168 }
169
170 #else
171   return kFALSE;
172 }
173 #endif
174
175 AliRawReaderDateOnline::~AliRawReaderDateOnline()
176 {
177 // Destructor
178 // Free the last event in shared memory
179
180 #ifdef ALI_DATE
181   if (fEvent) free(fEvent);
182 #endif
183 }
184
185 void 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", "*", "*",
193                             "PHY", "yes","*", "*",
194                             "EOR", "yes","*", "*",
195                             NULL, NULL, NULL, NULL};
196   TString trSelection;
197   for (Int_t i = 0; i < 50; i++) {
198     if (triggerMask & (1ull << i)) {
199         if (!trSelection.IsNull()) trSelection += "&";
200         trSelection += Form("%d",i);
201     }
202   }
203   table[7] = trSelection.Data();
204
205   monitorLogout();
206   monitorDeclareTableExtended(const_cast<char**>(table));
207   
208 #endif
209   AliRawReader::SelectEvents(type,triggerMask,triggerExpr);
210 }
211
212 //______________________________________________________________________________
213 void AliRawReaderDateOnline::Stop()
214 {
215   // Stop the event loop (called on SIGUSR1)
216
217   fStop = kTRUE; 
218 }