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