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 //////////////////////////////////////////////////////////////////////////
28 #include <TTimeStamp.h>
33 #include "AliRawEventTag.h"
35 #include "AliRawEventHeaderBase.h"
41 //______________________________________________________________________________
42 AliTagDB::AliTagDB(AliRawEventTag *eventTag, const char* fileName) :
53 if (!Create(fileName))
58 //______________________________________________________________________________
59 Bool_t AliTagDB::Create(const char* fileName)
61 // Create a new tag DB.
63 const char *name = fileName;
64 if (!name) name = GetFileName();
65 fTagDB = new TFile(name, "RECREATE",
66 Form("ALICE tag DB (%s)", AliRawDB::GetAliRootTag()), 1);
67 if (fTagDB->IsZombie()) {
68 Error("Create", "error opening tag DB");
72 // Put wide read-write permissions
73 if(gSystem->Chmod(name,438)) {
74 Error("Create", "can't set permissions for tag DB file");
79 // Create ROOT Tree object container
80 fTree = new TTree("T", Form("ALICE raw-data tag tree (%s)", AliRawDB::GetAliRootTag()));
81 fTree->SetAutoSave(100000000); // autosave when 100 Mbyte written
83 Int_t bufsize = 32000;
85 const char *tagname = fEventTag->GetName();
86 fTree->Branch("TAG", tagname, &fEventTag, bufsize, split);
91 //______________________________________________________________________________
92 void AliTagDB::Close()
103 // Close DB, this also deletes the fTree
107 gSystem->Unlink(fTagDB->GetName());
113 //______________________________________________________________________________
114 Bool_t AliTagDB::NextFile(const char* fileName)
116 // Close te current file and open a new one.
117 // Returns kFALSE in case opening failed.
121 if (!Create(fileName)) return kFALSE;
125 //______________________________________________________________________________
126 void AliTagDB::SetFS(const char* fs)
128 // set the file system location
132 gSystem->ResetErrno();
133 gSystem->MakeDirectory(fs);
134 if (gSystem->GetErrno() && gSystem->GetErrno() != EEXIST) {
135 SysError("SetFS", "mkdir %s", fs);
140 //______________________________________________________________________________
141 Float_t AliTagDB::GetCompressionFactor() const
143 // Return compression factor.
145 if (fTree->GetZipBytes() == 0.)
148 return fTree->GetTotBytes()/fTree->GetZipBytes();
151 //______________________________________________________________________________
152 const char *AliTagDB::GetFileName() const
154 // Return filename based on hostname and date and time. This will make
155 // each file unique. The tags will be stored in the /data1/tags directory.
157 static TString fname;
158 const char *fs = fFS;
160 // check that fs exists (crude check fails if fs is a file)
161 gSystem->MakeDirectory(fs);
163 // Get the run number
164 Int_t runNumber = -1;
166 AliRawEventHeaderBase *header = fEventTag->GetHeader();
167 if (header) runNumber = header->Get("RunNb");
171 hostname.Form("%s",gSystem->HostName());
172 if ( hostname.First('.') > 0 ) hostname.Resize(hostname.First('.'));
176 fname.Form("%s/Run%d.%s_%d_%d_%d.RAW.tag.root", fs, runNumber, hostname.Data(),
177 ts.GetDate(), ts.GetTime(), ts.GetNanoSec());