- // FIXME: should check if fs is a directory
-#endif
-
- TString hostname = gSystem->HostName();
- Int_t pos;
- if ((pos = hostname.Index(".")) != kNPOS)
- hostname.Remove(pos);
-
- fname = fs + "/" + hostname + "_";
- fname += dt.GetDate();
- fname += "_";
- fname += dt.GetTime();
- fname += ".root";
-
- return fname;
-}
-
-//______________________________________________________________________________
-void AliRawRootdDB::Close()
-{
- // Close raw rootd DB.
-
- if (!fRawDB) return;
-
- fRawDB->cd();
-
- // Write the tree.
- fTree->Write();
-
- // Close DB, this also deletes the fTree
- fRawDB->Close();
-
-#if 0
- // can use services of TFTP
- if (AliMDC::DeleteFiles())
- gSystem->Exec(Form("rfrm %s", fRawDB->GetName()));
-#endif
-
- delete fRawDB;
- fRawDB = 0;
-}
-
-
-//______________________________________________________________________________
-AliRawNullDB::AliRawNullDB(AliRawEvent *event, Double_t maxsize, Int_t compress)
- : AliRawDB(event, maxsize, compress, kFALSE)
-{
- // Create a new raw DB that will wrtie to /dev/null.
-
- if (!Create())
- MakeZombie();
-}
-
-//______________________________________________________________________________
-const char *AliRawNullDB::GetFileName() const
-{
- // Return /dev/null as filename.
-
- return "/dev/null";
-}
-
-//______________________________________________________________________________
-void AliRawNullDB::Close()
-{
- // Close raw RFIO DB.
-
- if (!fRawDB) return;
-
- fRawDB->cd();
-
- // Write the tree.
- fTree->Write();
-
- // Close DB, this also deletes the fTree
- fRawDB->Close();
-
- delete fRawDB;
- fRawDB = 0;
-}
-
-
-//______________________________________________________________________________
-AliTagDB::AliTagDB(AliRawEventHeader *header, Double_t maxsize, Bool_t create)
-{
- // Create tag DB.
-
- fHeader = header;
- fMaxSize = maxsize;
-
- if (create) {
- if (!Create())
- MakeZombie();
- }
-}
-
-//______________________________________________________________________________
-Bool_t AliTagDB::Create()
-{
- // Create a new tag DB.
-
- fTagDB = new TFile(GetFileName(), "RECREATE",
- Form("ALICE MDC%d tag DB", kMDC), 1);
- if (fTagDB->IsZombie()) {
- Error("Create", "error opening tag DB");
- fTagDB = 0;
- return kFALSE;
- }
-
- // Create ROOT Tree object container
- fTree = new TTree("TAG", Form("ALICE MDC%d header data tree", kMDC));
- fTree->SetAutoSave(100000000); // autosave when 100 Mbyte written
-
- Int_t bufsize = 32000;
- Int_t split = 1;
- fTree->Branch("header", "AliRawEventHeader", &fHeader, bufsize, split);
-
- return kTRUE;
-}
-
-//______________________________________________________________________________
-void AliTagDB::Close()
-{
- // Close tag DB.
-
- if (!fTagDB) return;
-
- fTagDB->cd();
-
- // Write the tree.
- fTree->Write();
-
- // Close DB, this also deletes the fTree
- fTagDB->Close();
-
- if (AliMDC::DeleteFiles())
- gSystem->Unlink(fTagDB->GetName());
-
- delete fTagDB;
- fTagDB = 0;
-}
-
-//______________________________________________________________________________
-Bool_t AliTagDB::NextFile()
-{
- // Close te current file and open a new one.
- // Returns kFALSE in case opening failed.
-
- Close();
-
- if (!Create()) return kFALSE;
- return kTRUE;
-}
-
-//______________________________________________________________________________
-Float_t AliTagDB::GetCompressionFactor() const
-{
- // Return compression factor.
-
- if (fTree->GetZipBytes() == 0.)
- return 1.0;
- else
- return fTree->GetTotBytes()/fTree->GetZipBytes();
-}
-
-//______________________________________________________________________________
-const char *AliTagDB::GetFileName() const
-{
- // Return filename based on hostname and date and time. This will make
- // each file unique. The tags will be stored in the /data1/tags directory.
-
- static char fname[64];
- const char *fs = kTagDBFS;
-
- // check that fs exists (crude check fails if fs is a file)
- gSystem->MakeDirectory(fs);
-
- char hostname[64];
-
- strcpy(hostname, gSystem->HostName());
-
- char *s;
- if ((s = strchr(hostname, '.')))
- *s = 0;
-
- TDatime dt;
-
- sprintf(fname, "%s/%s_%d_%d.root", fs, hostname, dt.GetDate(), dt.GetTime());
-
- return fname;
-}
-
-
-//______________________________________________________________________________
-AliTagNullDB::AliTagNullDB(AliRawEventHeader *header, Double_t maxsize) :
- AliTagDB(header, maxsize, kFALSE)
-{
- // Create tag db writing to /dev/null.
-
- if (!Create())
- MakeZombie();
-}
-
-//______________________________________________________________________________
-const char *AliTagNullDB::GetFileName() const
-{
- // Return /dev/null as filename.
-
- return "/dev/null";
-}
-
-//______________________________________________________________________________
-void AliTagNullDB::Close()
-{
- // Close null tag DB.
-
- if (!fTagDB) return;
-
- fTagDB->cd();
-
- // Write the tree.
- fTree->Write();
-
- // Close DB, this also deletes the fTree
- fTagDB->Close();
-
- delete fTagDB;
- fTagDB = 0;
-}
-
-
-//______________________________________________________________________________
-AliRunDB::AliRunDB(Bool_t noLocalDB)
-{
- // Open run database, and get or create tree.
-
- fRunDB = 0;
-
- if (noLocalDB) return;
-
- // Get hostname
- char hostname[64], filename[64];
- const char *fs = kRunDBFS;
-
- // check that fs exists (crude check fails if fs is a file)
- gSystem->MakeDirectory(fs);
-
- strcpy(hostname, gSystem->HostName());
-
- char *s;
- if ((s = strchr(hostname, '.')))
- *s = 0;
-
- sprintf(filename, "%s/%s_rundb.root", fs, hostname);
-
- if (!gSystem->AccessPathName(filename, kFileExists))
- fRunDB = new TFile(filename, "UPDATE");
- else
- fRunDB = new TFile(filename, "CREATE", Form("ALICE MDC%d Run DB", kMDC));
-}
-
-//______________________________________________________________________________
-void AliRunDB::Update(AliStats *stats)
-{
- // Add stats object to database.
-
- if (!stats || !fRunDB) return;
-
- TDirectory *ds = gDirectory;
- fRunDB->cd();
-
- char sname[64];
- char *s = (char*)strrchr(stats->GetFileName(), '/');
- if (s) {
- s++;
- strcpy(sname, s);
- } else
- strcpy(sname, stats->GetFileName());
- s = strchr(sname, '.');
- if (s) *s = 0;
-
- stats->Write(sname);
-
- ds->cd();
-}
-
-//______________________________________________________________________________
-void AliRunDB::UpdateRDBMS(AliStats *stats)
-{
- // Add stats object to central MySQL DB.
-
- if (!stats) return;
-
- char sql[4096];
- char bt[25], et[25];
-
- strcpy(bt, stats->GetBeginTime().AsSQLString());
- 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')", kMDC,
- stats->GetFileName(), (int)stats->GetFileSize(), stats->GetEvents(),
- stats->GetFirstRun(), stats->GetFirstEvent(), stats->GetLastRun(),
- stats->GetLastEvent(), stats->GetCompressionMode(),
- stats->GetCompressionFactor(), stats->GetFilterState() ? "on" : "off",
- bt, et);
-
- // open connection to MySQL server on pcsalo
- TSQLServer *db = TSQLServer::Connect("mysql://pcsalo.cern.ch/mdc", "alice", "amdc");
-
- if (!db || db->IsZombie()) {
- Error("UpdateRDBMS", "failed to connect to MySQL server on pcsalo");
- printf("%s\n", sql);
- delete db;
- return;
- }
-
- TSQLResult *res = db->Query(sql);
-
- if (!res) {
- Error("UpdateRDBMS", Form("insert into mdc%dcatalog failed", kMDC));
- printf("%s\n", sql);
- }
-
- delete res;
- delete db;
-}
-
-//______________________________________________________________________________
-void AliRunDB::UpdateAliEn(AliStats *stats)
-{
- // Record file in AliEn catalog.
-
- if (!stats) return;
-
- TGrid *g = TGrid::Connect(kAlienHost, "");
-
- TString lfn = kAlienDir;
- lfn += "/";
- lfn += gSystem->BaseName(stats->GetFileName());
-
- Int_t result = g->AddFile(lfn, stats->GetFileName(),
- (int)stats->GetFileSize());
-
- if (result == -1) {
- Error("UpdateAliEn", "error adding file to AliEn catalog");
- printf("AliEn: AddFile(%s, %s, %d)\n", lfn.Data(), stats->GetFileName(),
- (int)stats->GetFileSize());
- }
-
- delete g;
-}
-
-//______________________________________________________________________________
-void AliRunDB::Close()
-{
- // Close run database.
-
- if (fRunDB) fRunDB->Close();
- delete fRunDB;
-}
-
-//----------------- Use SIGUSR1 to interupt endless loop -----------------------
-class AliMDCInterruptHandler : public TSignalHandler {
-public:
- AliMDCInterruptHandler(AliMDC *mdc) : TSignalHandler(kSigUser1, kFALSE), fMDC(mdc) { }
- AliMDCInterruptHandler(const AliMDCInterruptHandler& handler): TSignalHandler(handler)
- {Fatal("AliMDCInterruptHandler", "copy constructor not implemented");};
- AliMDCInterruptHandler& operator = (const AliMDCInterruptHandler& /*rawDB*/) {
- Fatal("operator =", "assignment operator not implemented");
- return *this;
- };
- Bool_t Notify() {
- Info("Notify", "received a SIGUSR1 signal");
- fMDC->SetStopLoop();
- return kTRUE;
- }
-private:
- AliMDC *fMDC; // alimdc to signal
-};
-
-//______________________________________________________________________________
-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(kFifo, 0644) < 0) && (errno != EEXIST)) {
- Error("AliMDC", "cannot create fifo %s", kFifo);
- return;
- }
- if ((chmod(kFifo, 0666) == -1) && (errno != EPERM)) {
- Error("AliMDC", "cannot change permission of fifo %s", kFifo);
- return;
- }
- if ((fFd = open(kFifo, O_RDONLY)) == -1) {
- Error("AliMDC", "cannot open input file %s", kFifo);
- return;
- }
- fUseFifo = kTRUE;
-#endif
- fUseLoop = kFALSE;
- }
-
- printf("<AliMDC::AliMDC>: 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));
-
- gAliMDC = this;
-}
-
-//______________________________________________________________________________
-Int_t AliMDC::Run()
-{
- // 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] = kRawDBFS[0];
- dirs[1] = kRawDBFS[1];
- dirs[2] = kTagDBFS;
- dirs[3] = kRunDBFS;
- 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;
- }
- }
-
- // 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;
-
- // Create new raw DB.
- AliRawDB *rawdb;
- if (fWriteMode == kRFIO)
- rawdb = new AliRawRFIODB(event, fMaxFileSize, fCompress);
- else if (fWriteMode == kROOTD)
- rawdb = new AliRawRootdDB(event, fMaxFileSize, fCompress);
- else if (fWriteMode == kCASTOR)
- rawdb = new AliRawCastorDB(event, fMaxFileSize, fCompress);
- else if (fWriteMode == kDEVNULL)
- rawdb = new AliRawNullDB(event, fMaxFileSize, fCompress);
- else
- rawdb = new AliRawDB(event, 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 == kDEVNULL)
- tagdb = new AliTagNullDB(event->GetHeader(), kMaxTagFileSize);
- else
- tagdb = new AliTagDB(event->GetHeader(), kMaxTagFileSize);
- if (tagdb->IsZombie())
- tagdb = 0;
- else
- printf("Filling tag DB %s\n", tagdb->GetDBName());
-#endif
-
- // Create AliStats object
- AliStats *stats = new AliStats(rawdb->GetDBName(), fCompress, fUseFilter);
-
- // Shortcut for easy header access
- AliRawEventHeader &header = *event->GetHeader();
-
- // 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("<AliMDC::Run>: EOF, processed %d events\n", fNumEvents);
- break;
- }
- return 1;
- }
- ALIDEBUG(3)
- header.Dump();
-
- // 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;
- // This needs to be re-engineered for the next ADC...
- //if (fUseFilter && TEST_USER_ATTRIBUTE(header.GetTypeAttribute(), 0))
- // 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 kStartOfRun:
- case kEndOfRun:
- case kStartOfRunFiles:
- case 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;
- }
- break;
- default:
- ALIDEBUG(1) {
- Int_t s = header.GetEventSize() - header.HeaderSize();
- Info("Run", "Processing %s (%d bytes)", header.GetTypeName(), s);
- }
- }
-
- // 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;
- }
-
- // Loop over all sub-events... (LDCs)
- Int_t nsub = 1;
- while (toRead > 0) {
-#ifdef USE_EB
- ebdata = (char *)ebvec[nsub].iov_base;
-#endif
-
- ALIDEBUG(1)
- Info("Run", "reading LDC %d", nsub);
-
- AliRawEvent *subEvent = event->NextSubEvent();
-
- // 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;
- }
-
- ALIDEBUG(3)
- subHeader.Dump();
-
- toRead -= subHeader.HeaderSize();
-
-#ifdef USE_EB
- ebdata = (char *)(ebvec[nsub].iov_base) + subHeader.HeaderSize();
-#endif
-
- Int_t rawSize = subHeader.GetEventSize() - subHeader.HeaderSize();
-
- // Read Equipment Header (in case of physics or calibration event)
- if (header.GetType() == kPhysicsEvent ||
- header.GetType() == kCalibrationEvent) {
- AliRawEquipmentHeader &equipment = *subEvent->GetEquipmentHeader();
- Int_t equipHeaderSize = equipment.HeaderSize();
- if ((status = ReadEquipmentHeader(equipment, header.DataIsSwapped(),
- ebdata)) != equipHeaderSize) {
- if (status == 0) {
- Error("Run", "unexpected EOF reading equipment-header");
- break;
- }
- return 1;
- }
- toRead -= equipHeaderSize;
- rawSize -= equipHeaderSize;
-#ifdef USE_EB
- ebdata = (char *)(ebvec[nsub].iov_base) + subHeader.HeaderSize() +
- equipHeaderSize;
-#endif
- }
-
- // 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 sub-event raw data
- AliRawData &subRaw = *subEvent->GetRawData();
- if ((status = ReadRawData(subRaw, rawSize, ebdata)) != rawSize) {
- if (status == 0) {
- Error("Run", "unexpected EOF reading sub-event raw data");
- break;
- }
- return 1;
- }
-
- if (callFilter) {
- if (TEST_USER_ATTRIBUTE(subHeader.GetTypeAttribute(), 0))
- Filter(subRaw);
- else {
- // set size of all sectors without hard track flag to 0
- subRaw.SetSize(0);
- }
- }
-
- toRead -= rawSize;
- nsub++;
- }
-
- // 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++;
-
- if (!(fNumEvents%10))
- printf("Processed event %d (%d)\n", fNumEvents, rawdb->GetEvents());
-
- // Filling time statistics
- if (rawdb->GetBytesWritten() > nextChunk) {
- tnew = timer.RealTime();
- stats->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
- stats->WriteToDB(rawdb);
- 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;
- }
-
- // Check size of tag db
- if (tagdb && tagdb->FileFull()) {
- if (!tagdb->NextFile())
- tagdb = 0;
- else
- printf("Filling tag DB %s\n", tagdb->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_EB
- if (!ebReleaseEvent(ebvec)) {
- 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
- stats->WriteToDB(rawdb);
- delete stats;
-
- // Close the raw DB
- delete rawdb;
-
- // Close the tag DB
- delete tagdb;
-
- // Close input source
- close(fFd);
-
-#if 0
- // Cleanup fifo
- if (fUseFifo && ::unlink(kFifo) == -1) {
- SysError("Run", "unlink");
- return 1;
- }
-#endif
-
-#ifdef USE_EB
- // Print eor flag
- if (eorFlag) {
- Info("Run", "event builder reported end of run (%d)", eorFlag);
- }
-#endif
-
- return 0;
-}
-
-//______________________________________________________________________________
-Int_t AliMDC::Read(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;
-
- 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 == 0)
- break; // EOF
- if (errno != EINTR)
- SysError("Read", "read");
- return -1;
- }
- }
- return n;
-}
-
-//______________________________________________________________________________
-Int_t AliMDC::ReadHeader(AliRawEventHeader &header, void *eb)
-{
- // 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;
- }
- }
-
- // Swap header data if needed
- if (header.IsSwapped())
- header.Swap();
-
- // 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 nrecv;
-}
-
-//______________________________________________________________________________
-Int_t AliMDC::ReadEquipmentHeader(AliRawEquipmentHeader &header,
- Bool_t isSwapped, void *eb)
-{
- // 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;
- }
-
- return nrecv;
-}
-
-//______________________________________________________________________________
-Int_t AliMDC::ReadRawData(AliRawData &raw, Int_t size, void *eb)
-{
- // 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;
- }
- }
-
- 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;
-
- return nrecv;
-}
-
-#ifdef USE_HLT
-#include <AliTPCL3Tunnel.h>
-#endif
-
-//______________________________________________________________________________
-Int_t AliMDC::Filter(AliRawData &raw)
-{
- // Call 3rd level filter for this raw data segment.
-
-#ifdef USE_HLT
- AliTPCL3Tunnel *tunnel = 0;
- if (!tunnel) {
- // initialisation
- tunnel = new AliTPCL3Tunnel(Form("%s/TPCparams.root",
- gSystem->Getenv("ALITPC")));
- }
-
- Int_t obytes, nbytes;
- obytes = nbytes = raw.GetSize();
- char *outbuf = tunnel->EvalTrack((char *)raw.GetBuffer(), nbytes);
-
- raw.SetSize(nbytes);
- memcpy(raw.GetBuffer(), outbuf, nbytes);
-
- printf("Filter called for event %d: reduced from %d to %d\n", fNumEvents,
- obytes, nbytes);
-
-#else
-
- raw.GetSize();
- printf("Filter called for event %d\n", fNumEvents);
-
-#endif
-
- return 0;