]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RAW/AliTagDB.cxx
track matching macros from Alberto
[u/mrichter/AliRoot.git] / RAW / AliTagDB.cxx
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
25 #include <errno.h>
26
27 #include <TSystem.h>
28
29 #include "AliESD.h"
30
31 #include "AliRawDB.h"
32 #include "AliRawEventHeaderBase.h"
33 #include "AliTagDB.h"
34
35
36 ClassImp(AliTagDB)
37
38
39 //______________________________________________________________________________
40 AliTagDB::AliTagDB(AliRawEventHeaderBase *header, const char* fileName) :
41   fTagDB(NULL),
42   fTree(NULL),
43   fHeader(header),
44   fMaxSize(-1),
45   fFS(""),
46   fDeleteFiles(kFALSE)
47 {
48    // Create tag DB.
49
50    if (fileName) {
51       if (!Create(fileName))
52          MakeZombie();
53    }
54 }
55
56 //______________________________________________________________________________
57 Bool_t AliTagDB::Create(const char* fileName)
58 {
59    // Create a new tag DB.
60
61    const char *name = fileName;
62    if (!name) name = GetFileName();
63    fTagDB = new TFile(name, "RECREATE",
64                       Form("ALICE tag DB (%s)", AliRawDB::GetAliRootTag()), 1);
65    if (fTagDB->IsZombie()) {
66       Error("Create", "error opening tag DB");
67       fTagDB = 0;
68       return kFALSE;
69    }
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    }
76
77    // Create ROOT Tree object container
78    fTree = new TTree("TAG", Form("ALICE header data tree (%s)", AliRawDB::GetAliRootTag()));
79    fTree->SetAutoSave(100000000);  // autosave when 100 Mbyte written
80
81    Int_t bufsize = 32000;
82    Int_t split   = 1;
83    const char *headername = fHeader->GetName();
84    fTree->Branch("header", headername, &fHeader, bufsize, split);
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
104    if (fDeleteFiles)
105       gSystem->Unlink(fTagDB->GetName());
106
107    delete fTagDB;
108    fTagDB = 0;
109 }
110
111 //______________________________________________________________________________
112 Bool_t AliTagDB::NextFile(const char* fileName)
113 {
114    // Close te current file and open a new one.
115    // Returns kFALSE in case opening failed.
116
117    Close();
118
119    if (!Create(fileName)) return kFALSE;
120    return kTRUE;
121 }
122
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
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];
156    const char *fs = fFS;
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 }