]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - RAW/AliRawEvent.cxx
fix some coding violations.
[u/mrichter/AliRoot.git] / RAW / AliRawEvent.cxx
index 75705586fa484555287530dafb602a61f1ece7cb..31b5282b98da4fb8ed35e1b140235b819c9a0c5f 100644 (file)
@@ -2,6 +2,45 @@
 // Author: Fons Rademakers  26/11/99
 // Updated: Dario Favretto  15/04/2003
 
+/**************************************************************************
+ * Copyright(c) 1998-2003, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+//////////////////////////////////////////////////////////////////////////
+//                                                                      //
+// AliRawEvent                                                          //
+//                                                                      //
+// Set of classes defining the ALICE RAW event format. The AliRawEvent  //
+// class defines a RAW event. It consists of an AliEventHeader object   //
+// an AliEquipmentHeader object, an AliRawData object and an array of   //
+// sub-events, themselves also being AliRawEvents. The number of        //
+// sub-events depends on the number of DATE LDC's.                      //
+// The AliRawEvent objects are written to a ROOT file using different   //
+// technologies, i.e. to local disk via AliRawDB or via rfiod using     //
+// AliRawRFIODB or via rootd using AliRawRootdDB or to CASTOR via       //
+// rootd using AliRawCastorDB (and for performance testing there is     //
+// also AliRawNullDB).                                                  //
+// The AliRunDB class provides the interface to the run and file        //
+// catalogues (AliEn or plain MySQL).                                   //
+// The AliStats class provides statics information that is added as     //
+// a single keyed object to each raw file.                              //
+// The AliTagDB provides an interface to a TAG database.                //
+// The AliMDC class is usid by the "alimdc" stand-alone program         //
+// that reads data directly from DATE.                                  //
+//                                                                      //
+//////////////////////////////////////////////////////////////////////////
+
 #include <sys/types.h>
 #include <sys/stat.h>
 #if defined(__DECCXX)
@@ -27,6 +66,7 @@
 #include <TSQLResult.h>
 #include <TUrl.h>
 #include <TGrid.h>
+#include <TH1.h>
 
 #if defined(__APPLE__)
 #undef Free
@@ -62,25 +102,25 @@ const Int_t kMDC = 5;
 
 // Fixed file system locations for the different DB's
 #ifdef USE_RDM
-const char *kFifo       = "/tmp/alimdc.fifo";
-const char *kRawDBFS[2] = { "/tmp/mdc1", "/tmp/mdc2" };
-const char *kTagDBFS    = "/tmp/mdc1/tags";
-const char *kRunDBFS    = "/tmp/mdc1/meta";
-const char *kRFIOFS     = "rfio:/castor/cern.ch/user/r/rdm";
-const char *kCastorFS   = "castor:/castor/cern.ch/user/r/rdm";
-const char *kRootdFS    = "root://localhost//tmp/mdc1";
-const char *kAlienHost  = "alien://aliens7.cern.ch:15000/?direct";
-const char *kAlienDir   = "/alice_mdc/DC";
+const char* const kFifo       = "/tmp/alimdc.fifo";
+const char* const kRawDBFS[2] = { "/tmp/mdc1", "/tmp/mdc2" };
+const char* const kTagDBFS    = "/tmp/mdc1/tags";
+const char* const kRunDBFS    = "/tmp/mdc1/meta";
+const char* const kRFIOFS     = "rfio:/castor/cern.ch/user/r/rdm";
+const char* const kCastorFS   = "castor:/castor/cern.ch/user/r/rdm";
+const char* const kRootdFS    = "root://localhost//tmp/mdc1";
+const char* const kAlienHost  = "alien://aliens7.cern.ch:15000/?direct";
+const char* const kAlienDir   = "/alice_mdc/DC";
 #else
-const char *kFifo       = "/tmp/alimdc.fifo";
-const char *kRawDBFS[2] = { "/data1/mdc", "/data2/mdc" };
-const char *kTagDBFS    = "/data1/mdc/tags";
-const char *kRunDBFS    = "/data1/mdc/meta";
-const char *kRFIOFS     = "rfio:/castor/cern.ch/lcg/dc5";
-const char *kCastorFS   = "castor:/castor/cern.ch/lcg/dc5";
-const char *kRootdFS    = "root://localhost//tmp/mdc1";
-const char *kAlienHost  = "alien://aliens7.cern.ch:15000/?direct";
-const char *kAlienDir   = "/alice_mdc/DC";
+const char* const kFifo       = "/tmp/alimdc.fifo";
+const char* const kRawDBFS[2] = { "/data1/mdc", "/data2/mdc" };
+const char* const kTagDBFS    = "/data1/mdc/tags";
+const char* const kRunDBFS    = "/data1/mdc/meta";
+const char* const kRFIOFS     = "rfio:/castor/cern.ch/lcg/dc5";
+const char* const kCastorFS   = "castor:/castor/cern.ch/lcg/dc5";
+const char* const kRootdFS    = "root://localhost//tmp/mdc1";
+const char* const kAlienHost  = "alien://aliens7.cern.ch:15000/?direct";
+const char* const kAlienDir   = "/alice_mdc/DC";
 #endif
 
 // Maximum size of tag db files
@@ -201,12 +241,23 @@ AliRawEvent::AliRawEvent()
    // raw data object, otherwise a private copy will be made.
 
    fNSubEvents = 0;
-   fEvtHdr     = new AliRawEventHeader;
+   fEvtHdr     = 0;
    fEqpHdr     = 0;
    fRawData    = 0;
    fSubEvents  = 0;
 }
 
+//______________________________________________________________________________
+AliRawEventHeader *AliRawEvent::GetHeader()
+{
+   // Get event header part of AliRawEvent.
+
+   if (!fEvtHdr)
+      fEvtHdr = new AliRawEventHeader;
+
+   return fEvtHdr;
+}
+
 //______________________________________________________________________________
 AliRawEquipmentHeader *AliRawEvent::GetEquipmentHeader()
 {
@@ -408,7 +459,7 @@ AliRawDB::AliRawDB(AliRawEvent *event, Double_t maxsize, Int_t compress,
 }
 
 //______________________________________________________________________________
-Bool_t AliRawDB::FSHasSpace(const char *fs)
+Bool_t AliRawDB::FSHasSpace(const char *fs) const
 {
    // Check for at least fMaxSize bytes of free space on the file system.
    // If the space is not available return kFALSE, kTRUE otherwise.
@@ -430,7 +481,7 @@ Bool_t AliRawDB::FSHasSpace(const char *fs)
 }
 
 //______________________________________________________________________________
-const char *AliRawDB::GetFileName()
+const char *AliRawDB::GetFileName() const
 {
    // Return filename based on hostname and date and time. This will make
    // each file unique. Also makes sure (via FSHasSpace()) that there is
@@ -476,7 +527,9 @@ Bool_t AliRawDB::Create()
 {
    // Create a new raw DB.
 
-   const Int_t maxRetry = 10;
+   const Int_t kMaxRetry = 200;
+   const Int_t kMaxSleep = 1;      // seconds
+   const Int_t kMaxSleepLong = 10; // seconds
    Int_t retry = 0;
 
 again:
@@ -492,36 +545,43 @@ again:
    retry++;
 
    fRawDB = TFile::Open(fname, GetOpenOption(),
-                        Form("ALICE MDC%d raw DB", kMDC), fCompress);
+                        Form("ALICE MDC%d raw DB", kMDC), fCompress,
+                        GetNetopt());
    if (!fRawDB) {
-      if (retry < maxRetry) {
-         Warning("Create", "failure to open file, sleeping 10 seconds before retrying...");
-         gSystem->Sleep(10000);
+      if (retry < kMaxRetry) {
+         Warning("Create", "failure to open file, sleeping %d %s before retrying...",
+                 kMaxSleep, kMaxSleep==1 ? "second" : "seconds");
+         gSystem->Sleep(kMaxSleep*1000);
          goto again;
       }
-      Error("Create", "failure to open file %s after %d tries", fname, maxRetry);
+      Error("Create", "failure to open file %s after %d tries", fname, kMaxRetry);
       return kFALSE;
    }
+   if (retry > 1)
+      Warning("Create", "succeeded to open file after %d retries", retry);
+
    if (fRawDB->IsZombie()) {
       if (fRawDB->GetErrno() == ENOSPC ||
           fRawDB->GetErrno() == 1018   ||   // SECOMERR
           fRawDB->GetErrno() == 1027) {     // SESYSERR
          fRawDB->ResetErrno();
          delete fRawDB;
-         Warning("Create", "file is a zombie (no space), sleeping 10 seconds before retrying...");
-         gSystem->Sleep(10000);   // sleep 10 seconds before retrying
+         Warning("Create", "file is a zombie (no space), sleeping %d %s before retrying...",
+                 kMaxSleepLong, kMaxSleepLong==1 ? "second" : "seconds");
+         gSystem->Sleep(kMaxSleepLong*1000);   // sleep 10 seconds before retrying
          goto again;
       }
       Error("Create", "file %s is zombie", fname);
       fRawDB->ResetErrno();
       delete fRawDB;
       fRawDB = 0;
-      if (retry < maxRetry) {
-         Warning("Create", "file is a zombie, sleeping 10 seconds before retrying...");
-         gSystem->Sleep(10000);
+      if (retry < kMaxRetry) {
+         Warning("Create", "file is a zombie, sleeping %d %s before retrying...",
+                 kMaxSleep, kMaxSleep==1 ? "second" : "seconds");
+         gSystem->Sleep(kMaxSleep*1000);
          goto again;
       }
-      Error("Create", "failure to open file %s after %d tries", fname, maxRetry);
+      Error("Create", "failure to open file %s after %d tries", fname, kMaxRetry);
       return kFALSE;
    }
 
@@ -615,6 +675,12 @@ AliRawRFIODB::AliRawRFIODB(AliRawEvent *event, Double_t maxsize, Int_t compress)
       // WHATEVER HAS BEEN SET IN THE DATE SITE
       //gSystem->Setenv("STAGE_POOL", "lcg00");
       //gSystem->Setenv("STAGE_HOST", "stage013");
+
+      // however for sanity we check if they are really set
+      if (!gSystem->Getenv("STAGE_POOL"))
+         Error("AliRawRFIODB", "STAGE_POOL not set");
+      if (!gSystem->Getenv("STAGE_HOST"))
+         Error("AliRawRFIODB", "STAGE_HOST not set");
       init = 1;
    }
 #endif
@@ -626,7 +692,7 @@ AliRawRFIODB::AliRawRFIODB(AliRawEvent *event, Double_t maxsize, Int_t compress)
 }
 
 //______________________________________________________________________________
-const char *AliRawRFIODB::GetFileName()
+const char *AliRawRFIODB::GetFileName() const
 {
    // Return filename based on hostname and date and time. This will make
    // each file unique. Also the directory will be made unique for each
@@ -707,6 +773,12 @@ AliRawCastorDB::AliRawCastorDB(AliRawEvent *event, Double_t maxsize, Int_t compr
       // WHATEVER HAS BEEN SET IN THE DATE SITE
       //gSystem->Setenv("STAGE_POOL", "lcg00");
       //gSystem->Setenv("STAGE_HOST", "stage013");
+
+      // however for sanity we check if they are really set
+      if (!gSystem->Getenv("STAGE_POOL"))
+         Error("AliRawRFIODB", "STAGE_POOL not set");
+      if (!gSystem->Getenv("STAGE_HOST"))
+         Error("AliRawRFIODB", "STAGE_HOST not set");
       init = 1;
    }
 #endif
@@ -718,7 +790,7 @@ AliRawCastorDB::AliRawCastorDB(AliRawEvent *event, Double_t maxsize, Int_t compr
 }
 
 //______________________________________________________________________________
-const char *AliRawCastorDB::GetFileName()
+const char *AliRawCastorDB::GetFileName() const
 {
    // Return filename based on hostname and date and time. This will make
    // each file unique. Also the directory will be made unique for each
@@ -801,7 +873,7 @@ AliRawRootdDB::AliRawRootdDB(AliRawEvent *event, Double_t maxsize, Int_t compres
 }
 
 //______________________________________________________________________________
-const char *AliRawRootdDB::GetFileName()
+const char *AliRawRootdDB::GetFileName() const
 {
    // Return filename based on hostname and date and time. This will make
    // each file unique. Also the directory will be made unique for each
@@ -881,7 +953,7 @@ AliRawNullDB::AliRawNullDB(AliRawEvent *event, Double_t maxsize, Int_t compress)
 }
 
 //______________________________________________________________________________
-const char *AliRawNullDB::GetFileName()
+const char *AliRawNullDB::GetFileName() const
 {
    // Return /dev/null as filename.
 
@@ -992,7 +1064,7 @@ Float_t AliTagDB::GetCompressionFactor() const
 }
 
 //______________________________________________________________________________
-const char *AliTagDB::GetFileName()
+const char *AliTagDB::GetFileName() const
 {
    // Return filename based on hostname and date and time. This will make
    // each file unique. The tags will be stored in the /data1/tags directory.
@@ -1030,7 +1102,7 @@ AliTagNullDB::AliTagNullDB(AliRawEventHeader *header, Double_t maxsize) :
 }
 
 //______________________________________________________________________________
-const char *AliTagNullDB::GetFileName()
+const char *AliTagNullDB::GetFileName() const
 {
    // Return /dev/null as filename.
 
@@ -1164,6 +1236,23 @@ void AliRunDB::UpdateAliEn(AliStats *stats)
    TGrid *g = TGrid::Connect(kAlienHost, "");
 
    TString lfn = kAlienDir;
+   TDatime dt;
+
+   // make a subdirectory for each day
+   lfn += "/adc-";
+   lfn += dt.GetDate();
+
+   // check if directory exists, if not create it
+   Grid_ResultHandle_t res = 0;
+   if (!(res = g->OpenDir(lfn))) {
+      // directory does not exist, create it
+      if (g->Mkdir(lfn) == -1) {
+         Error("UpdateAliEn", "cannot create directory %s", lfn.Data());
+         lfn = kAlienDir;
+      }
+   }
+   if (res) g->CloseResult(res);
+
    lfn += "/";
    lfn += gSystem->BaseName(stats->GetFileName());
 
@@ -1190,8 +1279,6 @@ void AliRunDB::Close()
 
 //----------------- Use SIGUSR1 to interupt endless loop -----------------------
 class AliMDCInterruptHandler : public TSignalHandler {
-private:
-   AliMDC *fMDC;   // alimdc to signal
 public:
    AliMDCInterruptHandler(AliMDC *mdc) : TSignalHandler(kSigUser1, kFALSE), fMDC(mdc) { }
    Bool_t Notify() {
@@ -1199,6 +1286,11 @@ public:
       fMDC->SetStopLoop();
       return kTRUE;
    }
+private:
+   AliMDC *fMDC;   // alimdc to signal
+
+   AliMDCInterruptHandler(const AliMDCInterruptHandler &);
+   void operator=(const AliMDCInterruptHandler &);
 };
 
 //______________________________________________________________________________
@@ -1402,7 +1494,6 @@ Int_t AliMDC::Run()
                   Info("Run", "Skipping %s (%d bytes)", header.GetTypeName(), skip);
                continue;
             }
-            break;
          default:
             ALIDEBUG(1) {
                Int_t s = header.GetEventSize() - header.HeaderSize();
@@ -1780,32 +1871,14 @@ Int_t AliMDC::DumpEvent(Int_t toRead)
    return nrecv;
 }
 
-#ifdef USE_HLT
-#include <AliTPCL3Tunnel.h>
-#endif
-
 //______________________________________________________________________________
 Int_t AliMDC::Filter(AliRawData &raw)
 {
    // Call 3rd level filter for this raw data segment.
 
 #ifdef USE_HLT
-   AliTPCL3Tunnel *tunnel = 0;
-   if (!tunnel) {
-      // initialisation
-      tunnel = new AliTPCL3Tunnel(Form("%s/TPCparams.root",
-                                       gSystem->Getenv("ALITPC")));
-   }
-
-   Int_t obytes, nbytes;
-   obytes = nbytes = raw.GetSize();
-   char *outbuf = tunnel->EvalTrack((char *)raw.GetBuffer(), nbytes);
-
-   raw.SetSize(nbytes);
-   memcpy(raw.GetBuffer(), outbuf, nbytes);
 
-   printf("Filter called for event %d: reduced from %d to %d\n", fNumEvents,
-          obytes, nbytes);
+   // Add HLT code here
 
 #else