Missing header file added
[u/mrichter/AliRoot.git] / RAW / AliTagDB.cxx
CommitLineData
a197a4ce 1// @(#)alimdc:$Name$:$Id$
2// Author: Fons Rademakers 26/11/99
3
4/**************************************************************************
5 * Copyright(c) 1998-2003, ALICE Experiment at CERN, All rights reserved. *
6 * *
7 * Author: The ALICE Off-line Project. *
8 * Contributors are mentioned in the code where appropriate. *
9 * *
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 **************************************************************************/
18
19//////////////////////////////////////////////////////////////////////////
20// //
21// AliTagDB //
22// //
23//////////////////////////////////////////////////////////////////////////
24
e10815f1 25#include <errno.h>
26
a197a4ce 27#include <TSystem.h>
28
52f36b9b 29#include "AliESD.h"
a197a4ce 30
52f36b9b 31#include "AliRawDB.h"
32#include "AliRawEventHeader.h"
a197a4ce 33#include "AliTagDB.h"
34
35
36ClassImp(AliTagDB)
37
38
39//______________________________________________________________________________
e10815f1 40AliTagDB::AliTagDB(AliRawEventHeader *header, const char* fileName) :
41 fTagDB(NULL),
42 fTree(NULL),
43 fHeader(header),
44 fMaxSize(-1),
45 fFS(""),
46 fDeleteFiles(kFALSE)
a197a4ce 47{
48 // Create tag DB.
49
e10815f1 50 if (fileName) {
51 if (!Create(fileName))
a197a4ce 52 MakeZombie();
53 }
54}
55
56//______________________________________________________________________________
57AliTagDB::AliTagDB(const AliTagDB& tagDB): TObject(tagDB)
58{
59// copy constructor
60
61 Fatal("AliTagDB", "copy constructor not implemented");
62}
63
64//______________________________________________________________________________
65AliTagDB& AliTagDB::operator = (const AliTagDB& /*tagDB*/)
66{
67// assignment operator
68
69 Fatal("operator =", "assignment operator not implemented");
70 return *this;
71}
72
73//______________________________________________________________________________
e10815f1 74Bool_t AliTagDB::Create(const char* fileName)
a197a4ce 75{
76 // Create a new tag DB.
77
e10815f1 78 const char *name = fileName;
79 if (!name) name = GetFileName();
80 fTagDB = new TFile(name, "RECREATE",
81 Form("ALICE MDC%d tag DB", AliRawDB::kMDC), 1);
a197a4ce 82 if (fTagDB->IsZombie()) {
83 Error("Create", "error opening tag DB");
84 fTagDB = 0;
85 return kFALSE;
86 }
87
88 // Create ROOT Tree object container
e10815f1 89 fTree = new TTree("TAG", Form("ALICE MDC%d header data tree", AliRawDB::kMDC));
a197a4ce 90 fTree->SetAutoSave(100000000); // autosave when 100 Mbyte written
91
92 Int_t bufsize = 32000;
93 Int_t split = 1;
94 fTree->Branch("header", "AliRawEventHeader", &fHeader, bufsize, split);
95
96 return kTRUE;
97}
98
99//______________________________________________________________________________
100void AliTagDB::Close()
101{
102 // Close tag DB.
103
104 if (!fTagDB) return;
105
106 fTagDB->cd();
107
108 // Write the tree.
109 fTree->Write();
110
111 // Close DB, this also deletes the fTree
112 fTagDB->Close();
113
e10815f1 114 if (fDeleteFiles)
a197a4ce 115 gSystem->Unlink(fTagDB->GetName());
116
117 delete fTagDB;
118 fTagDB = 0;
119}
120
121//______________________________________________________________________________
e10815f1 122Bool_t AliTagDB::NextFile(const char* fileName)
a197a4ce 123{
124 // Close te current file and open a new one.
125 // Returns kFALSE in case opening failed.
126
127 Close();
128
e10815f1 129 if (!Create(fileName)) return kFALSE;
a197a4ce 130 return kTRUE;
131}
132
e10815f1 133//______________________________________________________________________________
134void AliTagDB::SetFS(const char* fs)
135{
136// set the file system location
137
138 fFS = fs;
139 if (fs) {
140 gSystem->ResetErrno();
141 gSystem->MakeDirectory(fs);
142 if (gSystem->GetErrno() && gSystem->GetErrno() != EEXIST) {
143 SysError("SetFS", "mkdir %s", fs);
144 }
145 }
146}
147
a197a4ce 148//______________________________________________________________________________
149Float_t AliTagDB::GetCompressionFactor() const
150{
151 // Return compression factor.
152
153 if (fTree->GetZipBytes() == 0.)
154 return 1.0;
155 else
156 return fTree->GetTotBytes()/fTree->GetZipBytes();
157}
158
159//______________________________________________________________________________
160const char *AliTagDB::GetFileName() const
161{
162 // Return filename based on hostname and date and time. This will make
163 // each file unique. The tags will be stored in the /data1/tags directory.
164
165 static char fname[64];
e10815f1 166 const char *fs = fFS;
a197a4ce 167
168 // check that fs exists (crude check fails if fs is a file)
169 gSystem->MakeDirectory(fs);
170
171 char hostname[64];
172
173 strcpy(hostname, gSystem->HostName());
174
175 char *s;
176 if ((s = strchr(hostname, '.')))
177 *s = 0;
178
179 TDatime dt;
180
181 sprintf(fname, "%s/%s_%d_%d.root", fs, hostname, dt.GetDate(), dt.GetTime());
182
183 return fname;
184}