]>
Commit | Line | Data |
---|---|---|
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" |
f2dc6b20 | 32 | #include "AliRawEventHeaderBase.h" |
a197a4ce | 33 | #include "AliTagDB.h" |
34 | ||
35 | ||
36 | ClassImp(AliTagDB) | |
37 | ||
38 | ||
39 | //______________________________________________________________________________ | |
f2dc6b20 | 40 | AliTagDB::AliTagDB(AliRawEventHeaderBase *header, const char* fileName) : |
e10815f1 | 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 | ||
a197a4ce | 56 | //______________________________________________________________________________ |
e10815f1 | 57 | Bool_t AliTagDB::Create(const char* fileName) |
a197a4ce | 58 | { |
59 | // Create a new tag DB. | |
60 | ||
e10815f1 | 61 | const char *name = fileName; |
62 | if (!name) name = GetFileName(); | |
63 | fTagDB = new TFile(name, "RECREATE", | |
ee8f2a6c | 64 | Form("ALICE tag DB (%s)", AliRawDB::GetAliRootTag()), 1); |
a197a4ce | 65 | if (fTagDB->IsZombie()) { |
66 | Error("Create", "error opening tag DB"); | |
67 | fTagDB = 0; | |
68 | return kFALSE; | |
69 | } | |
f07ec911 | 70 | // Put wide read-write permissions |
71 | if(gSystem->Chmod(name,438)) { | |
72 | Error("Create", "can't set permissions for tag DB file"); | |
73 | fTagDB = 0; | |
74 | return kFALSE; | |
75 | } | |
a197a4ce | 76 | |
77 | // Create ROOT Tree object container | |
ee8f2a6c | 78 | fTree = new TTree("TAG", Form("ALICE header data tree (%s)", AliRawDB::GetAliRootTag())); |
a197a4ce | 79 | fTree->SetAutoSave(100000000); // autosave when 100 Mbyte written |
80 | ||
81 | Int_t bufsize = 32000; | |
82 | Int_t split = 1; | |
f2dc6b20 | 83 | const char *headername = fHeader->GetName(); |
84 | fTree->Branch("header", headername, &fHeader, bufsize, split); | |
a197a4ce | 85 | |
86 | return kTRUE; | |
87 | } | |
88 | ||
89 | //______________________________________________________________________________ | |
90 | void AliTagDB::Close() | |
91 | { | |
92 | // Close tag DB. | |
93 | ||
94 | if (!fTagDB) return; | |
95 | ||
96 | fTagDB->cd(); | |
97 | ||
98 | // Write the tree. | |
99 | fTree->Write(); | |
100 | ||
101 | // Close DB, this also deletes the fTree | |
102 | fTagDB->Close(); | |
103 | ||
e10815f1 | 104 | if (fDeleteFiles) |
a197a4ce | 105 | gSystem->Unlink(fTagDB->GetName()); |
106 | ||
107 | delete fTagDB; | |
108 | fTagDB = 0; | |
109 | } | |
110 | ||
111 | //______________________________________________________________________________ | |
e10815f1 | 112 | Bool_t AliTagDB::NextFile(const char* fileName) |
a197a4ce | 113 | { |
114 | // Close te current file and open a new one. | |
115 | // Returns kFALSE in case opening failed. | |
116 | ||
117 | Close(); | |
118 | ||
e10815f1 | 119 | if (!Create(fileName)) return kFALSE; |
a197a4ce | 120 | return kTRUE; |
121 | } | |
122 | ||
e10815f1 | 123 | //______________________________________________________________________________ |
124 | void AliTagDB::SetFS(const char* fs) | |
125 | { | |
126 | // set the file system location | |
127 | ||
128 | fFS = fs; | |
129 | if (fs) { | |
130 | gSystem->ResetErrno(); | |
131 | gSystem->MakeDirectory(fs); | |
132 | if (gSystem->GetErrno() && gSystem->GetErrno() != EEXIST) { | |
133 | SysError("SetFS", "mkdir %s", fs); | |
134 | } | |
135 | } | |
136 | } | |
137 | ||
a197a4ce | 138 | //______________________________________________________________________________ |
139 | Float_t AliTagDB::GetCompressionFactor() const | |
140 | { | |
141 | // Return compression factor. | |
142 | ||
143 | if (fTree->GetZipBytes() == 0.) | |
144 | return 1.0; | |
145 | else | |
146 | return fTree->GetTotBytes()/fTree->GetZipBytes(); | |
147 | } | |
148 | ||
149 | //______________________________________________________________________________ | |
150 | const char *AliTagDB::GetFileName() const | |
151 | { | |
152 | // Return filename based on hostname and date and time. This will make | |
153 | // each file unique. The tags will be stored in the /data1/tags directory. | |
154 | ||
155 | static char fname[64]; | |
e10815f1 | 156 | const char *fs = fFS; |
a197a4ce | 157 | |
158 | // check that fs exists (crude check fails if fs is a file) | |
159 | gSystem->MakeDirectory(fs); | |
160 | ||
161 | char hostname[64]; | |
162 | ||
163 | strcpy(hostname, gSystem->HostName()); | |
164 | ||
165 | char *s; | |
166 | if ((s = strchr(hostname, '.'))) | |
167 | *s = 0; | |
168 | ||
169 | TDatime dt; | |
170 | ||
171 | sprintf(fname, "%s/%s_%d_%d.root", fs, hostname, dt.GetDate(), dt.GetTime()); | |
172 | ||
173 | return fname; | |
174 | } |