]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - RAW/AliRawReaderDateOnline.cxx
adapt binning in centrality for qa
[u/mrichter/AliRoot.git] / RAW / AliRawReaderDateOnline.cxx
index c77039cd53453ec02bddfcc40ed63a767b1adac1..c0eaf534f0eef59a0a6a76aad668765d460af1c4 100644 (file)
 ///
 /// Cvetan Cheshkov 1/04/2008
 ///////////////////////////////////////////////////////////////////////////////
-
+#include <TSystem.h>
+#include <cstdlib>
 #include "AliRawReaderDateOnline.h"
+#include "AliLog.h"
+#ifdef ALI_DATE
+#include "event.h"
+#include "monitor.h"
+#endif
 
 ClassImp(AliRawReaderDateOnline)
 
-AliRawReaderDate::AliRawReaderDate(
+Bool_t AliRawReaderDateOnline::fgNoSleep = kTRUE;
+
+AliRawReaderDateOnline::AliRawReaderDateOnline(
 #ifdef ALI_DATE
-                                  const char* filename
+                                    const char* filename
 #else
-                                  const char* /* filename */
+                                    const char* /* filename */
 #endif
-                                  ) :
-  AliRawReaderDate()
+                                  , const Char_t** customTable) :
+  AliRawReaderDate((void*)NULL),
+  fTable(customTable),
+  fStop(kFALSE)
 {
 
 // Constructor
@@ -47,10 +57,15 @@ AliRawReaderDate::AliRawReaderDate(
 
 #ifdef ALI_DATE
 
+
+  //  Removal of the selection of physics events
+  //  Requested by Filimon and FMD experts
+  //  fSelectEventType = PHYSICS_EVENT;
+
   int status;
 
   /* define data source : this is argument 1 */  
-  status=monitorSetDataSource( filename );
+  status=monitorSetDataSource( (char* )filename );
   if (status!=0) {
     AliFatal(Form("monitorSetDataSource() failed : %s",monitorDecodeError(status)));
   }
@@ -64,66 +79,155 @@ AliRawReaderDate::AliRawReaderDate(
   /* define wait event timeout - 1s max */
   monitorSetNowait();
   monitorSetNoWaitNetworkTimeout(1000);
-  
+
+  if (!fTable) {
+    const Char_t* table[]  = {"ALL", "few", "*", "*",
+                             "EOR", "yes","*", "*",
+                             NULL, NULL, NULL, NULL};
+    monitorDeclareTableExtended(const_cast<char**>(table));
+  }
+  else {
+    AliInfo("Custom monitoring table:");
+    Int_t index = 0;
+    while (fTable[index] != NULL) {
+      AliInfo(Form("%s %s %s %s",fTable[index],fTable[index+1],fTable[index+2],fTable[index+3]));
+      index += 4;
+    }
+    monitorDeclareTableExtended(const_cast<char**>(fTable));
+  }
+  // install SIGUSR1 handler to allow clean end-of-events loop
+  gSystem->AddSignalHandler(new AliRawReaderDateIntHandler(this));
+
 #else
   Fatal("AliRawReaderDateOnline", "this class was compiled without DATE");
 #endif
 }
 
-Bool_t AliRawReaderDate::NextEvent()
+Bool_t AliRawReaderDateOnline::NextEvent()
 {
 // wait and get the next event
 // from shared memory
 
 #ifdef ALI_DATE
 
+  // Stop on SIGUSR1
+  if (fStop) {
+    AliInfo("Raw-data reading stopped by SIGUSR1");
+    if (fEvent) free(fEvent);
+    fEvent = NULL;
+    return kFALSE;
+  }
+
+  // Event already loaded no need take a new one
+  if (AliRawReaderDate::NextEvent()) return kTRUE;
+
   if (fEvent) free(fEvent);
+  fEvent = NULL;
 
   while (1) {
     /* get next event (blocking call until timeout) */
-    int status=monitorGetEventDynamic(&fEvent);
-    struct eventHeaderStruct *event=(eventHeaderStruct*)eventPtr;
+    int status=monitorGetEventDynamic((void**)&fEvent);
 
     if (status==MON_ERR_EOF) {
       AliInfo("End of File detected");
+      Reset();
+      fEvent = NULL;
       return kFALSE; /* end of monitoring file has been reached */
     }
     
     if (status!=0) {
       AliError(Form("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status)));
+      Reset();
+      fEvent = NULL;
       return kFALSE;
     }
     
     /* retry if got no event */
-    if (event==NULL) {
+    if (fEvent==NULL) {
+      if (fgNoSleep) gSystem->ProcessEvents();
       continue;
     }
-
-    eventTypeType eventT=event->eventType;
+    
+    eventTypeType eventT=fEvent->eventType;
     /* exit when last event received, no need to wait for TERM signal */
     if (eventT==END_OF_RUN) {
       AliInfo("EOR event detected");
+      Reset();
+      free(fEvent);
+      fEvent = NULL;
       return kFALSE;
     }
-    if (eventT!=PHYSICS_EVENT) {
+    
+    if (!IsEventSelected()) {
+      free(fEvent);
+      fEvent = NULL;
+      if (fgNoSleep) gSystem->ProcessEvents();
       continue;
     }
 
-    AliInfo(Form("Run #%lu, event size: %lu, BC:%u, Orbit:%u, Period:%u",
-                (unsigned long)event->eventRunNb,
-                (unsigned long)event->eventSize,
-                EVENT_ID_GET_BUNCH_CROSSING(event->eventId),
-                EVENT_ID_GET_ORBIT(event->eventId),
-                EVENT_ID_GET_PERIOD(event->eventId)
+    AliInfo(Form("Run #%lu, event size: %lu, BC:0x%x, Orbit:0x%x, Period:0x%x",
+                (unsigned long)fEvent->eventRunNb,
+                (unsigned long)fEvent->eventSize,
+                EVENT_ID_GET_BUNCH_CROSSING(fEvent->eventId),
+                EVENT_ID_GET_ORBIT(fEvent->eventId),
+                EVENT_ID_GET_PERIOD(fEvent->eventId)
                 ));
+    break;
   }
 
-  return AliRawRederDate::NextEvent();
+  fEventNumber++;
+  Reset();
+
+  return kTRUE;
+
 }
 
+#else
+  return kFALSE;
+}
 #endif
 
-  return kFALSE;
+AliRawReaderDateOnline::~AliRawReaderDateOnline()
+{
+// Destructor
+// Free the last event in shared memory
+
+#ifdef ALI_DATE
+  if (fEvent) free(fEvent);
+#endif
+}
+
+void AliRawReaderDateOnline::SelectEvents(Int_t type,
+  ULong64_t triggerMask,
+  const char *triggerExpr)
+{
+  // Select event by using DATE monitoring
+  // library
+#ifdef ALI_DATE
+  const Char_t* table[]  = {"ALL", "no", "*", "*",
+                           "PHY", "yes","*", "*",
+                            "EOR", "yes","*", "*",
+                           NULL, NULL, NULL, NULL};
+  TString trSelection;
+  for (Int_t i = 0; i < 50; i++) {
+    if (triggerMask & (1ull << i)) {
+       if (!trSelection.IsNull()) trSelection += "&";
+       trSelection += Form("%d",i);
+    }
+  }
+  table[7] = trSelection.Data();
+
+  monitorLogout();
+  monitorDeclareTableExtended(const_cast<char**>(table));
+  
+#endif
+  AliRawReader::SelectEvents(type,triggerMask,triggerExpr);
 }
 
+//______________________________________________________________________________
+void AliRawReaderDateOnline::Stop()
+{
+  // Stop the event loop (called on SIGUSR1)
 
+  fStop = kTRUE; 
+}