1 // @(#)alimdc:$Name$:$Id$
2 // Author: Fons Rademakers 26/11/99
4 /**************************************************************************
5 * Copyright(c) 1998-2003, ALICE Experiment at CERN, All rights reserved. *
7 * Author: The ALICE Off-line Project. *
8 * Contributors are mentioned in the code where appropriate. *
10 * Permission to use, copy, modify and distribute this software and its *
11 * documentation strictly for non-commercial purposes is hereby granted *
12 * without fee, provided that the above copyright notice appears in all *
13 * copies and that both the copyright notice and this permission notice *
14 * appear in the supporting documentation. The authors make no claims *
15 * about the suitability of this software for any purpose. It is *
16 * provided "as is" without express or implied warranty. *
17 **************************************************************************/
19 //////////////////////////////////////////////////////////////////////////
23 //////////////////////////////////////////////////////////////////////////
33 #include "AliRawEvent.h"
34 #include "AliRawEventHeader.h"
47 //______________________________________________________________________________
48 AliRawDB::AliRawDB(AliRawEvent *event,
52 Double_t maxsize, Int_t compress,
55 // Create a new raw DB containing at most maxsize bytes.
62 // Consistency check with DATE header file
64 if (fEvent->GetHeader()->HeaderSize() != EVENT_HEAD_BASE_SIZE) {
65 Error("AliRawDB", "inconsistency between DATE and AliRawEvent headers");
77 //______________________________________________________________________________
78 AliRawDB::AliRawDB(const AliRawDB& rawDB): TObject(rawDB)
82 Fatal("AliRawDB", "copy constructor not implemented");
85 //______________________________________________________________________________
86 AliRawDB& AliRawDB::operator = (const AliRawDB& /*rawDB*/)
88 // assignment operator
90 Fatal("operator =", "assignment operator not implemented");
94 //______________________________________________________________________________
95 Bool_t AliRawDB::FSHasSpace(const char *fs) const
97 // Check for at least fMaxSize bytes of free space on the file system.
98 // If the space is not available return kFALSE, kTRUE otherwise.
100 Long_t id, bsize, blocks, bfree;
102 if (gSystem->GetFsInfo(fs, &id, &bsize, &blocks, &bfree) == 1) {
103 Error("FSHasSpace", "could not stat file system %s", fs);
107 // Leave 5 percent of diskspace free
108 Double_t avail = Double_t(bfree) * 0.95;
109 if (avail*bsize > fMaxSize)
112 Warning("FSHasSpace", "no space on file system %s", fs);
116 //______________________________________________________________________________
117 const char *AliRawDB::GetFileName() const
119 // Return filename based on hostname and date and time. This will make
120 // each file unique. Also makes sure (via FSHasSpace()) that there is
121 // enough space on the file system to store the file. Returns 0 in
122 // case of error or interrupt signal.
124 static TString fname;
125 static Bool_t fstoggle = kFALSE;
127 TString fs = fstoggle ? AliMDC::RawDBFS(1) : AliMDC::RawDBFS(0);
130 TString hostname = gSystem->HostName();
132 if ((pos = hostname.Index(".")) != kNPOS)
133 hostname.Remove(pos);
135 if (!FSHasSpace(fs)) {
137 fstoggle = !fstoggle;
138 fs = fstoggle ? AliMDC::RawDBFS(1) : AliMDC::RawDBFS(0);
139 if (FSHasSpace(fs)) break;
140 Info("GetFileName", "sleeping 30 seconds before retrying...");
141 gSystem->Sleep(30000); // sleep for 30 seconds
142 if (AliMDC::Instance() && AliMDC::Instance()->StopLoop())
147 fname = fs + "/" + hostname + "_";
148 fname += dt.GetDate();
150 fname += dt.GetTime();
153 fstoggle = !fstoggle;
158 //______________________________________________________________________________
159 Bool_t AliRawDB::Create()
161 // Create a new raw DB.
163 const Int_t kMaxRetry = 200;
164 const Int_t kMaxSleep = 1; // seconds
165 const Int_t kMaxSleepLong = 10; // seconds
169 if (AliMDC::Instance() && AliMDC::Instance()->StopLoop())
172 const char *fname = GetFileName();
174 Error("Create", "error getting raw DB file name");
180 fRawDB = TFile::Open(fname, GetOpenOption(),
181 Form("ALICE MDC%d raw DB", AliMDC::kMDC), fCompress,
184 if (retry < kMaxRetry) {
185 Warning("Create", "failure to open file, sleeping %d %s before retrying...",
186 kMaxSleep, kMaxSleep==1 ? "second" : "seconds");
187 gSystem->Sleep(kMaxSleep*1000);
190 Error("Create", "failure to open file %s after %d tries", fname, kMaxRetry);
194 Warning("Create", "succeeded to open file after %d retries", retry);
196 if (fRawDB->IsZombie()) {
197 if (fRawDB->GetErrno() == ENOSPC ||
198 fRawDB->GetErrno() == 1018 || // SECOMERR
199 fRawDB->GetErrno() == 1027) { // SESYSERR
200 fRawDB->ResetErrno();
202 Warning("Create", "file is a zombie (no space), sleeping %d %s before retrying...",
203 kMaxSleepLong, kMaxSleepLong==1 ? "second" : "seconds");
204 gSystem->Sleep(kMaxSleepLong*1000); // sleep 10 seconds before retrying
207 Error("Create", "file %s is zombie", fname);
208 fRawDB->ResetErrno();
211 if (retry < kMaxRetry) {
212 Warning("Create", "file is a zombie, sleeping %d %s before retrying...",
213 kMaxSleep, kMaxSleep==1 ? "second" : "seconds");
214 gSystem->Sleep(kMaxSleep*1000);
217 Error("Create", "failure to open file %s after %d tries", fname, kMaxRetry);
221 // Create raw data TTree
227 //______________________________________________________________________________
228 void AliRawDB::MakeTree()
230 // Create ROOT Tree object container.
232 fTree = new TTree("RAW", Form("ALICE MDC%d raw data tree", AliMDC::kMDC));
233 fTree->SetAutoSave(2000000000); // autosave when 2 Gbyte written
235 Int_t bufsize = 256000;
236 // splitting 29.6 MB/s, no splitting 35.3 MB/s on P4 2GHz 15k SCSI
239 fTree->Branch("rawevent", "AliRawEvent", &fEvent, bufsize, split);
242 // Create tree which will contain the HLT ESD information
244 fESDTree = new TTree("esdTree", Form("ALICE MDC%d HLT ESD tree", AliMDC::kMDC));
245 fESDTree->SetAutoSave(2000000000); // autosave when 2 Gbyte written
247 fESDTree->Branch("ESD", "AliESD", &fESD, bufsize, split);
252 //______________________________________________________________________________
253 void AliRawDB::Close()
265 // Close DB, this also deletes the fTree
268 if (AliMDC::DeleteFiles()) {
269 gSystem->Unlink(fRawDB->GetName());
275 // Create semaphore to say this file is finished
276 Int_t tfd = ::creat(Form("%s.done", fRawDB->GetName()), 0644);
283 //______________________________________________________________________________
284 Bool_t AliRawDB::NextFile()
286 // Close te current file and open a new one.
287 // Returns kFALSE in case opening failed.
291 if (!Create()) return kFALSE;
295 //______________________________________________________________________________
296 Float_t AliRawDB::GetCompressionFactor() const
298 // Return compression factor.
300 if (fTree->GetZipBytes() == 0.)
303 return fTree->GetTotBytes()/fTree->GetZipBytes();