]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RAW/AliTagDB.cxx
Using AliLog (F.Carminati)
[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 "AliRawEventHeader.h"
33 #include "AliTagDB.h"
34
35
36 ClassImp(AliTagDB)
37
38
39 //______________________________________________________________________________
40 AliTagDB::AliTagDB(AliRawEventHeader *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 AliTagDB::AliTagDB(const AliTagDB& tagDB): TObject(tagDB)
58 {
59 // copy constructor
60
61   Fatal("AliTagDB", "copy constructor not implemented");
62 }
63
64 //______________________________________________________________________________
65 AliTagDB& AliTagDB::operator = (const AliTagDB& /*tagDB*/)
66 {
67 // assignment operator
68
69   Fatal("operator =", "assignment operator not implemented");
70   return *this;
71 }
72
73 //______________________________________________________________________________
74 Bool_t AliTagDB::Create(const char* fileName)
75 {
76    // Create a new tag DB.
77
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);
82    if (fTagDB->IsZombie()) {
83       Error("Create", "error opening tag DB");
84       fTagDB = 0;
85       return kFALSE;
86    }
87    // Put wide read-write permissions
88    if(gSystem->Chmod(name,438)) {
89      Error("Create", "can't set permissions for tag DB file");
90      fTagDB = 0;
91      return kFALSE;
92    }
93
94    // Create ROOT Tree object container
95    fTree = new TTree("TAG", Form("ALICE MDC%d header data tree", AliRawDB::kMDC));
96    fTree->SetAutoSave(100000000);  // autosave when 100 Mbyte written
97
98    Int_t bufsize = 32000;
99    Int_t split   = 1;
100    fTree->Branch("header", "AliRawEventHeader", &fHeader, bufsize, split);
101
102    return kTRUE;
103 }
104
105 //______________________________________________________________________________
106 void 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
120    if (fDeleteFiles)
121       gSystem->Unlink(fTagDB->GetName());
122
123    delete fTagDB;
124    fTagDB = 0;
125 }
126
127 //______________________________________________________________________________
128 Bool_t AliTagDB::NextFile(const char* fileName)
129 {
130    // Close te current file and open a new one.
131    // Returns kFALSE in case opening failed.
132
133    Close();
134
135    if (!Create(fileName)) return kFALSE;
136    return kTRUE;
137 }
138
139 //______________________________________________________________________________
140 void 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
154 //______________________________________________________________________________
155 Float_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 //______________________________________________________________________________
166 const 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
171    static char fname[64];
172    const char *fs = fFS;
173
174    // check that fs exists (crude check fails if fs is a file)
175    gSystem->MakeDirectory(fs);
176
177    char hostname[64];
178
179    strcpy(hostname, gSystem->HostName());
180
181    char *s;
182    if ((s = strchr(hostname, '.')))
183       *s = 0;
184
185    TDatime dt;
186
187    sprintf(fname, "%s/%s_%d_%d.root", fs, hostname, dt.GetDate(), dt.GetTime());
188
189    return fname;
190 }