]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RAW/AliTagDB.cxx
Minor modification related to the new CASTOR stager
[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 "AliRawDB.h"
30
31 #include "AliTagDB.h"
32
33
34 ClassImp(AliTagDB)
35
36
37 //______________________________________________________________________________
38 AliTagDB::AliTagDB(AliRawEventHeader *header, const char* fileName) :
39   fTagDB(NULL),
40   fTree(NULL),
41   fHeader(header),
42   fMaxSize(-1),
43   fFS(""),
44   fDeleteFiles(kFALSE)
45 {
46    // Create tag DB.
47
48    if (fileName) {
49       if (!Create(fileName))
50          MakeZombie();
51    }
52 }
53
54 //______________________________________________________________________________
55 AliTagDB::AliTagDB(const AliTagDB& tagDB): TObject(tagDB)
56 {
57 // copy constructor
58
59   Fatal("AliTagDB", "copy constructor not implemented");
60 }
61
62 //______________________________________________________________________________
63 AliTagDB& AliTagDB::operator = (const AliTagDB& /*tagDB*/)
64 {
65 // assignment operator
66
67   Fatal("operator =", "assignment operator not implemented");
68   return *this;
69 }
70
71 //______________________________________________________________________________
72 Bool_t AliTagDB::Create(const char* fileName)
73 {
74    // Create a new tag DB.
75
76    const char *name = fileName;
77    if (!name) name = GetFileName();
78    fTagDB = new TFile(name, "RECREATE",
79                       Form("ALICE MDC%d tag DB", AliRawDB::kMDC), 1);
80    if (fTagDB->IsZombie()) {
81       Error("Create", "error opening tag DB");
82       fTagDB = 0;
83       return kFALSE;
84    }
85
86    // Create ROOT Tree object container
87    fTree = new TTree("TAG", Form("ALICE MDC%d header data tree", AliRawDB::kMDC));
88    fTree->SetAutoSave(100000000);  // autosave when 100 Mbyte written
89
90    Int_t bufsize = 32000;
91    Int_t split   = 1;
92    fTree->Branch("header", "AliRawEventHeader", &fHeader, bufsize, split);
93
94    return kTRUE;
95 }
96
97 //______________________________________________________________________________
98 void AliTagDB::Close()
99 {
100    // Close tag DB.
101
102    if (!fTagDB) return;
103
104    fTagDB->cd();
105
106    // Write the tree.
107    fTree->Write();
108
109    // Close DB, this also deletes the fTree
110    fTagDB->Close();
111
112    if (fDeleteFiles)
113       gSystem->Unlink(fTagDB->GetName());
114
115    delete fTagDB;
116    fTagDB = 0;
117 }
118
119 //______________________________________________________________________________
120 Bool_t AliTagDB::NextFile(const char* fileName)
121 {
122    // Close te current file and open a new one.
123    // Returns kFALSE in case opening failed.
124
125    Close();
126
127    if (!Create(fileName)) return kFALSE;
128    return kTRUE;
129 }
130
131 //______________________________________________________________________________
132 void AliTagDB::SetFS(const char* fs)
133 {
134 // set the file system location
135
136   fFS = fs;
137   if (fs) {
138     gSystem->ResetErrno();
139     gSystem->MakeDirectory(fs);
140     if (gSystem->GetErrno() && gSystem->GetErrno() != EEXIST) {
141       SysError("SetFS", "mkdir %s", fs);
142     }
143   }
144 }
145
146 //______________________________________________________________________________
147 Float_t AliTagDB::GetCompressionFactor() const
148 {
149    // Return compression factor.
150
151    if (fTree->GetZipBytes() == 0.)
152       return 1.0;
153    else
154       return fTree->GetTotBytes()/fTree->GetZipBytes();
155 }
156
157 //______________________________________________________________________________
158 const char *AliTagDB::GetFileName() const
159 {
160    // Return filename based on hostname and date and time. This will make
161    // each file unique. The tags will be stored in the /data1/tags directory.
162
163    static char fname[64];
164    const char *fs = fFS;
165
166    // check that fs exists (crude check fails if fs is a file)
167    gSystem->MakeDirectory(fs);
168
169    char hostname[64];
170
171    strcpy(hostname, gSystem->HostName());
172
173    char *s;
174    if ((s = strchr(hostname, '.')))
175       *s = 0;
176
177    TDatime dt;
178
179    sprintf(fname, "%s/%s_%d_%d.root", fs, hostname, dt.GetDate(), dt.GetTime());
180
181    return fname;
182 }