From e10815f1d81dbd131a43ebba6708937ffb71a740 Mon Sep 17 00:00:00 2001 From: tkuhr Date: Fri, 3 Dec 2004 11:56:06 +0000 Subject: [PATCH] AliMDC event loop and rootification separated, c interface to AliMDC, command line parameter for run/tag DB, file locations steerable by environment varaibles, filter algorithms extracted to AliFilter classes, new library MDC --- RAW/AliFilter.cxx | 31 ++ RAW/AliFilter.h | 28 + RAW/AliHoughFilter.cxx | 125 +++++ RAW/AliHoughFilter.h | 25 + RAW/AliMDC.cxx | 1193 +++++++++++++++++----------------------- RAW/AliMDC.h | 121 ++-- RAW/AliRawCastorDB.cxx | 32 +- RAW/AliRawCastorDB.h | 5 +- RAW/AliRawDB.cxx | 111 ++-- RAW/AliRawDB.h | 38 +- RAW/AliRawNullDB.cxx | 14 +- RAW/AliRawNullDB.h | 5 +- RAW/AliRawRFIODB.cxx | 29 +- RAW/AliRawRFIODB.h | 5 +- RAW/AliRawRootdDB.cxx | 27 +- RAW/AliRawRootdDB.h | 5 +- RAW/AliRunDB.cxx | 53 +- RAW/AliRunDB.h | 13 +- RAW/AliStats.cxx | 2 - RAW/AliTagDB.cxx | 52 +- RAW/AliTagDB.h | 18 +- RAW/AliTagNullDB.cxx | 6 +- RAW/AliTagNullDB.h | 2 +- RAW/RAWLinkDef.h | 1 + RAW/alimdcLinkDef.h | 9 + RAW/alimdc_main.cxx | 177 ++++-- RAW/binalimdc.pkg | 12 +- RAW/libMDC.pkg | 27 + RAW/libRAW.pkg | 4 +- RAW/mdc.cxx | 66 +++ RAW/mdc.h | 31 ++ 31 files changed, 1259 insertions(+), 1008 deletions(-) create mode 100644 RAW/AliFilter.cxx create mode 100644 RAW/AliFilter.h create mode 100644 RAW/AliHoughFilter.cxx create mode 100644 RAW/AliHoughFilter.h create mode 100644 RAW/alimdcLinkDef.h create mode 100644 RAW/libMDC.pkg create mode 100644 RAW/mdc.cxx create mode 100644 RAW/mdc.h diff --git a/RAW/AliFilter.cxx b/RAW/AliFilter.cxx new file mode 100644 index 00000000000..b757779d68c --- /dev/null +++ b/RAW/AliFilter.cxx @@ -0,0 +1,31 @@ +/************************************************************************** + * Copyright(c) 1998-1999, 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. * + **************************************************************************/ + +/* $Id$ */ + +/////////////////////////////////////////////////////////////////////////////// +// // +// base class for high level filter algorithms // +// Derived classes should implement a default constructor and // +// the virtual method Filter // +// // +/////////////////////////////////////////////////////////////////////////////// + + +#include "AliFilter.h" + + +ClassImp(AliFilter) + diff --git a/RAW/AliFilter.h b/RAW/AliFilter.h new file mode 100644 index 00000000000..e057a43c21a --- /dev/null +++ b/RAW/AliFilter.h @@ -0,0 +1,28 @@ +#ifndef ALIFILTER_H +#define ALIFILTER_H +/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * See cxx source for full Copyright notice */ + +/* $Id$ */ + +// +// base class for high level filter algorithms +// Derived classes should implement a default constructor and +// the virtual method Filter +// + +#include + +class AliRawEvent; +class AliESD; + + +class AliFilter: public TObject { +public: + virtual Bool_t Filter(AliRawEvent* event, AliESD* esd) = 0; + +private: + ClassDef(AliFilter, 0) // base class for high level filter algorithms +}; + +#endif diff --git a/RAW/AliHoughFilter.cxx b/RAW/AliHoughFilter.cxx new file mode 100644 index 00000000000..e7fca6ed065 --- /dev/null +++ b/RAW/AliHoughFilter.cxx @@ -0,0 +1,125 @@ +/************************************************************************** + * Copyright(c) 1998-1999, 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. * + **************************************************************************/ + +/* $Id$ */ + +/////////////////////////////////////////////////////////////////////////////// +// // +// high level filter algorithm for TPC using a hough transformation // +// // +/////////////////////////////////////////////////////////////////////////////// + + +#include + +#include "AliL3StandardIncludes.h" +#include "AliL3Logging.h" +#include "AliL3Transform.h" +#include "AliL3Hough.h" +#include "AliLog.h" + +#include "AliHoughFilter.h" + + +ClassImp(AliHoughFilter) + +//_____________________________________________________________________________ +AliHoughFilter::AliHoughFilter() +{ +// default constructor + + AliL3Log::fgLevel = AliL3Log::kError; + if (AliDebugLevel() > 0) AliL3Log::fgLevel = AliL3Log::kWarning; + if (AliDebugLevel() > 1) AliL3Log::fgLevel = AliL3Log::kInformational; + if (AliDebugLevel() > 2) AliL3Log::fgLevel = AliL3Log::kDebug; + if (!AliL3Transform::Init("./", kFALSE)) { + AliError("HLT initialization failed!"); + } +} + +//_____________________________________________________________________________ +Bool_t AliHoughFilter::Filter(AliRawEvent* event, AliESD* esd) +{ +// TPC hough transformation + + TStopwatch timer; + timer.Start(); + + Float_t ptmin = 0.1*AliL3Transform::GetSolenoidField(); + + AliL3Hough *hough1 = new AliL3Hough(); + + hough1->SetThreshold(4); + hough1->CalcTransformerParams(ptmin); + hough1->SetPeakThreshold(70,-1); + // Attention Z of the vertex to be taken from the event head! + // So far for debug purposes it is fixed by hand... + hough1->Init(100,4,event,3.82147); + hough1->SetAddHistograms(); + + AliL3Hough *hough2 = new AliL3Hough(); + + hough2->SetThreshold(4); + hough2->CalcTransformerParams(ptmin); + hough2->SetPeakThreshold(70,-1); + hough2->Init(100,4,event,3.82147); + hough2->SetAddHistograms(); + + Int_t nglobaltracks = 0; + /* In case we run HLT code in 2 threads */ + hough1->StartProcessInThread(0,17); + hough2->StartProcessInThread(18,35); + + if(hough1->WaitForThreadFinish()) + AliFatal(" Can not join the required thread! "); + if(hough2->WaitForThreadFinish()) + AliFatal(" Can not join the required thread! "); + + /* In case we run HLT code in the main thread + for(Int_t slice=0; slice<=17; slice++) + { + hough1->ReadData(slice,0); + hough1->Transform(); + hough1->AddAllHistogramsRows(); + hough1->FindTrackCandidatesRow(); + hough1->AddTracks(); + } + for(Int_t slice=18; slice<=35; slice++) + { + hough2->ReadData(slice,0); + hough2->Transform(); + hough2->AddAllHistogramsRows(); + hough2->FindTrackCandidatesRow(); + hough2->AddTracks(); + } + */ + + nglobaltracks += hough1->FillESD(esd); + nglobaltracks += hough2->FillESD(esd); + + /* In case we want to debug the ESD + gSystem->MakeDirectory("hough1"); + hough1->WriteTracks("./hough1"); + gSystem->MakeDirectory("hough2"); + hough2->WriteTracks("./hough2"); + */ + + delete hough1; + delete hough2; + + printf("Filter has found %d TPC tracks in %f seconds\n", nglobaltracks,timer.RealTime()); + + return kFALSE; +} diff --git a/RAW/AliHoughFilter.h b/RAW/AliHoughFilter.h new file mode 100644 index 00000000000..73414db2939 --- /dev/null +++ b/RAW/AliHoughFilter.h @@ -0,0 +1,25 @@ +#ifndef ALIHOUGHFILTER_H +#define ALIHOUGHFILTER_H +/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * See cxx source for full Copyright notice */ + +/* $Id$ */ + +/// +/// high level filter algorithm for TPC using a hough transformation +/// + +#include "AliFilter.h" + + +class AliHoughFilter: public AliFilter { +public: + AliHoughFilter(); + + virtual Bool_t Filter(AliRawEvent* event, AliESD* esd); + +private: + ClassDef(AliHoughFilter, 0) // TPC hough filter +}; + +#endif diff --git a/RAW/AliMDC.cxx b/RAW/AliMDC.cxx index 1206823e7da..b7b1f65d5bb 100644 --- a/RAW/AliMDC.cxx +++ b/RAW/AliMDC.cxx @@ -49,26 +49,16 @@ #include #include -#include +#include #include -#ifdef ALI_DATE -#include "event.h" -#endif +#include #ifdef USE_EB #include "libDateEb.h" #endif -#ifdef USE_HLT -#include -#ifndef use_logging -#include "AliL3Logging.h" -#endif -#include -#include "AliRawReaderRoot.h" -#include +#include #include -#endif #include "AliRawEvent.h" #include "AliRawEventHeader.h" @@ -83,6 +73,7 @@ #include "AliRawNullDB.h" #include "AliTagDB.h" #include "AliRunDB.h" +#include "AliFilter.h" #include "AliMDC.h" @@ -90,107 +81,95 @@ ClassImp(AliMDC) -#define ALIDEBUG(level) \ - if (AliMDC::Instance() && (AliMDC::Instance()->GetDebugLevel() >= (level))) +// Filter names +const char* const AliMDC::fgkFilterName[kNFilters] = {"AliHoughFilter"}; +//______________________________________________________________________________ +AliMDC::AliMDC(Int_t compress, Bool_t deleteFiles, EFilterMode filterMode, + const char* localRunDB, Bool_t rdbmsRunDB, + const char* alienHostRunDB, const char* alienDirRunDB, + Double_t maxSizeTagDB, const char* fileNameTagDB) : + fEvent(new AliRawEvent), + fESD(NULL), + fStats(NULL), + fRawDB(NULL), + fRunDB(new AliRunDB(localRunDB, rdbmsRunDB, alienHostRunDB, alienDirRunDB)), + fTagDB(NULL), + fCompress(compress), + fDeleteFiles(deleteFiles), + fFilterMode(filterMode), + fFilters(), + fStop(kFALSE) +{ + // Create MDC processor object. + // compress is the file compression mode. + // If deleteFiles is kTRUE the raw data files will be deleted after they + // were closed. + // If the filterMode if kFilterOff no filter algorithm will be, if it is + // kFilterTransparent the algorthims will be run but no events will be + // rejected, if it is kFilterOn the filters will be run and the event will + // be rejected if all filters return kFALSE. + // localRunDB is the file name of the local run DB; if NULL no local run DB + // will be created. + // The filling of a MySQL run DB can be switch on or off with rdbmsRunDB. + // The host and directory name of the alien run DB can be specified by + // alienHostRunDB and alienDirRunDB; if NULL no alien DB will be filled. + // If maxSizeTagDB is greater than 0 it determines the maximal size of the + // tag DB and then fileNameTagDB is the directory name for the tag DB. + // Otherwise fileNameTagDB is the file name of the tag DB. If it is NULL + // no tag DB will be created. + + + if (fFilterMode != kFilterOff) { + fESD = new AliESD; + } -// Fixed file system locations for the different DB's -#ifdef USE_RDM -const char* const AliMDC::fgkFifo = "/tmp/alimdc.fifo"; -const char* const AliMDC::fgkRawDBFS[2] = { "/tmp/mdc1", "/tmp/mdc2" }; -const char* const AliMDC::fgkTagDBFS = "/tmp/mdc1/tags"; -const char* const AliMDC::fgkRunDBFS = "/tmp/mdc1/meta"; -const char* const AliMDC::fgkRFIOFS = "rfio:/castor/cern.ch/user/r/rdm"; -const char* const AliMDC::fgkCastorFS = "castor:/castor/cern.ch/user/r/rdm"; -const char* const AliMDC::fgkRootdFS = "root://localhost//tmp/mdc1"; -const char* const AliMDC::fgkAlienHost = "alien://aliens7.cern.ch:15000/?direct"; -const char* const AliMDC::fgkAlienDir = "/alice_mdc/DC"; -#else -const char* const AliMDC::fgkFifo = "/tmp/alimdc.fifo"; -const char* const AliMDC::fgkRawDBFS[2] = { "/data1/mdc", "/data2/mdc" }; -const char* const AliMDC::fgkTagDBFS = "/data1/mdc/tags"; -const char* const AliMDC::fgkRunDBFS = "/data1/mdc/meta"; -const char* const AliMDC::fgkRFIOFS = "rfio:/castor/cern.ch/lcg/dc5"; -const char* const AliMDC::fgkCastorFS = "castor:/castor/cern.ch/lcg/dc5"; -const char* const AliMDC::fgkRootdFS = "root://localhost//tmp/mdc1"; -const char* const AliMDC::fgkAlienHost = "alien://aliens7.cern.ch:15000/?direct"; -const char* const AliMDC::fgkAlienDir = "/alice_mdc/DC"; -#endif - -// Maximum size of tag db files -const Double_t AliMDC::fgkMaxTagFileSize = 2.5e8; // 250MB - -Bool_t AliMDC::fgDeleteFiles = kFALSE; -AliMDC* AliMDC::fgInstance = NULL; + if (fileNameTagDB) { + if (maxSizeTagDB > 0) { + fTagDB = new AliTagDB(fEvent->GetHeader(), NULL); + fTagDB->SetMaxSize(maxSizeTagDB); + fTagDB->SetFS(fileNameTagDB); + fTagDB->Create(); + } else { + fTagDB = new AliTagDB(fEvent->GetHeader(), fileNameTagDB); + } + } + // install SIGUSR1 handler to allow clean interrupts + gSystem->AddSignalHandler(new AliMDCInterruptHandler(this)); -//______________________________________________________________________________ -AliMDC::AliMDC(Int_t fd, Int_t compress, Double_t maxFileSize, Bool_t useFilter, - EWriteMode mode, Bool_t useLoop, Bool_t delFiles) -{ - // Create MDC processor object. - - fFd = fd; - fCompress = compress; - fMaxFileSize = maxFileSize; - fUseFilter = useFilter; - fWriteMode = mode; - fUseLoop = useLoop; - fUseFifo = kFALSE; - fUseEb = kFALSE; - fStopLoop = kFALSE; - fNumEvents = 0; - fDebugLevel = 0; - fgDeleteFiles = delFiles; - - if (fFd == -1) { -#ifdef USE_EB - if (!ebRegister()) { - Error("AliMDC", "cannot register with the event builder (%s)", - ebGetLastError()); - return; - } - fUseEb = kTRUE; -#else - if ((mkfifo(fgkFifo, 0644) < 0) && (errno != EEXIST)) { - Error("AliMDC", "cannot create fifo %s", fgkFifo); - return; - } - if ((chmod(fgkFifo, 0666) == -1) && (errno != EPERM)) { - Error("AliMDC", "cannot change permission of fifo %s", fgkFifo); - return; + // create the high level filters + if (fFilterMode != kFilterOff) { + for (Int_t iFilter = 0; iFilter < kNFilters; iFilter++) { + TClass* filterClass = gROOT->GetClass(fgkFilterName[iFilter]); + if (!filterClass) { + Warning("AliMDC", "no filter class %s found", fgkFilterName[iFilter]); + continue; } - if ((fFd = open(fgkFifo, O_RDONLY)) == -1) { - Error("AliMDC", "cannot open input file %s", fgkFifo); - return; + AliFilter* filter = (AliFilter*) filterClass->New(); + if (!filter) { + Warning("AliMDC", "creation of filter %s failed", fgkFilterName[iFilter]); + continue; } - fUseFifo = kTRUE; -#endif - fUseLoop = kFALSE; - } - - printf(": input = %s, rawdb size = %f, filter = %s, " - "looping = %s, compression = %d, delete files = %s", - fUseFifo ? "fifo" : (fUseEb ? "eb" : "file"), fMaxFileSize, - fUseFilter ? "on" : "off", fUseLoop ? "yes" : "no", fCompress, - fgDeleteFiles ? "yes" : "no"); - if (fWriteMode == kRFIO) - printf(", use RFIO\n"); - else if (fWriteMode == kROOTD) - printf(", use rootd\n"); - else if (fWriteMode == kCASTOR) - printf(", use CASTOR/rootd\n"); - else if (fWriteMode == kDEVNULL) - printf(", write raw data to /dev/null\n"); - else - printf("\n"); - - // install SIGUSR1 handler to allow clean interrupts - gSystem->AddSignalHandler(new AliMDCInterruptHandler(this)); - - fgInstance = this; + fFilters.Add(filter); + } + } } +//______________________________________________________________________________ +AliMDC::~AliMDC() +{ +// destructor + + fFilters.Delete(); + delete fTagDB; + delete fRunDB; + delete fRawDB; + delete fStats; + delete fESD; + delete fEvent; +} + //______________________________________________________________________________ AliMDC::AliMDC(const AliMDC& mdc): TObject(mdc) { @@ -208,449 +187,450 @@ AliMDC& AliMDC::operator = (const AliMDC& /*mdc*/) return *this; } + //______________________________________________________________________________ -Int_t AliMDC::Run() +Int_t AliMDC::Open(EWriteMode mode, const char* fileName) { - // Run the MDC processor. Read from the input stream and only return - // when the input gave and EOF or a fatal error occured. On success 0 - // is returned, 1 in case of a fatality. - - TStopwatch timer; - Int_t status; - - // Make sure needed directories exist - const char *dirs[4]; - dirs[0] = fgkRawDBFS[0]; - dirs[1] = fgkRawDBFS[1]; - dirs[2] = fgkTagDBFS; - dirs[3] = fgkRunDBFS; - for (int idir = 0; idir < 4; idir++) { - gSystem->ResetErrno(); - gSystem->MakeDirectory(dirs[idir]); - if (gSystem->GetErrno() && gSystem->GetErrno() != EEXIST) { - SysError("Run", "mkdir %s", dirs[idir]); - return 1; - } - } +// open a new raw DB file + + if (mode == kRFIO) + fRawDB = new AliRawRFIODB(fEvent, fESD, fCompress, fileName); + else if (mode == kROOTD) + fRawDB = new AliRawRootdDB(fEvent, fESD, fCompress, fileName); + else if (mode == kCASTOR) + fRawDB = new AliRawCastorDB(fEvent, fESD, fCompress, fileName); + else if (mode == kDEVNULL) + fRawDB = new AliRawNullDB(fEvent, fESD, fCompress, fileName); + else + fRawDB = new AliRawDB(fEvent, fESD, fCompress, fileName); + fRawDB->SetDeleteFiles(fDeleteFiles); + + if (fRawDB->IsZombie()) { + delete fRawDB; + fRawDB = NULL; + return 1; + } + Info("Open", "Filling raw DB %s\n", fRawDB->GetDBName()); - // Used for statistics - timer.Start(); - Double_t told = 0, tnew = 0; - Float_t chunkSize = fMaxFileSize/100, nextChunk = chunkSize; - - // Event object used to store event data. - AliRawEvent *event = new AliRawEvent; -#ifdef USE_HLT - //Init HLT -#ifndef use_logging - AliL3Log::fgLevel=AliL3Log::kError; - ALIDEBUG(1) - AliL3Log::fgLevel=AliL3Log::kWarning; - ALIDEBUG(2) - AliL3Log::fgLevel=AliL3Log::kWarning; - ALIDEBUG(3) - AliL3Log::fgLevel=AliL3Log::kNone; -#endif - if (fUseFilter) { - if (!AliL3Transform::Init("./", kFALSE)) { - Error("Run","HLT initialization failed!"); - return 1; - } - } + // Create AliStats object + fStats = new AliStats(fRawDB->GetDBName(), fCompress, + fFilterMode != kFilterOff); + return 0; +} - AliESD *esd = new AliESD; -#endif +//______________________________________________________________________________ +Int_t AliMDC::ProcessEvent(void* event, Bool_t isIovecArray) +{ +// Convert the DATE event to an AliRawEvent object and store it in the raw DB, +// optionally also run the filter. +// event is either a pointer to the streamlined event +// or, if isIovecArray is kTRUE, a pointer to an array of iovecs with one +// iovec per subevent (used by the event builder). +// The return value is the number of written bytes or an error code + + Int_t status; + char* data = (char*) event; + if (isIovecArray) data = (char*) ((iovec*) event)[0].iov_base; + + // Shortcut for easy header access + AliRawEventHeader &header = *fEvent->GetHeader(); + + // Read event header + if ((status = ReadHeader(header, data)) != header.HeaderSize()) { + return kErrHeader; + } - // Create new raw DB. - AliRawDB *rawdb; - if (fWriteMode == kRFIO) - rawdb = new AliRawRFIODB(event, -#ifdef USE_HLT - esd, -#endif - fMaxFileSize, fCompress); - else if (fWriteMode == kROOTD) - rawdb = new AliRawRootdDB(event, -#ifdef USE_HLT - esd, -#endif - fMaxFileSize, fCompress); - else if (fWriteMode == kCASTOR) - rawdb = new AliRawCastorDB(event, -#ifdef USE_HLT - esd, -#endif - fMaxFileSize, fCompress); - else if (fWriteMode == kDEVNULL) - rawdb = new AliRawNullDB(event, -#ifdef USE_HLT - esd, -#endif - fMaxFileSize, fCompress); - else - rawdb = new AliRawDB(event, -#ifdef USE_HLT - esd, -#endif - fMaxFileSize, fCompress); - - if (rawdb->IsZombie()) return 1; - printf("Filling raw DB %s\n", rawdb->GetDBName()); - - // Create new tag DB. - AliTagDB *tagdb = 0; -#if 0 - // no tagdb for the time being to get maximum speed - if (fWriteMode == fgkDEVNULL) - tagdb = new AliTagNullDB(event->GetHeader(), fgkMaxTagFileSize); - else - tagdb = new AliTagDB(event->GetHeader(), fgkMaxTagFileSize); - if (tagdb->IsZombie()) - tagdb = 0; - else - printf("Filling tag DB %s\n", tagdb->GetDBName()); -#endif + if (AliDebugLevel() > 2) ToAliDebug(3, header.Dump();); + + // Check event type and skip "Start of Run", "End of Run", + // "Start of Run Files" and "End of Run Files" + Int_t size = header.GetEventSize() - header.HeaderSize(); + switch (header.GetType()) { + case AliRawEventHeader::kStartOfRun: + case AliRawEventHeader::kEndOfRun: + case AliRawEventHeader::kStartOfRunFiles: + case AliRawEventHeader::kEndOfRunFiles: + { + AliDebug(1, Form("Skipping %s (%d bytes)", header.GetTypeName(), size)); + return kErrStartEndRun; + } + default: + { + AliDebug(1, Form("Processing %s (%d bytes)", header.GetTypeName(), size)); + } + } - // Create AliStats object - AliStats *stats = new AliStats(rawdb->GetDBName(), fCompress, fUseFilter); + // Amount of data left to read for this event + Int_t toRead = size; - // Shortcut for easy header access - AliRawEventHeader &header = *event->GetHeader(); + // If there is less data for this event than the next sub-event + // header, something is wrong. Skip to next event... + if (toRead < header.HeaderSize()) { + Error("ProcessEvent", "header size (%d) exceeds number of bytes " + "to read (%d)", header.HeaderSize(), toRead); + if (AliDebugLevel() > 0) ToAliDebug(1, header.Dump();); + return kErrHeaderSize; + } + + // Loop over all sub-events... (LDCs) + Int_t nsub = 1; + while (toRead > 0) { + if (isIovecArray) data = (char*) ((iovec*) event)[nsub].iov_base; + + AliDebug(1, Form("reading LDC %d", nsub)); + + AliRawEvent *subEvent = fEvent->NextSubEvent(); + + // Read sub-event header + AliRawEventHeader &subHeader = *subEvent->GetHeader(); + if ((status = ReadHeader(subHeader, data)) != subHeader.HeaderSize()) { + return kErrSubHeader; + } + + if (AliDebugLevel() > 2) ToAliDebug(3, subHeader.Dump();); + + toRead -= subHeader.HeaderSize(); + + Int_t rawSize = subHeader.GetEventSize() - subHeader.HeaderSize(); + + // Make sure raw data less than left over bytes for current event + if (rawSize > toRead) { + Warning("ProcessEvent", "raw data size (%d) exceeds number of " + "bytes to read (%d)\n", rawSize, toRead); + if (AliDebugLevel() > 0) ToAliDebug(1, subHeader.Dump();); + return kErrDataSize; + } + + // Read Equipment Headers (in case of physics or calibration event) + if (header.GetType() == AliRawEventHeader::kPhysicsEvent || + header.GetType() == AliRawEventHeader::kCalibrationEvent) { + while (rawSize > 0) { + AliRawEquipment &equipment = *subEvent->NextEquipment(); + AliRawEquipmentHeader &equipmentHeader = + *equipment.GetEquipmentHeader(); + Int_t equipHeaderSize = equipmentHeader.HeaderSize(); + if ((status = ReadEquipmentHeader(equipmentHeader, header.DataIsSwapped(), + data)) != equipHeaderSize) { + return kErrEquipmentHeader; + } + toRead -= equipHeaderSize; + rawSize -= equipHeaderSize; + + // Read equipment raw data + AliRawData &subRaw = *equipment.GetRawData(); + + Int_t eqSize = equipmentHeader.GetEquipmentSize() - equipHeaderSize; + if ((status = ReadRawData(subRaw, eqSize, data)) != eqSize) { + return kErrEquipment; + } + toRead -= eqSize; + rawSize -= eqSize; - // Process input stream -#ifdef USE_EB - Int_t eorFlag = 0; - while (!(eorFlag = ebEor())) { - struct iovec *ebvec; - if ((ebvec = ebGetNextEvent()) == (void *)-1) { - Error("Run", "error getting next event (%s)", ebGetLastError()); - break; - } - if (ebvec == 0) { - // no event, sleep for 1 second and try again - gSystem->Sleep(1000); - continue; } - char *ebdata = (char *) ebvec[0].iov_base; -#else - while (1) { - char *ebdata = 0; -#endif - // Read event header - if ((status = ReadHeader(header, ebdata)) != header.HeaderSize()) { - if (status == 0) { - if (fUseLoop) { -#ifndef USE_EB - ::lseek(fFd, 0, SEEK_SET); -#endif - continue; - } - printf(": EOF, processed %d events\n", fNumEvents); - break; - } - return 1; + } else { // Read only raw data but no equipment header + AliRawEquipment &equipment = *subEvent->NextEquipment(); + AliRawData &subRaw = *equipment.GetRawData(); + if ((status = ReadRawData(subRaw, rawSize, data)) != rawSize) { + return kErrEquipment; } - ALIDEBUG(3) - header.Dump(); + toRead -= rawSize; - // If we were in looping mode stop directly after a SIGUSR1 signal - if (StopLoop()) { - Info("Run", "Stopping loop, processed %d events", fNumEvents); - break; - } + } - // Check if event has any hard track flagged - Bool_t callFilter = kFALSE; - if (fUseFilter) - callFilter = kTRUE; - - // Check event type and skip "Start of Run", "End of Run", - // "Start of Run Files" and "End of Run Files" - switch (header.GetType()) { - case AliRawEventHeader::kStartOfRun: - case AliRawEventHeader::kEndOfRun: - case AliRawEventHeader::kStartOfRunFiles: - case AliRawEventHeader::kEndOfRunFiles: - { - Int_t skip = header.GetEventSize() - header.HeaderSize(); -#ifndef USE_EB - ::lseek(fFd, skip, SEEK_CUR); -#endif - ALIDEBUG(1) - Info("Run", "Skipping %s (%d bytes)", header.GetTypeName(), skip); - continue; - } - default: - ALIDEBUG(1) { - Int_t s = header.GetEventSize() - header.HeaderSize(); - Info("Run", "Processing %s (%d bytes)", header.GetTypeName(), s); - } - } + nsub++; + } - // Amount of data left to read for this event - Int_t toRead = header.GetEventSize() - header.HeaderSize(); - - // If there is less data for this event than the next sub-event - // header, something is wrong. Skip to next event... - if (toRead < header.HeaderSize()) { - ALIDEBUG(1) { - Warning("Run", - "header size (%d) exceeds number of bytes to read (%d)\n", - header.HeaderSize(), toRead); - header.Dump(); - } - if ((status = DumpEvent(toRead)) != toRead) { - if (status == 0) - break; - return 1; - } - Error("Run", "discarding event %d (too little data for header)", fNumEvents); - continue; + // High Level Event Filter + if (fFilterMode != kFilterOff) { + if (header.GetType() == AliRawEventHeader::kPhysicsEvent || + header.GetType() == AliRawEventHeader::kCalibrationEvent) { + Bool_t result = kFALSE; + for (Int_t iFilter = 0; iFilter < fFilters.GetEntriesFast(); iFilter++) { + AliFilter* filter = (AliFilter*) fFilters[iFilter]; + if (!filter) continue; + if (filter->Filter(fEvent, fESD)) result = kTRUE; } + if ((fFilterMode == kFilterOn) && !result) return kFilterReject; + } + } - // Loop over all sub-events... (LDCs) - Int_t nsub = 1; - while (toRead > 0) { -#ifdef USE_EB - ebdata = (char *)ebvec[nsub].iov_base; -#endif + // Set stat info for first event of this file + if (fRawDB->GetEvents() == 0) + fStats->SetFirstId(header.GetRunNumber(), header.GetEventInRun()); + + // Store raw event in tree + Int_t nBytes = fRawDB->Fill(); - ALIDEBUG(1) - Info("Run", "reading LDC %d", nsub); + // Store header in tree + if (fTagDB) fTagDB->Fill(); - AliRawEvent *subEvent = event->NextSubEvent(); + return nBytes; +} + +//______________________________________________________________________________ +Int_t AliMDC::Close() +{ +// close the current raw DB file + + if (!fRawDB) return 1; + + fRawDB->WriteStats(fStats); + fRunDB->Update(fStats); + delete fRawDB; + fRawDB = NULL; + delete fStats; + fStats = NULL; + return 0; +} - // Read sub-event header - AliRawEventHeader &subHeader = *subEvent->GetHeader(); - if ((status = ReadHeader(subHeader, ebdata)) != subHeader.HeaderSize()) { - if (status == 0) { - Error("Run", "unexpected EOF reading sub-event header"); - break; - } - return 1; - } +//______________________________________________________________________________ +Int_t AliMDC::Run(const char* inputFile, Bool_t loop, + EWriteMode mode, Double_t maxFileSize, + const char* fs1, const char* fs2) +{ + // Run the MDC processor. Read from the input stream and only return + // when the input gave and EOF or a fatal error occured. On success 0 + // is returned, 1 in case of a fatality. + // inputFile is the name of the DATE input file; if NULL the input will + // be taken from the event builder. + // If loop is set the same input file will be reused in an infinite loop. + // mode specifies the type of the raw DB. + // maxFileSize is the maximal size of the raw DB. + // fs1 and fs2 are the file system locations of the raw DB. + + Info("Run", "input = %s, rawdb size = %f, filter = %s, " + "looping = %s, compression = %d, delete files = %s", + inputFile ? inputFile : "event builder", maxFileSize, + fFilterMode == kFilterOff ? "off" : + (fFilterMode == kFilterOn ? "on" : "transparent"), + loop ? "yes" : "no", fCompress, fDeleteFiles ? "yes" : "no"); + + // Open the input file + Int_t fd = -1; + if (inputFile) { + if ((fd = open(inputFile, O_RDONLY)) == -1) { + Error("Run", "cannot open input file %s", inputFile); + return 1; + } + } - ALIDEBUG(3) - subHeader.Dump(); + // Used for statistics + TStopwatch timer; + timer.Start(); + Double_t told = 0, tnew = 0; + Float_t chunkSize = maxFileSize/100, nextChunk = chunkSize; + + // Create new raw DB. + if (fRawDB) Close(); + if (mode == kRFIO) { + fRawDB = new AliRawRFIODB(fEvent, fESD, fCompress, NULL); + } else if (mode == kROOTD) { + fRawDB = new AliRawRootdDB(fEvent, fESD, fCompress, NULL); + } else if (mode == kCASTOR) { + fRawDB = new AliRawCastorDB(fEvent, fESD, fCompress, NULL); + } else if (mode == kDEVNULL) { + fRawDB = new AliRawNullDB(fEvent, fESD, fCompress, NULL); + } else { + fRawDB = new AliRawDB(fEvent, fESD, fCompress, NULL); + } + fRawDB->SetMaxSize(maxFileSize); + fRawDB->SetFS(fs1, fs2); + fRawDB->SetDeleteFiles(fDeleteFiles); + fRawDB->Create(); + + if (fRawDB->IsZombie()) { + delete fRawDB; + fRawDB = NULL; + return 1; + } + printf("Filling raw DB %s\n", fRawDB->GetDBName()); - toRead -= subHeader.HeaderSize(); + // Create AliStats object + fStats = new AliStats(fRawDB->GetDBName(), fCompress, + fFilterMode != kFilterOff); + // Process input stream #ifdef USE_EB - ebdata = (char *)(ebvec[nsub].iov_base) + subHeader.HeaderSize(); + Int_t eorFlag = 0; #endif + char* event = NULL; + UInt_t eventSize = 0; + Int_t numEvents = 0; + + while (kTRUE) { + + // If we were in looping mode stop directly after a SIGUSR1 signal + if (fStop) { + Info("Run", "Stopping loop, processed %d events", numEvents); + break; + } - Int_t rawSize = subHeader.GetEventSize() - subHeader.HeaderSize(); - - // Make sure raw data less than left over bytes for current event - if (rawSize > toRead) { - ALIDEBUG(1) { - Warning("Run", "raw data size (%d) exceeds number of " - "bytes to read (%d)\n", rawSize, toRead); - subHeader.Dump(); - } - if ((status = DumpEvent(toRead)) != toRead) { - if (status == 0) - break; - return 1; - } - Error("Run", "discarding event %d (too much data)", fNumEvents); - continue; - } - - // Read Equipment Headers (in case of physics or calibration event) - if (header.GetType() == AliRawEventHeader::kPhysicsEvent || - header.GetType() == AliRawEventHeader::kCalibrationEvent) { - while (rawSize > 0) { - AliRawEquipment &equipment = *subEvent->NextEquipment(); - AliRawEquipmentHeader &equipmentHeader = - *equipment.GetEquipmentHeader(); - Int_t equipHeaderSize = equipmentHeader.HeaderSize(); - if ((status = ReadEquipmentHeader(equipmentHeader, header.DataIsSwapped(), - ebdata)) != equipHeaderSize) { - if (status == 0) { - Error("Run", "unexpected EOF reading equipment-header"); - break; - } - return 1; - } - toRead -= equipHeaderSize; - rawSize -= equipHeaderSize; + if (!inputFile) { // get data from event builder #ifdef USE_EB - ebdata = (char *)(ebvec[nsub].iov_base) + - subHeader.HeaderSize() + equipHeaderSize; + if ((eorFlag = ebEor())) break; + if ((event = (char*)ebGetNextEvent()) == (char*)-1) { + Error("Run", "error getting next event (%s)", ebGetLastError()); + break; + } + if (event == 0) { + // no event, sleep for 1 second and try again + gSystem->Sleep(1000); + continue; + } +#else + Error("Run", "AliMDC was compiled without event builder support"); + delete fRawDB; + fRawDB = NULL; + delete fStats; + fStats = NULL; + return 1; #endif - // Read equipment raw data - AliRawData &subRaw = *equipment.GetRawData(); - - Int_t eqSize = equipmentHeader.GetEquipmentSize() - - equipHeaderSize; - if ((status = ReadRawData(subRaw, eqSize, ebdata)) != eqSize) { - if (status == 0) { - Error("Run", "unexpected EOF reading sub-event raw data"); - break; - } - return 1; - } - toRead -= eqSize; - rawSize -= eqSize; - - } - - } else { // Read only raw data but no equipment header - AliRawEquipment &equipment = *subEvent->NextEquipment(); - AliRawData &subRaw = *equipment.GetRawData(); - if ((status = ReadRawData(subRaw, rawSize, ebdata)) != rawSize) { - if (status == 0) { - Error("Run", "unexpected EOF reading sub-event raw data"); - break; - } - return 1; - } - toRead -= rawSize; - - } - - nsub++; + } else { // get data from a file + AliRawEventHeader header; + Int_t nrecv; + if ((nrecv = Read(fd, header.HeaderBegin(), header.HeaderSize())) != + header.HeaderSize()) { + if (nrecv == 0) { // eof + if (loop) { + ::lseek(fd, 0, SEEK_SET); + continue; + } else { + break; + } + } else { + Error("Run", "error reading header"); + Close(); + delete[] event; + return 1; + } } - - //HLT - if (callFilter) { -#ifdef ALI_DATE - if(header.GetType() == AliRawEventHeader::kPhysicsEvent || - header.GetType() == AliRawEventHeader::kCalibrationEvent) - Filter( -#ifdef USE_HLT - event,esd -#endif - ); -#endif + if (eventSize < header.GetEventSize()) { + delete[] event; + eventSize = 2 * header.GetEventSize(); + event = new char[eventSize]; } + memcpy(event, header.HeaderBegin(), header.HeaderSize()); + Int_t size = header.GetEventSize() - header.HeaderSize(); + if (Read(fd, event + header.HeaderSize(), size) != size) { + Error("Run", "error reading data"); + Close(); + delete[] event; + return 1; + } + } - // Set stat info for first event of this file - if (rawdb->GetEvents() == 0) - stats->SetFirstId(header.GetRunNumber(), header.GetEventInRun()); - - // Store raw event in tree - rawdb->Fill(); - - // Store header in tree - if (tagdb) tagdb->Fill(); - - fNumEvents++; + Int_t result = ProcessEvent(event, !inputFile); - if (!(fNumEvents%10)) - printf("Processed event %d (%d)\n", fNumEvents, rawdb->GetEvents()); + if (result >= 0) { + numEvents++; + if (!(numEvents%10)) + printf("Processed event %d (%d)\n", numEvents, fRawDB->GetEvents()); + } + if (result > 0) { // Filling time statistics - if (rawdb->GetBytesWritten() > nextChunk) { - tnew = timer.RealTime(); - stats->Fill(tnew-told); - told = tnew; - timer.Continue(); - nextChunk += chunkSize; + if (fRawDB->GetBytesWritten() > nextChunk) { + tnew = timer.RealTime(); + fStats->Fill(tnew-told); + told = tnew; + timer.Continue(); + nextChunk += chunkSize; } // Check size of raw db. If bigger than maxFileSize, close file // and continue with new file. - if (rawdb->FileFull()) { - - printf("Written raw DB at a rate of %.1f MB/s\n", - rawdb->GetBytesWritten() / timer.RealTime() / 1000000.); - - // Write stats object to raw db, run db, MySQL and AliEn - rawdb->WriteStats(stats); - AliRunDB::WriteStats(stats); - delete stats; - - if (!rawdb->NextFile()) { - Error("Run", "error opening next raw data file"); - return 1; - } - - printf("Filling raw DB %s\n", rawdb->GetDBName()); - stats = new AliStats(rawdb->GetDBName(), fCompress, fUseFilter); - - timer.Start(); - told = 0, tnew = 0; - nextChunk = chunkSize; + if (fRawDB->GetBytesWritten() > maxFileSize) { + + printf("Written raw DB at a rate of %.1f MB/s\n", + fRawDB->GetBytesWritten() / timer.RealTime() / 1000000.); + + // Write stats object to raw db, run db, MySQL and AliEn + fRawDB->WriteStats(fStats); + if (fRunDB) fRunDB->Update(fStats); + delete fStats; + fStats = NULL; + + if (!fRawDB->NextFile()) { + Error("Run", "error opening next raw data file"); + Close(); + if (inputFile) delete[] event; + return 1; + } + + printf("Filling raw DB %s\n", fRawDB->GetDBName()); + fStats = new AliStats(fRawDB->GetDBName(), fCompress, + fFilterMode != kFilterOff); + + timer.Start(); + told = 0, tnew = 0; + nextChunk = chunkSize; } // Check size of tag db - if (tagdb && tagdb->FileFull()) { - if (!tagdb->NextFile()) - tagdb = 0; - else - printf("Filling tag DB %s\n", tagdb->GetDBName()); + if (fTagDB && fTagDB->FileFull()) { + if (!fTagDB->NextFile()) { + delete fTagDB; + fTagDB = 0; + } else { + printf("Filling tag DB %s\n", fTagDB->GetDBName()); + } } + } - // Make top event object ready for next event data - //printf("Event %d has %d sub-events\n", fNumEvents, event->GetNSubEvents()); - event->Reset(); -#ifdef USE_HLT - // Clean up HLT ESD for the next event - // Probably we could add esd->Reset() method to AliESD? - esd->Reset(); -#endif + // Make top event object ready for next event data + //printf("Event %d has %d sub-events\n", numEvents, fEvent->GetNSubEvents()); + fEvent->Reset(); + // Clean up HLT ESD for the next event + if (fESD) fESD->Reset(); + + if (!inputFile) { #ifdef USE_EB - if (!ebReleaseEvent(ebvec)) { - Error("Run", "problem releasing event (%s)", ebGetLastError()); - break; + if (!ebReleaseEvent((iovec*)event)) { + Error("Run", "problem releasing event (%s)", ebGetLastError()); + break; } #endif - } - - printf("Written raw DB at a rate of %.1f MB/s\n", - rawdb->GetBytesWritten() / timer.RealTime() / 1000000.); - - // Write stats to raw db and run db and delete stats object - rawdb->WriteStats(stats); - AliRunDB::WriteStats(stats); - delete stats; - - // Close the raw DB - delete rawdb; - - // Close the tag DB - delete tagdb; + } + } - // Close input source - close(fFd); + printf("Written raw DB at a rate of %.1f MB/s\n", + fRawDB->GetBytesWritten() / timer.RealTime() / 1000000.); -#if 0 - // Cleanup fifo - if (fUseFifo && ::unlink(fgkFifo) == -1) { - SysError("Run", "unlink"); - return 1; - } -#endif + // Write stats to raw db and run db and delete stats object + Close(); + if (!inputFile) { #ifdef USE_EB - // Print eor flag - if (eorFlag) { + // Print eor flag + if (eorFlag) { Info("Run", "event builder reported end of run (%d)", eorFlag); - } + } #endif + } else { + // Close input source + close(fd); + } - return 0; + return 0; } //______________________________________________________________________________ -Int_t AliMDC::Read(void *buffer, Int_t length) +Int_t AliMDC::Read(Int_t fd, void *buffer, Int_t length) { // Read exactly length bytes into buffer. Returns number of bytes // received, returns -1 in case of error and 0 for EOF. errno = 0; - if (fFd < 0) return -1; + if (fd < 0) return -1; Int_t n, nrecv = 0; char *buf = (char *)buffer; for (n = 0; n < length; n += nrecv) { - if ((nrecv = read(fFd, buf+n, length-n)) <= 0) { + if ((nrecv = read(fd, buf+n, length-n)) <= 0) { if (nrecv == 0) break; // EOF if (errno != EINTR) @@ -662,225 +642,80 @@ Int_t AliMDC::Read(void *buffer, Int_t length) } //______________________________________________________________________________ -Int_t AliMDC::ReadHeader(AliRawEventHeader &header, void *eb) +Int_t AliMDC::ReadHeader(AliRawEventHeader &header, char*& data) { - // Read header info from DATE data stream. Returns bytes read (i.e. - // AliRawEventHeader::HeaderSize()), -1 in case of error and 0 for EOF. - - Int_t nrecv; - - if (eb) { - // read from event builder memory area - memcpy(header.HeaderBegin(), eb, header.HeaderSize()); - nrecv = header.HeaderSize(); - } else { - // read from fifo or file - if ((nrecv = Read(header.HeaderBegin(), header.HeaderSize())) != - header.HeaderSize()) { - if (nrecv == 0) - return 0; - return -1; - } - } + // Read header info from DATE data stream. Returns bytes read (i.e. + // AliRawEventHeader::HeaderSize()), -1 in case of error and 0 for EOF. - // Swap header data if needed - if (header.IsSwapped()) - header.Swap(); + memcpy(header.HeaderBegin(), data, header.HeaderSize()); + data += header.HeaderSize(); - // Is header valid... - if (!header.IsValid()) { - Error("ReadHeader", "invalid header format"); - // try recovery... how? - return -1; - } - if (header.GetEventSize() < (UInt_t)header.HeaderSize()) { - Error("ReadHeader", "invalid header size"); - // try recovery... how? - return -1; - } + // Swap header data if needed + if (header.IsSwapped()) + header.Swap(); - return nrecv; + // Is header valid... + if (!header.IsValid()) { + Error("ReadHeader", "invalid header format"); + // try recovery... how? + return -1; + } + if (header.GetEventSize() < (UInt_t)header.HeaderSize()) { + Error("ReadHeader", "invalid header size"); + // try recovery... how? + return -1; + } + + return header.HeaderSize(); } //______________________________________________________________________________ Int_t AliMDC::ReadEquipmentHeader(AliRawEquipmentHeader &header, - Bool_t isSwapped, void *eb) + Bool_t isSwapped, char*& data) { - // Read equipment header info from DATE data stream. Returns bytes read - // (i.e. AliRawEquipmentHeader::HeaderSize()), -1 in case of error and - // 0 for EOF. If isSwapped is kTRUE the event data is byte swapped - // and we will swap the header to host format. - - Int_t nrecv; - - if (eb) { - // read from event builder memory area - memcpy(header.HeaderBegin(), eb, header.HeaderSize()); - nrecv = header.HeaderSize(); - } else { - // read from fifo or file - if ((nrecv = Read(header.HeaderBegin(), header.HeaderSize())) != - header.HeaderSize()) { - if (nrecv == 0) - return 0; - return -1; - } - } - - // Swap equipment header data if needed - if (isSwapped) - header.Swap(); - - if (header.GetEquipmentSize() < (UInt_t)header.HeaderSize()) { - Error("ReadEquipmentHeader", "invalid equipment header size"); - // try recovery... how? - return -1; - } + // Read equipment header info from DATE data stream. Returns bytes read + // (i.e. AliRawEquipmentHeader::HeaderSize()), -1 in case of error and + // 0 for EOF. If isSwapped is kTRUE the event data is byte swapped + // and we will swap the header to host format. + + memcpy(header.HeaderBegin(), data, header.HeaderSize()); + data += header.HeaderSize(); + + // Swap equipment header data if needed + if (isSwapped) + header.Swap(); + + if (header.GetEquipmentSize() < (UInt_t)header.HeaderSize()) { + Error("ReadEquipmentHeader", "invalid equipment header size"); + // try recovery... how? + return -1; + } - return nrecv; + return header.HeaderSize(); } //______________________________________________________________________________ -Int_t AliMDC::ReadRawData(AliRawData &raw, Int_t size, void *eb) +Int_t AliMDC::ReadRawData(AliRawData &raw, Int_t size, char*& data) { - // Read raw data from DATE data stream. Returns bytes read (i.e. - // AliRawEventHeader::HeaderSize()), -1 in case of error and 0 for EOF. - - Int_t nrecv; - - if (eb) { - // read from event builder memory area - raw.SetBuffer(eb, size); - nrecv = size; - } else { - // read from fifo or file - raw.SetSize(size); - if ((nrecv = Read(raw.GetBuffer(), size)) != size) { - if (nrecv == 0) { - Error("ReadRawData", "unexpected EOF"); - return 0; - } - return -1; - } - } + // Read raw data from DATE data stream. Returns bytes read (i.e. + // size), -1 in case of error and 0 for EOF. - return nrecv; -} - -//______________________________________________________________________________ -Int_t AliMDC::DumpEvent(Int_t toRead) -{ - // This case should not happen, but if it does try to handle it - // gracefully by reading the rest of the event and discarding it. - // Returns bytes read, -1 in case of fatal error and 0 for EOF. - - Error("DumpEvent", "dumping %d bytes of event %d", toRead, fNumEvents); - - Int_t nrecv; - char *tbuf = new char[toRead]; - if ((nrecv = Read(tbuf, toRead)) != toRead) { - if (nrecv == 0) { - Error("DumpEvent", "unexpected EOF"); - return 0; - } - return -1; - } - delete [] tbuf; + raw.SetBuffer(data, size); + data += size; - return nrecv; + return size; } //______________________________________________________________________________ -Int_t AliMDC::Filter( -#ifdef USE_HLT - AliRawEvent *event,AliESD *esd -#endif - ) +void AliMDC::Stop() { - // Call 3rd level filter for this raw data event. - -#ifdef USE_HLT - - // Run the HLT code - { - TStopwatch timer; - timer.Start(); - - Float_t ptmin = 0.1*AliL3Transform::GetSolenoidField(); - - AliL3Hough *hough1 = new AliL3Hough(); - - hough1->SetThreshold(4); - hough1->CalcTransformerParams(ptmin); - hough1->SetPeakThreshold(70,-1); - // Attention Z of the vertex to be taken from the event head! - // So far for debug purposes it is fixed by hand... - hough1->Init(100,4,event,3.82147); - hough1->SetAddHistograms(); - - AliL3Hough *hough2 = new AliL3Hough(); - - hough2->SetThreshold(4); - hough2->CalcTransformerParams(ptmin); - hough2->SetPeakThreshold(70,-1); - hough2->Init(100,4,event,3.82147); - hough2->SetAddHistograms(); - - Int_t nglobaltracks = 0; - /* In case we run HLT code in 2 threads */ - hough1->StartProcessInThread(0,17); - hough2->StartProcessInThread(18,35); - - if(hough1->WaitForThreadFinish()) - ::Fatal("AliL3Hough::WaitForThreadFinish"," Can not join the required thread! "); - if(hough2->WaitForThreadFinish()) - ::Fatal("AliL3Hough::WaitForThreadFinish"," Can not join the required thread! "); - - /* In case we run HLT code in the main thread - for(Int_t slice=0; slice<=17; slice++) - { - hough1->ReadData(slice,0); - hough1->Transform(); - hough1->AddAllHistogramsRows(); - hough1->FindTrackCandidatesRow(); - hough1->AddTracks(); - } - for(Int_t slice=18; slice<=35; slice++) - { - hough2->ReadData(slice,0); - hough2->Transform(); - hough2->AddAllHistogramsRows(); - hough2->FindTrackCandidatesRow(); - hough2->AddTracks(); - } - */ - - nglobaltracks += hough1->FillESD(esd); - nglobaltracks += hough2->FillESD(esd); - - /* In case we want to debug the ESD - gSystem->MakeDirectory("hough1"); - hough1->WriteTracks("./hough1"); - gSystem->MakeDirectory("hough2"); - hough2->WriteTracks("./hough2"); - */ - - delete hough1; - delete hough2; - - printf("Filter called for event %d\n", fNumEvents); - printf("Filter has found %d TPC tracks in %f seconds\n", nglobaltracks,timer.RealTime()); - } - -#else - - printf("Filter called for event %d\n", fNumEvents); - -#endif - - return 0; + // Stop the event loop + + fStop = kTRUE; + if (fRawDB) fRawDB->Stop(); } + //______________________________________________________________________________ AliMDC::AliMDCInterruptHandler::AliMDCInterruptHandler(const AliMDCInterruptHandler& diff --git a/RAW/AliMDC.h b/RAW/AliMDC.h index 5444985b9a3..ee7815bced7 100644 --- a/RAW/AliMDC.h +++ b/RAW/AliMDC.h @@ -16,6 +16,10 @@ #include #endif +#ifndef ROOT_TObjArray +#include +#endif + #ifndef ROOT_TSysEvtHandler #include #endif @@ -25,41 +29,41 @@ class AliRawEvent; class AliRawEventHeader; class AliRawEquipmentHeader; class AliRawData; -#ifdef USE_HLT +class AliRawDB; +class AliRunDB; +class AliTagDB; +class AliStats; class AliESD; -#endif class AliMDC : public TObject { public: enum EWriteMode { kLOCAL, kRFIO, kROOTD, kCASTOR, kDEVNULL }; - - AliMDC(Int_t fd, Int_t compress, Double_t maxFileSize, Bool_t useFilter, - EWriteMode mode, Bool_t useLoop, Bool_t delFiles); - ~AliMDC() { fgInstance = NULL; } - - static AliMDC* Instance() {return fgInstance;} - - Int_t Run(); - void SetStopLoop() { fStopLoop = kTRUE; } - Bool_t StopLoop() const { return fStopLoop; } - - void SetDebugLevel(Int_t level) { fDebugLevel = level; } - Int_t GetDebugLevel() const { return fDebugLevel; } - - static Bool_t DeleteFiles() { return fgDeleteFiles; } - - enum {kMDC = 6}; // Which MDC is this... - - static const char* Fifo() {return fgkFifo;} - static const char* RawDBFS(Int_t i) {return fgkRawDBFS[i];} - static const char* TagDBFS() {return fgkTagDBFS;} - static const char* RunDBFS() {return fgkRunDBFS;} - static const char* RFIOFS() {return fgkRFIOFS;} - static const char* CastorFS() {return fgkCastorFS;} - static const char* RootdFS() {return fgkRootdFS;} - static const char* AlienHost() {return fgkAlienHost;} - static const char* AlienDir() {return fgkAlienDir;} + enum EFilterMode { kFilterOff, kFilterTransparent, kFilterOn }; + enum EErrorCode { kFilterReject = 0, + kErrStartEndRun = -1, + kErrHeader = -2, + kErrHeaderSize = -3, + kErrSubHeader = -4, + kErrDataSize = -5, + kErrEquipmentHeader = -6, + kErrEquipment = -7 }; + + AliMDC(Int_t compress, Bool_t deleteFiles, + EFilterMode filterMode = kFilterTransparent, + const char* localRunDB = NULL, Bool_t rdbmsRunDB = kFALSE, + const char* alienHostRunDB = NULL, const char* alienDirRunDB = NULL, + Double_t maxSizeTagDB = -1, const char* fileNameTagDB = NULL); + virtual ~AliMDC(); + + Int_t Open(EWriteMode mode, const char* fileName); + Int_t ProcessEvent(void* event, Bool_t isIovecArray = kFALSE); + Int_t Close(); + + Int_t Run(const char* inputFile, Bool_t loop, + EWriteMode mode, Double_t maxFileSize, + const char* fs1 = NULL, const char* fs2 = NULL); + void Stop(); private: class AliMDCInterruptHandler : public TSignalHandler { @@ -67,7 +71,7 @@ private: AliMDCInterruptHandler(AliMDC *mdc) : TSignalHandler(kSigUser1, kFALSE), fMDC(mdc) { } Bool_t Notify() { Info("Notify", "received a SIGUSR1 signal"); - fMDC->SetStopLoop(); + fMDC->Stop(); return kTRUE; } private: @@ -77,50 +81,31 @@ private: AliMDCInterruptHandler& operator=(const AliMDCInterruptHandler& handler); }; - static AliMDC* fgInstance; // singleton instance - - Int_t fFd; // DATE input stream - Int_t fCompress; // compression factor used for raw output DB - Int_t fNumEvents; // number of events processed - Int_t fDebugLevel; // controls debug print-out - Double_t fMaxFileSize; // maximum size of raw output DB - EWriteMode fWriteMode; // write mode (local, rfio, rootd, castor, /dev/null) - Bool_t fUseFifo; // read from fifo, file otherwise - Bool_t fUseEb; // use event builder API instead of fifo - Bool_t fUseFilter; // use 3rd level trigger filter - Bool_t fUseLoop; // loop on input source (must be file) - Bool_t fStopLoop; // break from endless loop (triggered by SIGUSR1) - - static Bool_t fgDeleteFiles; // flag for deletion of files - - static const Double_t fgkMaxTagFileSize; // maximal size of tag DB - - // Fixed file system locations for the different DB's - static const char* const fgkFifo; // fifo - static const char* const fgkRawDBFS[2]; // raw DB - static const char* const fgkTagDBFS; // tag DB - static const char* const fgkRunDBFS; // run DB - static const char* const fgkRFIOFS; // rfio - static const char* const fgkCastorFS; // castor - static const char* const fgkRootdFS; // rootd - static const char* const fgkAlienHost; // alien host name - static const char* const fgkAlienDir; // alien directory + AliRawEvent *fEvent; // produced AliRawEvent + AliESD *fESD; // pointer to HLT ESD object + AliStats *fStats; // statistics + AliRawDB *fRawDB; // raw data DB + AliRunDB *fRunDB; // run DB + AliTagDB *fTagDB; // tag DB + Int_t fCompress; // compression factor used for raw output DB + Bool_t fDeleteFiles; // flag for deletion of files + EFilterMode fFilterMode; // high level filter mode + TObjArray fFilters; // filter algorithms + Bool_t fStop; // stop execution (triggered by SIGUSR1) + + // Filter names + enum {kNFilters = 1}; + static const char* const fgkFilterName[kNFilters]; AliMDC(const AliMDC& mdc); AliMDC& operator = (const AliMDC& mdc); Int_t Read(const char *name) { return TObject::Read(name); } - Int_t Read(void *buffer, Int_t length); - Int_t ReadHeader(AliRawEventHeader &header, void *eb = 0); + Int_t Read(Int_t fd, void *buffer, Int_t length); + Int_t ReadHeader(AliRawEventHeader &header, char*& data); Int_t ReadEquipmentHeader(AliRawEquipmentHeader &header, - Bool_t isSwapped, void *eb = 0); - Int_t ReadRawData(AliRawData &raw, Int_t size, void *eb = 0); - Int_t DumpEvent(Int_t toRead); - Int_t Filter( -#ifdef USE_HLT - AliRawEvent *event,AliESD *esd -#endif - ); + Bool_t isSwapped, char*& data); + Int_t ReadRawData(AliRawData &raw, Int_t size, char*& data); ClassDef(AliMDC,0) // MDC processor }; diff --git a/RAW/AliRawCastorDB.cxx b/RAW/AliRawCastorDB.cxx index 68715e1dc25..facc19884b2 100644 --- a/RAW/AliRawCastorDB.cxx +++ b/RAW/AliRawCastorDB.cxx @@ -25,8 +25,6 @@ #include #include -#include "AliMDC.h" - #include "AliRawCastorDB.h" @@ -35,19 +33,13 @@ ClassImp(AliRawCastorDB) //______________________________________________________________________________ AliRawCastorDB::AliRawCastorDB(AliRawEvent *event, -#ifdef USE_HLT AliESD *esd, -#endif - Double_t maxsize, Int_t compress) - : AliRawDB(event, -#ifdef USE_HLT - esd, -#endif - maxsize, compress, kFALSE) + Int_t compress, + const char* fileName) + : AliRawDB(event, esd, compress, fileName) { // Create a new raw DB that will be accessed via CASTOR and rootd. -#ifndef USE_RDM static int init = 0; // Set STAGE_POOL environment variable to current host if (!init) { @@ -64,12 +56,8 @@ AliRawCastorDB::AliRawCastorDB(AliRawEvent *event, Error("AliRawRFIODB", "STAGE_HOST not set"); init = 1; } -#endif - if (!Create()) - MakeZombie(); - else - fRawDB->UseCache(50, 0x200000); //0x100000 = 1MB) + if (fRawDB) fRawDB->UseCache(50, 0x200000); //0x100000 = 1MB) } //______________________________________________________________________________ @@ -82,8 +70,9 @@ const char *AliRawCastorDB::GetFileName() const static TString fname; - TString fs = AliMDC::CastorFS(); - TString fsr = AliMDC::RFIOFS(); + TString fs = fFS1; + TString fsr = fs; + fsr.ReplaceAll("castor:", "rfio:"); TDatime dt; // make a new subdirectory for each day @@ -98,8 +87,8 @@ const char *AliRawCastorDB::GetFileName() const // directory does not exist, create it if (gSystem->mkdir(fsr, kTRUE) == -1) { Error("GetFileName", "cannot create dir %s, using %s", fsr.Data(), - AliMDC::RFIOFS()); - fs = AliMDC::CastorFS(); + fFS1.Data()); + fs = fFS1; } } // FIXME: should check if fs is a directory @@ -129,11 +118,12 @@ void AliRawCastorDB::Close() // Write the tree. fTree->Write(); + if (fESDTree) fESDTree->Write(); // Close DB, this also deletes the fTree fRawDB->Close(); - if (AliMDC::DeleteFiles()) { + if (fDeleteFiles) { TUrl u(fRawDB->GetName()); gSystem->Exec(Form("rfrm %s", u.GetFile())); } diff --git a/RAW/AliRawCastorDB.h b/RAW/AliRawCastorDB.h index 8e53e8f84ef..88766bf6d19 100644 --- a/RAW/AliRawCastorDB.h +++ b/RAW/AliRawCastorDB.h @@ -19,10 +19,9 @@ class AliRawCastorDB : public AliRawDB { public: AliRawCastorDB(AliRawEvent *event, -#ifdef USE_HLT AliESD *esd, -#endif - Double_t maxsize, Int_t compress); + Int_t compress, + const char* fileName = NULL); ~AliRawCastorDB() { Close(); } const char *GetOpenOption() const { return "-RECREATE"; } diff --git a/RAW/AliRawDB.cxx b/RAW/AliRawDB.cxx index 1b991564ced..0fb765674a9 100644 --- a/RAW/AliRawDB.cxx +++ b/RAW/AliRawDB.cxx @@ -33,11 +33,6 @@ #include "AliRawEvent.h" #include "AliRawEventHeader.h" #include "AliStats.h" -#include "AliMDC.h" - -#ifdef USE_HLT -#include "AliESD.h" -#endif #include "AliRawDB.h" @@ -47,20 +42,22 @@ ClassImp(AliRawDB) //______________________________________________________________________________ AliRawDB::AliRawDB(AliRawEvent *event, -#ifdef USE_HLT AliESD *esd, -#endif - Double_t maxsize, Int_t compress, - Bool_t create) + Int_t compress, + const char* fileName) : + fRawDB(NULL), + fTree(NULL), + fEvent(event), + fESDTree(NULL), + fESD(esd), + fCompress(compress), + fMaxSize(-1), + fFS1(""), + fFS2(""), + fDeleteFiles(kFALSE), + fStop(kFALSE) { - // Create a new raw DB containing at most maxsize bytes. - - fEvent = event; -#ifdef USE_HLT - fESD = esd; -#endif - fMaxSize = maxsize; - fCompress = compress; + // Create a new raw DB // Consistency check with DATE header file #ifdef ALI_DATE @@ -71,8 +68,8 @@ AliRawDB::AliRawDB(AliRawEvent *event, } #endif - if (create) { - if (!Create()) + if (fileName) { + if (!Create(fileName)) MakeZombie(); } } @@ -127,7 +124,7 @@ const char *AliRawDB::GetFileName() const static TString fname; static Bool_t fstoggle = kFALSE; - TString fs = fstoggle ? AliMDC::RawDBFS(1) : AliMDC::RawDBFS(0); + TString fs = fstoggle ? fFS2 : fFS1; TDatime dt; TString hostname = gSystem->HostName(); @@ -138,12 +135,11 @@ const char *AliRawDB::GetFileName() const if (!FSHasSpace(fs)) { while (1) { fstoggle = !fstoggle; - fs = fstoggle ? AliMDC::RawDBFS(1) : AliMDC::RawDBFS(0); + fs = fstoggle ? fFS2 : fFS1; if (FSHasSpace(fs)) break; Info("GetFileName", "sleeping 30 seconds before retrying..."); gSystem->Sleep(30000); // sleep for 30 seconds - if (AliMDC::Instance() && AliMDC::Instance()->StopLoop()) - return 0; + if (fStop) return 0; } } @@ -159,7 +155,31 @@ const char *AliRawDB::GetFileName() const } //______________________________________________________________________________ -Bool_t AliRawDB::Create() +void AliRawDB::SetFS(const char* fs1, const char* fs2) +{ +// set the file system location + + fFS1 = fs1; + if (fs1 && !fFS1.Contains(":")) { + gSystem->ResetErrno(); + gSystem->MakeDirectory(fs1); + if (gSystem->GetErrno() && gSystem->GetErrno() != EEXIST) { + SysError("SetFS", "mkdir %s", fs1); + } + } + + fFS2 = fs2; + if (fs2) { + gSystem->ResetErrno(); + gSystem->MakeDirectory(fs2); + if (gSystem->GetErrno() && gSystem->GetErrno() != EEXIST) { + SysError("SetFS", "mkdir %s", fs2); + } + } +} + +//______________________________________________________________________________ +Bool_t AliRawDB::Create(const char* fileName) { // Create a new raw DB. @@ -169,10 +189,10 @@ Bool_t AliRawDB::Create() Int_t retry = 0; again: - if (AliMDC::Instance() && AliMDC::Instance()->StopLoop()) - return kFALSE; + if (fStop) return kFALSE; - const char *fname = GetFileName(); + const char *fname = fileName; + if (!fname) fname = GetFileName(); if (!fname) { Error("Create", "error getting raw DB file name"); return kFALSE; @@ -181,7 +201,7 @@ again: retry++; fRawDB = TFile::Open(fname, GetOpenOption(), - Form("ALICE MDC%d raw DB", AliMDC::kMDC), fCompress, + Form("ALICE MDC%d raw DB", kMDC), fCompress, GetNetopt()); if (!fRawDB) { if (retry < kMaxRetry) { @@ -232,7 +252,7 @@ void AliRawDB::MakeTree() { // Create ROOT Tree object container. - fTree = new TTree("RAW", Form("ALICE MDC%d raw data tree", AliMDC::kMDC)); + fTree = new TTree("RAW", Form("ALICE MDC%d raw data tree", kMDC)); fTree->SetAutoSave(2000000000); // autosave when 2 Gbyte written Int_t bufsize = 256000; @@ -241,14 +261,14 @@ void AliRawDB::MakeTree() Int_t split = 0; fTree->Branch("rawevent", "AliRawEvent", &fEvent, bufsize, split); -#ifdef USE_HLT // Create tree which will contain the HLT ESD information - fESDTree = new TTree("esdTree", Form("ALICE MDC%d HLT ESD tree", AliMDC::kMDC)); - fESDTree->SetAutoSave(2000000000); // autosave when 2 Gbyte written - split = 99; - fESDTree->Branch("ESD", "AliESD", &fESD, bufsize, split); -#endif + if (fESD) { + fESDTree = new TTree("esdTree", Form("ALICE MDC%d HLT ESD tree", kMDC)); + fESDTree->SetAutoSave(2000000000); // autosave when 2 Gbyte written + split = 99; + fESDTree->Branch("ESD", "AliESD", &fESD, bufsize, split); + } } @@ -263,14 +283,12 @@ void AliRawDB::Close() // Write the tree. fTree->Write(); -#ifdef USE_HLT - fESDTree->Write(); -#endif + if (fESDTree) fESDTree->Write(); // Close DB, this also deletes the fTree fRawDB->Close(); - if (AliMDC::DeleteFiles()) { + if (fDeleteFiles) { gSystem->Unlink(fRawDB->GetName()); delete fRawDB; fRawDB = 0; @@ -285,6 +303,17 @@ void AliRawDB::Close() fRawDB = 0; } +//______________________________________________________________________________ +Int_t AliRawDB::Fill() +{ + // Fill the trees and return the number of written bytes + + Double_t bytes = fRawDB->GetBytesWritten(); + fTree->Fill(); + if (fESDTree) fESDTree->Fill(); + return Int_t(fRawDB->GetBytesWritten() - bytes); +} + //______________________________________________________________________________ void AliRawDB::WriteStats(AliStats* stats) { @@ -305,14 +334,14 @@ void AliRawDB::WriteStats(AliStats* stats) } //______________________________________________________________________________ -Bool_t AliRawDB::NextFile() +Bool_t AliRawDB::NextFile(const char* fileName) { // Close te current file and open a new one. // Returns kFALSE in case opening failed. Close(); - if (!Create()) return kFALSE; + if (!Create(fileName)) return kFALSE; return kTRUE; } diff --git a/RAW/AliRawDB.h b/RAW/AliRawDB.h index 8ae6b53b0f8..d223f848f57 100644 --- a/RAW/AliRawDB.h +++ b/RAW/AliRawDB.h @@ -24,42 +24,39 @@ #include #endif +#ifndef ROOT_TString +#include +#endif + // Forward class declarations class AliRawEvent; class AliStats; class TFile; - -#ifdef USE_HLT class AliESD; -#endif class AliRawDB : public TObject { public: AliRawDB(AliRawEvent *event, -#ifdef USE_HLT AliESD *esd, -#endif - Double_t maxsize, Int_t compress, - Bool_t create = kTRUE); + Int_t compress, + const char* fileName = NULL); virtual ~AliRawDB() { Close(); } virtual const char *GetOpenOption() const { return "RECREATE"; } virtual Int_t GetNetopt() const { return 0; } - virtual Bool_t Create(); + virtual Bool_t Create(const char* fileName = NULL); virtual void Close(); - void Fill() { fTree->Fill(); -#ifdef USE_HLT - fESDTree->Fill(); -#endif - } - Bool_t FileFull() { return (fRawDB->GetBytesWritten() > fMaxSize) ? - kTRUE : kFALSE; } + Int_t Fill(); void WriteStats(AliStats* stats); - Bool_t NextFile(); + void SetMaxSize(Double_t maxSize) { fMaxSize = maxSize; } + void SetFS(const char* fs1, const char* fs2 = NULL); + void SetDeleteFiles(Bool_t deleteFiles = kTRUE) { fDeleteFiles = deleteFiles; } + + Bool_t NextFile(const char* fileName = NULL); Double_t GetBytesWritten() const { return fRawDB->GetBytesWritten(); } TFile *GetDB() const { return fRawDB; } @@ -68,17 +65,22 @@ public: AliRawEvent *GetEvent() const { return fEvent; } Float_t GetCompressionFactor() const; Int_t GetCompressionMode() const { return fRawDB->GetCompressionLevel(); } + void Stop() { fStop = kTRUE; } + + enum {kMDC = 6}; // Which MDC is this... protected: TFile *fRawDB; // DB to store raw data TTree *fTree; // tree used to store raw data AliRawEvent *fEvent; // AliRawEvent via which data is stored -#ifdef USE_HLT TTree *fESDTree; // tree for storing HLT ESD information AliESD *fESD; // pointer to HLT ESD object -#endif Int_t fCompress; // compression mode (1 default) Double_t fMaxSize; // maximum size in bytes of the raw DB + TString fFS1; // first raw DB file system location + TString fFS2; // second raw DB file system location + Bool_t fDeleteFiles; // flag for deletion of files + Bool_t fStop; // stop execution (triggered by SIGUSR1) virtual const char *GetFileName() const; virtual Bool_t FSHasSpace(const char *fs) const; diff --git a/RAW/AliRawNullDB.cxx b/RAW/AliRawNullDB.cxx index 25c65efa3f2..7455f9d8421 100644 --- a/RAW/AliRawNullDB.cxx +++ b/RAW/AliRawNullDB.cxx @@ -30,20 +30,13 @@ ClassImp(AliRawNullDB) //______________________________________________________________________________ AliRawNullDB::AliRawNullDB(AliRawEvent *event, -#ifdef USE_HLT AliESD *esd, -#endif - Double_t maxsize, Int_t compress) - : AliRawDB(event, -#ifdef USE_HLT - esd, -#endif - maxsize, compress, kFALSE) + Int_t compress, + const char* fileName) + : AliRawDB(event, esd, compress, fileName) { // Create a new raw DB that will wrtie to /dev/null. - if (!Create()) - MakeZombie(); } //______________________________________________________________________________ @@ -65,6 +58,7 @@ void AliRawNullDB::Close() // Write the tree. fTree->Write(); + if (fESDTree) fESDTree->Write(); // Close DB, this also deletes the fTree fRawDB->Close(); diff --git a/RAW/AliRawNullDB.h b/RAW/AliRawNullDB.h index 83d4fcbdb83..4f462adafd1 100644 --- a/RAW/AliRawNullDB.h +++ b/RAW/AliRawNullDB.h @@ -19,10 +19,9 @@ class AliRawNullDB : public AliRawDB { public: AliRawNullDB(AliRawEvent *event, -#ifdef USE_HLT AliESD *esd, -#endif - Double_t maxsize, Int_t compress); + Int_t compress, + const char* fileName); ~AliRawNullDB() { Close(); } void Close(); diff --git a/RAW/AliRawRFIODB.cxx b/RAW/AliRawRFIODB.cxx index a6b15b04cca..899eb3346f6 100644 --- a/RAW/AliRawRFIODB.cxx +++ b/RAW/AliRawRFIODB.cxx @@ -25,8 +25,6 @@ #include #include -#include "AliMDC.h" - #include "AliRawRFIODB.h" @@ -35,19 +33,13 @@ ClassImp(AliRawRFIODB) //______________________________________________________________________________ AliRawRFIODB::AliRawRFIODB(AliRawEvent *event, -#ifdef USE_HLT AliESD *esd, -#endif - Double_t maxsize, Int_t compress) - : AliRawDB(event, -#ifdef USE_HLT - esd, -#endif - maxsize, compress, kFALSE) + Int_t compress, + const char* fileName) + : AliRawDB(event, esd, compress, fileName) { // Create a new raw DB that will be accessed via RFIO. -#ifndef USE_RDM static int init = 0; // Set STAGE_POOL environment variable to current host if (!init) { @@ -64,12 +56,8 @@ AliRawRFIODB::AliRawRFIODB(AliRawEvent *event, Error("AliRawRFIODB", "STAGE_HOST not set"); init = 1; } -#endif - if (!Create()) - MakeZombie(); - else - fRawDB->UseCache(50, 0x200000); //0x100000 = 1MB) + if (fRawDB) fRawDB->UseCache(50, 0x200000); //0x100000 = 1MB) } //______________________________________________________________________________ @@ -82,7 +70,7 @@ const char *AliRawRFIODB::GetFileName() const static TString fname; - TString fs = AliMDC::RFIOFS(); + TString fs = fFS1; TDatime dt; // make a new subdirectory for each day @@ -94,8 +82,8 @@ const char *AliRawRFIODB::GetFileName() const // directory does not exist, create it if (gSystem->mkdir(fs, kTRUE) == -1) { Error("GetFileName", "cannot create dir %s, using %s", fs.Data(), - AliMDC::RFIOFS()); - fs = AliMDC::RFIOFS(); + fFS1.Data()); + fs = fFS1; } } // FIXME: should check if fs is a directory @@ -125,11 +113,12 @@ void AliRawRFIODB::Close() // Write the tree. fTree->Write(); + if (fESDTree) fESDTree->Write(); // Close DB, this also deletes the fTree fRawDB->Close(); - if (AliMDC::DeleteFiles()) { + if (fDeleteFiles) { TUrl u(fRawDB->GetName()); gSystem->Exec(Form("rfrm %s", u.GetFile())); } diff --git a/RAW/AliRawRFIODB.h b/RAW/AliRawRFIODB.h index 1f6ca3f0ac3..529cfe177c8 100644 --- a/RAW/AliRawRFIODB.h +++ b/RAW/AliRawRFIODB.h @@ -19,10 +19,9 @@ class AliRawRFIODB : public AliRawDB { public: AliRawRFIODB(AliRawEvent *event, -#ifdef USE_HLT AliESD *esd, -#endif - Double_t maxsize, Int_t compress); + Int_t compress, + const char* fileName = NULL); ~AliRawRFIODB() { Close(); } void Close(); diff --git a/RAW/AliRawRootdDB.cxx b/RAW/AliRawRootdDB.cxx index 58af4b90a8d..1de0c9a30bd 100644 --- a/RAW/AliRawRootdDB.cxx +++ b/RAW/AliRawRootdDB.cxx @@ -24,8 +24,6 @@ #include -#include "AliMDC.h" - #include "AliRawRootdDB.h" @@ -34,22 +32,14 @@ ClassImp(AliRawRootdDB) //______________________________________________________________________________ AliRawRootdDB::AliRawRootdDB(AliRawEvent *event, -#ifdef USE_HLT AliESD *esd, -#endif - Double_t maxsize, Int_t compress) - : AliRawDB(event, -#ifdef USE_HLT - esd, -#endif - maxsize, compress, kFALSE) + Int_t compress, + const char* fileName) + : AliRawDB(event, esd, compress, fileName) { // Create a new raw DB that will be accessed via rootd daemon. - if (!Create()) - MakeZombie(); - else - fRawDB->UseCache(50, 0x200000); //0x100000 = 1MB) + if (fRawDB) fRawDB->UseCache(50, 0x200000); //0x100000 = 1MB) } //______________________________________________________________________________ @@ -62,7 +52,7 @@ const char *AliRawRootdDB::GetFileName() const static TString fname; - TString fs = AliMDC::RootdFS(); + TString fs = fFS1; TDatime dt; #if 0 @@ -75,8 +65,8 @@ const char *AliRawRootdDB::GetFileName() const // directory does not exist, create it if (gSystem->mkdir(fs, kTRUE) == -1) { Error("GetFileName", "cannot create dir %s, using %s", fs.Data(), - AliMDC::RootdFS()); - fs = AliMDC::RootdFS(); + fFS1.Data()); + fs = fFS1; } } // FIXME: should check if fs is a directory @@ -107,13 +97,14 @@ void AliRawRootdDB::Close() // Write the tree. fTree->Write(); + if (fESDTree) fESDTree->Write(); // Close DB, this also deletes the fTree fRawDB->Close(); #if 0 // can use services of TFTP - if (AliMDC::DeleteFiles()) + if (fDeleteFiles) gSystem->Exec(Form("rfrm %s", fRawDB->GetName())); #endif diff --git a/RAW/AliRawRootdDB.h b/RAW/AliRawRootdDB.h index 67dea9735c0..d226c4bb890 100644 --- a/RAW/AliRawRootdDB.h +++ b/RAW/AliRawRootdDB.h @@ -19,10 +19,9 @@ class AliRawRootdDB : public AliRawDB { public: AliRawRootdDB(AliRawEvent *event, -#ifdef USE_HLT AliESD *esd, -#endif - Double_t maxsize, Int_t compress); + Int_t compress, + const char* fileName = NULL); ~AliRawRootdDB() { Close(); } void Close(); diff --git a/RAW/AliRunDB.cxx b/RAW/AliRunDB.cxx index 450c16ac861..1e4d60a9ac5 100644 --- a/RAW/AliRunDB.cxx +++ b/RAW/AliRunDB.cxx @@ -31,7 +31,7 @@ #include #include "AliStats.h" -#include "AliMDC.h" +#include "AliRawDB.h" #include "AliRunDB.h" @@ -40,20 +40,22 @@ ClassImp(AliRunDB) //______________________________________________________________________________ -AliRunDB::AliRunDB(Bool_t noLocalDB) +AliRunDB::AliRunDB(const char* localFS, Bool_t rdbms, + const char* alienHost, const char* alienDir) : + fRunDB(NULL), + fRDBMS(rdbms), + fAlienHost(alienHost), + fAlienDir(alienDir) { // Open run database, and get or create tree. - fRunDB = 0; - - if (noLocalDB) return; + if (!localFS) return; // Get hostname char hostname[64], filename[64]; - const char *fs = AliMDC::RunDBFS(); // check that fs exists (crude check fails if fs is a file) - gSystem->MakeDirectory(fs); + gSystem->MakeDirectory(localFS); strcpy(hostname, gSystem->HostName()); @@ -61,12 +63,12 @@ AliRunDB::AliRunDB(Bool_t noLocalDB) if ((s = strchr(hostname, '.'))) *s = 0; - sprintf(filename, "%s/%s_rundb.root", fs, hostname); + sprintf(filename, "%s/%s_rundb.root", localFS, hostname); if (!gSystem->AccessPathName(filename, kFileExists)) fRunDB = new TFile(filename, "UPDATE"); else - fRunDB = new TFile(filename, "CREATE", Form("ALICE MDC%d Run DB", AliMDC::kMDC)); + fRunDB = new TFile(filename, "CREATE", Form("ALICE MDC%d Run DB", AliRawDB::kMDC)); } //______________________________________________________________________________ @@ -88,6 +90,14 @@ AliRunDB& AliRunDB::operator = (const AliRunDB& /*runDB*/) //______________________________________________________________________________ void AliRunDB::Update(AliStats *stats) +{ + UpdateLocal(stats); + UpdateRDBMS(stats); + UpdateAliEn(stats); +} + +//______________________________________________________________________________ +void AliRunDB::UpdateLocal(AliStats *stats) { // Add stats object to database. @@ -116,7 +126,7 @@ void AliRunDB::UpdateRDBMS(AliStats *stats) { // Add stats object to central MySQL DB. - if (!stats) return; + if (!stats || !fRDBMS) return; char sql[4096]; char bt[25], et[25]; @@ -125,7 +135,7 @@ void AliRunDB::UpdateRDBMS(AliStats *stats) strcpy(et, stats->GetEndTime().AsSQLString()); sprintf(sql, "INSERT INTO mdc%dcatalog VALUES (0, '%s', %d, " - "%d, %d, %d, %d, %d, %d, %.2f, '%s', '%s', '%s')", AliMDC::kMDC, + "%d, %d, %d, %d, %d, %d, %.2f, '%s', '%s', '%s')", AliRawDB::kMDC, stats->GetFileName(), (int)stats->GetFileSize(), stats->GetEvents(), stats->GetFirstRun(), stats->GetFirstEvent(), stats->GetLastRun(), stats->GetLastEvent(), stats->GetCompressionMode(), @@ -145,7 +155,7 @@ void AliRunDB::UpdateRDBMS(AliStats *stats) TSQLResult *res = db->Query(sql); if (!res) { - Error("UpdateRDBMS", Form("insert into mdc%dcatalog failed", AliMDC::kMDC)); + Error("UpdateRDBMS", Form("insert into mdc%dcatalog failed", AliRawDB::kMDC)); printf("%s\n", sql); } @@ -158,11 +168,11 @@ void AliRunDB::UpdateAliEn(AliStats *stats) { // Record file in AliEn catalog. - if (!stats) return; + if (!stats || fAlienHost.IsNull()) return; - TGrid *g = TGrid::Connect(AliMDC::AlienHost(), ""); + TGrid *g = TGrid::Connect(fAlienHost, ""); - TString lfn = AliMDC::AlienDir(); + TString lfn = fAlienDir; TDatime dt; // make a subdirectory for each day @@ -175,7 +185,7 @@ void AliRunDB::UpdateAliEn(AliStats *stats) // directory does not exist, create it if (g->Mkdir(lfn) == -1) { Error("UpdateAliEn", "cannot create directory %s", lfn.Data()); - lfn = AliMDC::AlienDir(); + lfn = fAlienDir; } } if (res) g->CloseResult(res); @@ -204,14 +214,3 @@ void AliRunDB::Close() delete fRunDB; } - -//______________________________________________________________________________ -void AliRunDB::WriteStats(AliStats* stats) -{ - // Write stats also in the bookkeeping RunDB - AliRunDB *rundb = new AliRunDB(kTRUE); - rundb->Update(stats); - rundb->UpdateRDBMS(stats); - rundb->UpdateAliEn(stats); - delete rundb; -} diff --git a/RAW/AliRunDB.h b/RAW/AliRunDB.h index 74faac74447..a30c24ba5fe 100644 --- a/RAW/AliRunDB.h +++ b/RAW/AliRunDB.h @@ -16,6 +16,10 @@ #include #endif +#ifndef ROOT_TString +#include +#endif + // Forward class declarations class AliStats; @@ -25,18 +29,21 @@ class TFile; class AliRunDB : public TObject { public: - AliRunDB(Bool_t noLocalDB = kFALSE); + AliRunDB(const char* localFS, Bool_t rdbms = kFALSE, + const char* alienHost = NULL, const char* alienDir = NULL); ~AliRunDB() { Close(); } void Update(AliStats *stats); + void UpdateLocal(AliStats *stats); void UpdateRDBMS(AliStats *stats); void UpdateAliEn(AliStats *stats); void Close(); - static void WriteStats(AliStats* stats); - private: TFile *fRunDB; // run database + Bool_t fRDBMS; // flag for usage of central MySQL DB + TString fAlienHost; // alien host name + TString fAlienDir; // alien directory AliRunDB(const AliRunDB& runDB); AliRunDB& operator = (const AliRunDB& runDB); diff --git a/RAW/AliStats.cxx b/RAW/AliStats.cxx index d89a49e86a8..453643f70fa 100644 --- a/RAW/AliStats.cxx +++ b/RAW/AliStats.cxx @@ -27,8 +27,6 @@ #include "AliRawEvent.h" #include "AliRawEventHeader.h" -#include "AliRawDB.h" -#include "AliRunDB.h" #include "AliStats.h" diff --git a/RAW/AliTagDB.cxx b/RAW/AliTagDB.cxx index 84f178cdfe6..67bdba80212 100644 --- a/RAW/AliTagDB.cxx +++ b/RAW/AliTagDB.cxx @@ -22,9 +22,11 @@ // // ////////////////////////////////////////////////////////////////////////// +#include + #include -#include "AliMDC.h" +#include "AliRawDB.h" #include "AliTagDB.h" @@ -33,15 +35,18 @@ ClassImp(AliTagDB) //______________________________________________________________________________ -AliTagDB::AliTagDB(AliRawEventHeader *header, Double_t maxsize, Bool_t create) +AliTagDB::AliTagDB(AliRawEventHeader *header, const char* fileName) : + fTagDB(NULL), + fTree(NULL), + fHeader(header), + fMaxSize(-1), + fFS(""), + fDeleteFiles(kFALSE) { // Create tag DB. - fHeader = header; - fMaxSize = maxsize; - - if (create) { - if (!Create()) + if (fileName) { + if (!Create(fileName)) MakeZombie(); } } @@ -64,12 +69,14 @@ AliTagDB& AliTagDB::operator = (const AliTagDB& /*tagDB*/) } //______________________________________________________________________________ -Bool_t AliTagDB::Create() +Bool_t AliTagDB::Create(const char* fileName) { // Create a new tag DB. - fTagDB = new TFile(GetFileName(), "RECREATE", - Form("ALICE MDC%d tag DB", AliMDC::kMDC), 1); + const char *name = fileName; + if (!name) name = GetFileName(); + fTagDB = new TFile(name, "RECREATE", + Form("ALICE MDC%d tag DB", AliRawDB::kMDC), 1); if (fTagDB->IsZombie()) { Error("Create", "error opening tag DB"); fTagDB = 0; @@ -77,7 +84,7 @@ Bool_t AliTagDB::Create() } // Create ROOT Tree object container - fTree = new TTree("TAG", Form("ALICE MDC%d header data tree", AliMDC::kMDC)); + fTree = new TTree("TAG", Form("ALICE MDC%d header data tree", AliRawDB::kMDC)); fTree->SetAutoSave(100000000); // autosave when 100 Mbyte written Int_t bufsize = 32000; @@ -102,7 +109,7 @@ void AliTagDB::Close() // Close DB, this also deletes the fTree fTagDB->Close(); - if (AliMDC::DeleteFiles()) + if (fDeleteFiles) gSystem->Unlink(fTagDB->GetName()); delete fTagDB; @@ -110,17 +117,32 @@ void AliTagDB::Close() } //______________________________________________________________________________ -Bool_t AliTagDB::NextFile() +Bool_t AliTagDB::NextFile(const char* fileName) { // Close te current file and open a new one. // Returns kFALSE in case opening failed. Close(); - if (!Create()) return kFALSE; + if (!Create(fileName)) return kFALSE; return kTRUE; } +//______________________________________________________________________________ +void AliTagDB::SetFS(const char* fs) +{ +// set the file system location + + fFS = fs; + if (fs) { + gSystem->ResetErrno(); + gSystem->MakeDirectory(fs); + if (gSystem->GetErrno() && gSystem->GetErrno() != EEXIST) { + SysError("SetFS", "mkdir %s", fs); + } + } +} + //______________________________________________________________________________ Float_t AliTagDB::GetCompressionFactor() const { @@ -139,7 +161,7 @@ const char *AliTagDB::GetFileName() const // each file unique. The tags will be stored in the /data1/tags directory. static char fname[64]; - const char *fs = AliMDC::TagDBFS(); + const char *fs = fFS; // check that fs exists (crude check fails if fs is a file) gSystem->MakeDirectory(fs); diff --git a/RAW/AliTagDB.h b/RAW/AliTagDB.h index 64a8336879e..adf83213408 100644 --- a/RAW/AliTagDB.h +++ b/RAW/AliTagDB.h @@ -24,6 +24,11 @@ #include #endif +#ifndef ROOT_TString +#include +#endif + + // Forward class declarations class AliRawEventHeader; @@ -32,16 +37,19 @@ class AliRawEventHeader; class AliTagDB : public TObject { public: - AliTagDB(AliRawEventHeader *header, Double_t maxsize, Bool_t create = kTRUE); + AliTagDB(AliRawEventHeader *header, const char* fileName = NULL); virtual ~AliTagDB() { Close(); } - Bool_t Create(); + Bool_t Create(const char* fileName = NULL); virtual void Close(); void Fill() { fTree->Fill(); } Bool_t FileFull() - { return (fTagDB->GetBytesWritten() > fMaxSize) ? kTRUE : kFALSE; } + { return (fMaxSize >= 0) ? ((fTagDB->GetBytesWritten() > fMaxSize) ? kTRUE : kFALSE) : kFALSE; } + + Bool_t NextFile(const char* fileName = NULL); - Bool_t NextFile(); + void SetMaxSize(Double_t maxSize) { fMaxSize = maxSize; } + void SetFS(const char* fs); Double_t GetBytesWritten() const { return fTagDB->GetBytesWritten(); } TFile *GetDB() const { return fTagDB; } @@ -55,6 +63,8 @@ protected: TTree *fTree; // tree use to store header AliRawEventHeader *fHeader; // header via which data is stored Double_t fMaxSize; // maximum size in bytes of tag DB + TString fFS; // tag DB file system location + Bool_t fDeleteFiles; // flag for deletion of files virtual const char *GetFileName() const; diff --git a/RAW/AliTagNullDB.cxx b/RAW/AliTagNullDB.cxx index e65c8f8c881..4d5849888d0 100644 --- a/RAW/AliTagNullDB.cxx +++ b/RAW/AliTagNullDB.cxx @@ -29,13 +29,11 @@ ClassImp(AliTagNullDB) //______________________________________________________________________________ -AliTagNullDB::AliTagNullDB(AliRawEventHeader *header, Double_t maxsize) : - AliTagDB(header, maxsize, kFALSE) +AliTagNullDB::AliTagNullDB(AliRawEventHeader *header) : + AliTagDB(header, "/dev/null") { // Create tag db writing to /dev/null. - if (!Create()) - MakeZombie(); } //______________________________________________________________________________ diff --git a/RAW/AliTagNullDB.h b/RAW/AliTagNullDB.h index ec3947a63d3..53e609b3f28 100644 --- a/RAW/AliTagNullDB.h +++ b/RAW/AliTagNullDB.h @@ -18,7 +18,7 @@ class AliTagNullDB : public AliTagDB { public: - AliTagNullDB(AliRawEventHeader *header, Double_t maxsize); + AliTagNullDB(AliRawEventHeader *header); ~AliTagNullDB() { Close(); } void Close(); diff --git a/RAW/RAWLinkDef.h b/RAW/RAWLinkDef.h index 1a458e7c079..84cc5858b9e 100644 --- a/RAW/RAWLinkDef.h +++ b/RAW/RAWLinkDef.h @@ -10,6 +10,7 @@ #pragma link C++ class AliRawEquipment; #pragma link C++ class AliRawData; #pragma link C++ class AliStats; +#pragma link C++ class AliFilter; #pragma link C++ class AliRawReader+; #pragma link C++ class AliRawReaderFile+; #pragma link C++ class AliRawReaderRoot+; diff --git a/RAW/alimdcLinkDef.h b/RAW/alimdcLinkDef.h new file mode 100644 index 00000000000..7237fd7d4a7 --- /dev/null +++ b/RAW/alimdcLinkDef.h @@ -0,0 +1,9 @@ +#ifdef __CINT__ + +#pragma link off all globals; +#pragma link off all classes; +#pragma link off all functions; + +#pragma link C++ class AliHoughFilter; + +#endif diff --git a/RAW/alimdc_main.cxx b/RAW/alimdc_main.cxx index b7be3915511..44f41e810eb 100644 --- a/RAW/alimdc_main.cxx +++ b/RAW/alimdc_main.cxx @@ -23,6 +23,8 @@ #include #include +#include + #ifdef USE_SMI extern "C" { #include @@ -105,26 +107,25 @@ static void SMI_handle_command() static void Usage(const char *prognam) { #ifdef USE_SMI - fprintf(stderr, "Usage: %s [date_file]\n", + fprintf(stderr, "Usage: %s [date_file]\n", prognam); fprintf(stderr, " = name used by SMI\n"); #else - fprintf(stderr, "Usage: %s [date_file]\n", + fprintf(stderr, "Usage: %s [date_file]\n", prognam); #endif fprintf(stderr, " = maximum raw DB size (in bytes)\n"); fprintf(stderr, " (precede by - to delete raw and tag databases on close)\n"); - fprintf(stderr, " = state of 3rd level filter (0 or 1)\n"); + fprintf(stderr, " = maximum tag DB size (in bytes, 0 for no tag DB)\n"); + fprintf(stderr, " (precede by - to switch off the run DB)\n"); + fprintf(stderr, " (precede by + to fill only the local run DB)\n"); + fprintf(stderr, " = state of 3rd level filter (0: off, 1: transparent, 2: on)\n"); fprintf(stderr, " = compression level (see TFile)\n"); fprintf(stderr, " (precede by - to use RFIO, -0 is RFIO and 0 compression)\n"); fprintf(stderr, " (precede by + to use rootd, +0 is rootd and 0 compression)\n"); fprintf(stderr, " (precede by %% to use Castor/rootd, %%0 is Castor/rootd and 0 compression)\n"); fprintf(stderr, " (precede by @ to use /dev/null as sink)\n"); -#ifdef USE_EB fprintf(stderr, " [date_file] = optional input file (default reads from DATE EventBuffer)\n"); -#else - fprintf(stderr, " [date_file] = optional input file (default reads from pipe /tmp/alimdc.fifo)\n"); -#endif fprintf(stderr, " (precede with - for endless loop on same file (use SIGUSR1 to stop)\n"); } @@ -137,97 +138,161 @@ int main(int argc, char **argv) gROOT->SetBatch(); // Set custom error handler + AliLog::SetHandleRootMessages(kFALSE); SetErrorHandler(AliMDCErrorHandler); -#ifdef USE_SMI - // Handle command line arguments + // Default file system locations +#ifdef USE_EB + const char* rawDBFS[2] = { "/data1/mdc", "/data2/mdc" }; + const char* tagDBFS = "/data1/mdc/tags"; + const char* runDBFS = "/data1/mdc/meta"; + const char* rfioFS = "rfio:/castor/cern.ch/lcg/dc5"; + const char* castorFS = "castor:/castor/cern.ch/lcg/dc5"; +#else + const char* rawDBFS[2] = { "/tmp/mdc1", "/tmp/mdc2" }; + const char* tagDBFS = "/tmp/mdc1/tags"; + const char* runDBFS = "/tmp/mdc1/meta"; + TString user(gSystem->Getenv("USER")[0] + TString("/") + + gSystem->Getenv("USER")); + TString rfioStr("rfio:/castor/cern.ch/user/" + user); + const char* rfioFS = rfioStr.Data(); + TString castorStr("castor:/castor/cern.ch/user/" + user); + const char* castorFS = castorStr.Data(); +#endif + const char* rootdFS = "root://localhost//tmp/mdc1"; + const char* alienHost = "alien://aliens7.cern.ch:15000/?direct"; + const char* alienDir = "/alice_mdc/DC"; + + // User defined file system locations + if (gSystem->Getenv("ALIMDC_RAWDB1")) + rawDBFS[0] = gSystem->Getenv("ALIMDC_RAWDB1"); + if (gSystem->Getenv("ALIMDC_RAWDB2")) + rawDBFS[1] = gSystem->Getenv("ALIMDC_RAWDB2"); + if (gSystem->Getenv("ALIMDC_TAGDB")) + tagDBFS = gSystem->Getenv("ALIMDC_TAGDB"); + if (gSystem->Getenv("ALIMDC_RUNDB")) + runDBFS = gSystem->Getenv("ALIMDC_RUNDB"); + if (gSystem->Getenv("ALIMDC_RFIO")) + rfioFS = gSystem->Getenv("ALIMDC_RFIO"); + if (gSystem->Getenv("ALIMDC_CASTOR")) + castorFS = gSystem->Getenv("ALIMDC_CASTOR"); + if (gSystem->Getenv("ALIMDC_ROOTD")) + rootdFS = gSystem->Getenv("ALIMDC_ROOTD"); + if (gSystem->Getenv("ALIMDC_ALIENHOST")) + alienHost = gSystem->Getenv("ALIMDC_ALIENHOST"); + if (gSystem->Getenv("ALIMDC_ALIENDIR")) + alienDir = gSystem->Getenv("ALIMDC_ALIENDIR"); + + // Handle command line arguments if ((argc == 2 && (!strcmp(argv[1], "-?") || !strcmp(argv[1], "-help"))) || +#ifdef USE_SMI + argc > 7 || argc < 6) { +#else argc > 6 || argc < 5) { +#endif Usage(argv[0]); return 1; } + Int_t iarg = 1; +#ifdef USE_SMI char smiobj[128]; - strcpy(smiobj, argv[1]); + strcpy(smiobj, argv[iarg]); smi_attach(smiobj, SMI_handle_command); smi_volatile(); smi_set_state("RUNNING"); - - for (int i = 1; i < argc-1; i++) - argv[i] = argv[i+1]; - argc--; - -#else - // Handle command line arguments - if ((argc == 2 && (!strcmp(argv[1], "-?") || !strcmp(argv[1], "-help"))) || - argc > 5 || argc < 4) { - Usage(argv[0]); - return 1; - } + iarg++; #endif AliMDC::EWriteMode wmode = AliMDC::kLOCAL; - Bool_t useFilter = kFALSE, useLoop = kFALSE; + Int_t filterMode = 0; + Bool_t useLoop = kFALSE; Bool_t delFiles = kFALSE; - Int_t fd = -1, compress; + Bool_t rdbmsRunDB = kTRUE; + Int_t compress; Double_t maxFileSize; + Double_t maxTagSize; + const char* fs1 = NULL; + const char* fs2 = NULL; // no special arg checking so don't make errors - if (argv[1][0] == '-') { + if (argv[iarg][0] == '-') { delFiles = kTRUE; - maxFileSize = atoi(argv[1]+1); + maxFileSize = atoi(argv[iarg]+1); } else - maxFileSize = atoi(argv[1]); + maxFileSize = atoi(argv[iarg]); if (maxFileSize < 1000 || maxFileSize > 2.e9) { Error(argv[0], "unreasonable file size %f\n", maxFileSize); return 1; } + iarg++; + + if (argv[iarg][0] == '-') { + runDBFS = NULL; + rdbmsRunDB = kFALSE; + alienHost = alienDir = NULL; + maxTagSize = atoi(argv[iarg]+1); + } else if (argv[iarg][0] == '+') { + rdbmsRunDB = kFALSE; + alienHost = alienDir = NULL; + maxTagSize = atoi(argv[iarg]+1); + } else + maxTagSize = atoi(argv[iarg]); + if (maxTagSize > 0 && (maxTagSize < 1000 || maxTagSize > 2.e9)) { + Error(argv[0], "unreasonable tag file size %f\n", maxTagSize); + return 1; + } + if (maxTagSize == 0) tagDBFS = NULL; + iarg++; - int filter = atoi(argv[2]); - if (filter != 0) - useFilter = kTRUE; + filterMode = atoi(argv[iarg]); + if (filterMode < 0 || filterMode > 2) { + Error(argv[0], "unreasonable filter mode %d\n", filterMode); + return 1; + } + iarg++; - if (argv[3][0] == '-') { + if (argv[iarg][0] == '-') { wmode = AliMDC::kRFIO; - compress = atoi(argv[3]+1); - } else if (argv[3][0] == '+') { + compress = atoi(argv[iarg]+1); + fs1 = rfioFS; + } else if (argv[iarg][0] == '+') { wmode = AliMDC::kROOTD; - compress = atoi(argv[3]+1); - } else if (argv[3][0] == '%') { + compress = atoi(argv[iarg]+1); + fs1 = rootdFS; + } else if (argv[iarg][0] == '%') { wmode = AliMDC::kCASTOR; - compress = atoi(argv[3]+1); - } else if (argv[3][0] == '@') { + compress = atoi(argv[iarg]+1); + fs1 = castorFS; + } else if (argv[iarg][0] == '@') { wmode = AliMDC::kDEVNULL; - compress = atoi(argv[3]+1); - } else - compress = atoi(argv[3]); + compress = atoi(argv[iarg]+1); + } else { + compress = atoi(argv[iarg]); + fs1 = rawDBFS[0]; + fs2 = rawDBFS[1]; + } if (compress > 9) { Error(argv[0], "unreasonable compression mode %d\n", compress); return 1; } + iarg++; - if (argc == 5) { - char *file = argv[4]; - if (argv[4][0] == '-') { + char* file = NULL; + if (iarg < argc) { + file = argv[iarg]; + if (argv[iarg][0] == '-') { useLoop = kTRUE; - file = argv[4]+1; - } - if ((fd = open(file, O_RDONLY)) == -1) { - Error(argv[0], "cannot open input file %s", argv[4]); - return 1; + file = argv[iarg]+1; } } // Create MDC processor object and process input stream - AliMDC mdcproc(fd, compress, maxFileSize, useFilter, wmode, useLoop, delFiles); - -#ifdef USE_DEBUG - mdcproc.SetDebugLevel(3); -#endif - - Int_t result = 0; + AliMDC mdcproc(compress, delFiles, AliMDC::EFilterMode(filterMode), + runDBFS, rdbmsRunDB, alienHost, alienDir, + maxTagSize, tagDBFS); - result = mdcproc.Run(); + Int_t result = mdcproc.Run(file, useLoop, wmode, maxFileSize, fs1, fs2); if (result == 0) Info(argv[0], "normal termination of run"); diff --git a/RAW/binalimdc.pkg b/RAW/binalimdc.pkg index ffece3b66ad..a8b5305a635 100644 --- a/RAW/binalimdc.pkg +++ b/RAW/binalimdc.pkg @@ -7,22 +7,20 @@ PACKCXXFLAGS := ${HLTCXXFLAGS} PACKCFLAGS := ${HLTCLFAGS} PACKDCXXFLAGS:= ${HLTDCXXFLAGS} -ESRCS:= AliMDC.cxx AliRawDB.cxx \ - AliRawRFIODB.cxx AliRawCastorDB.cxx AliRawRootdDB.cxx \ - AliRawNullDB.cxx AliTagDB.cxx AliTagNullDB.cxx \ - AliRunDB.cxx +ESRCS:= AliHoughFilter.cxx SRCS:= alimdc_main.cxx ${ESRCS} HDRS:= $(ESRCS:.cxx=.h) -DHDR:=MDCLinkDef.h +DHDR:=alimdcLinkDef.h + +#EDEFINE+= -DUSE_EB EINCLUDE+=TPC CONTAINERS ITS RAW HLT/src HLT/hough HLT/comp -EDEFINE+= -DUSE_RDM -DUSE_HLT # -DUSE_DEBUG for alimdc debug printout -ELIBS:=ESD STEER RAW TPCbase TPCsim TPCrec CONTAINERS AliL3Src AliL3Misc AliL3Hough AliL3Comp pythia6 pdf microcern +ELIBS:=ESD RAW MDC STEER TPCbase TPCsim TPCrec CONTAINERS AliL3Src AliL3Misc AliL3Hough AliL3Comp pythia6 pdf microcern ifdef DATE_ROOT diff --git a/RAW/libMDC.pkg b/RAW/libMDC.pkg new file mode 100644 index 00000000000..0f7590927f7 --- /dev/null +++ b/RAW/libMDC.pkg @@ -0,0 +1,27 @@ +#-*- Mode: Makefile -*- + +include HLT/hlt.conf + +EDEFINE := ${HLTDEFS} +PACKCXXFLAGS := ${HLTCXXFLAGS} +PACKCFLAGS := ${HLTCLFAGS} +PACKDCXXFLAGS:= ${HLTDCXXFLAGS} + +SRCS:= AliMDC.cxx AliRawDB.cxx \ + AliRawRFIODB.cxx AliRawCastorDB.cxx AliRawRootdDB.cxx \ + AliRawNullDB.cxx AliTagDB.cxx AliTagNullDB.cxx \ + AliRunDB.cxx mdc.cxx + +HDRS:= $(SRCS:.cxx=.h) + +EHDRS:=$(shell root-config --incdir)/TH1F.h + +#EDEFINE+= -DUSE_EB + +EINCLUDE+=HLT/src HLT/hough HLT/comp + +DHDR:= MDCLinkDef.h + +ifdef DATE_ROOT +EINCLUDE+= ${DATE_COMMON_DEFS} +endif diff --git a/RAW/libRAW.pkg b/RAW/libRAW.pkg index 31521caa2fc..b75a6bc2139 100644 --- a/RAW/libRAW.pkg +++ b/RAW/libRAW.pkg @@ -9,7 +9,7 @@ PACKDCXXFLAGS:= ${HLTDCXXFLAGS} SRCS:= AliRawEventHeader.cxx AliRawEquipmentHeader.cxx \ AliRawData.cxx AliRawEquipment.cxx AliRawEvent.cxx \ - AliStats.cxx \ + AliStats.cxx AliFilter.cxx \ AliRawReader.cxx AliRawReaderFile.cxx AliRawReaderRoot.cxx \ AliRawReaderDate.cxx AliRawReaderDateV3.cxx \ AliBitPacking.cxx AliAltroBuffer.cxx \ @@ -31,4 +31,4 @@ ifdef DATE_ROOT EINCLUDE+= ${DATE_COMMON_DEFS} endif -EXPORT:=AliRawReader.h AliRawDataHeader.h AliAltroRawStream.h AliAltroBuffer.h AliBitPacking.h +EXPORT:=AliRawReader.h AliRawDataHeader.h AliAltroRawStream.h AliAltroBuffer.h AliBitPacking.h AliFilter.h diff --git a/RAW/mdc.cxx b/RAW/mdc.cxx new file mode 100644 index 00000000000..76021edd283 --- /dev/null +++ b/RAW/mdc.cxx @@ -0,0 +1,66 @@ +/************************************************************************** + * Copyright(c) 1998-1999, 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. * + **************************************************************************/ + +/* $Id$ */ + +////////////////////////////////////////////////////////////////////////// +// // +// c interface to AliMDC // +// // +////////////////////////////////////////////////////////////////////////// + +#include "mdc.h" +#include "AliMDC.h" + +void* alimdcCreate(int compress, int filterMode, + const char* localRunDB, int rdbmsRunDB, + const char* alienHostRunDB, const char* alienDirRunDB, + double maxSizeTagDB, const char* fileNameTagDB) +{ +// create an AliMDC object + + return new AliMDC(compress, kFALSE, AliMDC::EFilterMode(filterMode), + localRunDB, rdbmsRunDB, alienHostRunDB, alienDirRunDB, + maxSizeTagDB, fileNameTagDB); + +} + +int alimdcOpen(void* alimdc, int mode, const char* fileName) +{ +// open a new raw DB + + return ((AliMDC*)alimdc)->Open(AliMDC::EWriteMode(mode), fileName); +} + +int alimdcProcessEvent(void* alimdc, void* event, int isIovecArray) +{ +// process one event + + return ((AliMDC*)alimdc)->ProcessEvent(event, isIovecArray); +} + +int alimdcClose(void* alimdc) +{ +// close the raw DB + + return ((AliMDC*)alimdc)->Close(); +} + +void alimdcDelete(void* alimdc) +{ +// delete the AliMDC object + + delete (AliMDC*)alimdc; +} diff --git a/RAW/mdc.h b/RAW/mdc.h new file mode 100644 index 00000000000..e420f0e05dd --- /dev/null +++ b/RAW/mdc.h @@ -0,0 +1,31 @@ +#ifndef MDC_H +#define MDC_H +/* Copyright(c) 1998-2003, ALICE Experiment at CERN, All rights reserved. * + * See cxx source for full Copyright notice */ + +/* $Id$ */ + +////////////////////////////////////////////////////////////////////////// +// // +// c interface to AliMDC // +// // +////////////////////////////////////////////////////////////////////////// + +#ifdef __cplusplus +extern "C" { +#endif + +void* alimdcCreate(int compress, int filterMode, + const char* localRunDB, int rdbmsRunDB, + const char* alienHostRunDB, const char* alienDirRunDB, + double maxSizeTagDB, const char* fileNameTagDB); +int alimdcOpen(void* alimdc, int mode, const char* fileName); +int alimdcProcessEvent(void* alimdc, void* event, int isIovecArray); +int alimdcClose(void* alimdc); +void alimdcDelete(void* alimdc); + +#ifdef __cplusplus +} +#endif + +#endif -- 2.43.0