]>
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> |
54dd2271 | 28 | #include <TTimeStamp.h> |
a197a4ce | 29 | |
52f36b9b | 30 | #include "AliESD.h" |
a197a4ce | 31 | |
52f36b9b | 32 | #include "AliRawDB.h" |
54dd2271 | 33 | #include "AliRawEventTag.h" |
a197a4ce | 34 | #include "AliTagDB.h" |
54dd2271 | 35 | #include "AliRawEventHeaderBase.h" |
a197a4ce | 36 | |
37 | ||
38 | ClassImp(AliTagDB) | |
39 | ||
40 | ||
41 | //______________________________________________________________________________ | |
54dd2271 | 42 | AliTagDB::AliTagDB(AliRawEventTag *eventTag, const char* fileName) : |
e10815f1 | 43 | fTagDB(NULL), |
44 | fTree(NULL), | |
54dd2271 | 45 | fEventTag(eventTag), |
e10815f1 | 46 | fMaxSize(-1), |
47 | fFS(""), | |
48 | fDeleteFiles(kFALSE) | |
a197a4ce | 49 | { |
50 | // Create tag DB. | |
51 | ||
e10815f1 | 52 | if (fileName) { |
53 | if (!Create(fileName)) | |
a197a4ce | 54 | MakeZombie(); |
55 | } | |
56 | } | |
57 | ||
a197a4ce | 58 | //______________________________________________________________________________ |
e10815f1 | 59 | Bool_t AliTagDB::Create(const char* fileName) |
a197a4ce | 60 | { |
61 | // Create a new tag DB. | |
62 | ||
e10815f1 | 63 | const char *name = fileName; |
64 | if (!name) name = GetFileName(); | |
65 | fTagDB = new TFile(name, "RECREATE", | |
ee8f2a6c | 66 | Form("ALICE tag DB (%s)", AliRawDB::GetAliRootTag()), 1); |
a197a4ce | 67 | if (fTagDB->IsZombie()) { |
68 | Error("Create", "error opening tag DB"); | |
69 | fTagDB = 0; | |
70 | return kFALSE; | |
71 | } | |
f07ec911 | 72 | // Put wide read-write permissions |
73 | if(gSystem->Chmod(name,438)) { | |
74 | Error("Create", "can't set permissions for tag DB file"); | |
75 | fTagDB = 0; | |
76 | return kFALSE; | |
77 | } | |
a197a4ce | 78 | |
79 | // Create ROOT Tree object container | |
54dd2271 | 80 | fTree = new TTree("T", Form("ALICE raw-data tag tree (%s)", AliRawDB::GetAliRootTag())); |
a197a4ce | 81 | fTree->SetAutoSave(100000000); // autosave when 100 Mbyte written |
82 | ||
83 | Int_t bufsize = 32000; | |
84 | Int_t split = 1; | |
54dd2271 | 85 | const char *tagname = fEventTag->GetName(); |
86 | fTree->Branch("TAG", tagname, &fEventTag, bufsize, split); | |
a197a4ce | 87 | |
88 | return kTRUE; | |
89 | } | |
90 | ||
91 | //______________________________________________________________________________ | |
92 | void AliTagDB::Close() | |
93 | { | |
94 | // Close tag DB. | |
95 | ||
96 | if (!fTagDB) return; | |
97 | ||
98 | fTagDB->cd(); | |
99 | ||
100 | // Write the tree. | |
101 | fTree->Write(); | |
102 | ||
103 | // Close DB, this also deletes the fTree | |
104 | fTagDB->Close(); | |
105 | ||
e10815f1 | 106 | if (fDeleteFiles) |
a197a4ce | 107 | gSystem->Unlink(fTagDB->GetName()); |
108 | ||
109 | delete fTagDB; | |
110 | fTagDB = 0; | |
111 | } | |
112 | ||
113 | //______________________________________________________________________________ | |
e10815f1 | 114 | Bool_t AliTagDB::NextFile(const char* fileName) |
a197a4ce | 115 | { |
116 | // Close te current file and open a new one. | |
117 | // Returns kFALSE in case opening failed. | |
118 | ||
119 | Close(); | |
120 | ||
e10815f1 | 121 | if (!Create(fileName)) return kFALSE; |
a197a4ce | 122 | return kTRUE; |
123 | } | |
124 | ||
e10815f1 | 125 | //______________________________________________________________________________ |
126 | void AliTagDB::SetFS(const char* fs) | |
127 | { | |
128 | // set the file system location | |
129 | ||
130 | fFS = fs; | |
131 | if (fs) { | |
132 | gSystem->ResetErrno(); | |
133 | gSystem->MakeDirectory(fs); | |
134 | if (gSystem->GetErrno() && gSystem->GetErrno() != EEXIST) { | |
135 | SysError("SetFS", "mkdir %s", fs); | |
136 | } | |
137 | } | |
138 | } | |
139 | ||
a197a4ce | 140 | //______________________________________________________________________________ |
141 | Float_t AliTagDB::GetCompressionFactor() const | |
142 | { | |
143 | // Return compression factor. | |
144 | ||
145 | if (fTree->GetZipBytes() == 0.) | |
146 | return 1.0; | |
147 | else | |
148 | return fTree->GetTotBytes()/fTree->GetZipBytes(); | |
149 | } | |
150 | ||
151 | //______________________________________________________________________________ | |
152 | const char *AliTagDB::GetFileName() const | |
153 | { | |
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. | |
156 | ||
157 | static char fname[64]; | |
e10815f1 | 158 | const char *fs = fFS; |
a197a4ce | 159 | |
160 | // check that fs exists (crude check fails if fs is a file) | |
161 | gSystem->MakeDirectory(fs); | |
162 | ||
54dd2271 | 163 | // Get the run number |
164 | Int_t runNumber = -1; | |
165 | if (fEventTag) { | |
166 | AliRawEventHeaderBase *header = fEventTag->GetHeader(); | |
167 | if (header) runNumber = header->Get("RunNb"); | |
168 | } | |
a197a4ce | 169 | |
54dd2271 | 170 | char hostname[64]; |
a197a4ce | 171 | strcpy(hostname, gSystem->HostName()); |
172 | ||
173 | char *s; | |
174 | if ((s = strchr(hostname, '.'))) | |
54dd2271 | 175 | *s = 0; |
a197a4ce | 176 | |
54dd2271 | 177 | TTimeStamp ts; |
a197a4ce | 178 | |
54dd2271 | 179 | sprintf(fname, "%s/Run%d.%s_%d_%d_%d.RAW.tag.root", fs, runNumber, hostname, |
180 | ts.GetDate(), ts.GetTime(), ts.GetNanoSec()); | |
a197a4ce | 181 | |
182 | return fname; | |
183 | } |