]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RAW/AliTagDB.cxx
Better selection between menus
[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 #include <TTimeStamp.h>
29
30 #include "AliESD.h"
31
32 #include "AliRawDB.h"
33 #include "AliRawEventTag.h"
34 #include "AliTagDB.h"
35 #include "AliRawEventHeaderBase.h"
36
37
38 ClassImp(AliTagDB)
39
40
41 //______________________________________________________________________________
42 AliTagDB::AliTagDB(AliRawEventTag *eventTag, const char* fileName) :
43   fTagDB(NULL),
44   fTree(NULL),
45   fEventTag(eventTag),
46   fMaxSize(-1),
47   fFS(""),
48   fDeleteFiles(kFALSE)
49 {
50    // Create tag DB.
51
52    if (fileName) {
53       if (!Create(fileName))
54          MakeZombie();
55    }
56 }
57
58 //______________________________________________________________________________
59 Bool_t AliTagDB::Create(const char* fileName)
60 {
61    // Create a new tag DB.
62
63    const char *name = fileName;
64    if (!name) name = GetFileName();
65    fTagDB = new TFile(name, "RECREATE",
66                       Form("ALICE tag DB (%s)", AliRawDB::GetAliRootTag()), 1);
67    if (fTagDB->IsZombie()) {
68       Error("Create", "error opening tag DB");
69       fTagDB = 0;
70       return kFALSE;
71    }
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    }
78
79    // Create ROOT Tree object container
80    fTree = new TTree("T", Form("ALICE raw-data tag tree (%s)", AliRawDB::GetAliRootTag()));
81    fTree->SetAutoSave(100000000);  // autosave when 100 Mbyte written
82
83    Int_t bufsize = 32000;
84    Int_t split   = 1;
85    const char *tagname = fEventTag->GetName();
86    fTree->Branch("TAG", tagname, &fEventTag, bufsize, split);
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
106    if (fDeleteFiles)
107       gSystem->Unlink(fTagDB->GetName());
108
109    delete fTagDB;
110    fTagDB = 0;
111 }
112
113 //______________________________________________________________________________
114 Bool_t AliTagDB::NextFile(const char* fileName)
115 {
116    // Close te current file and open a new one.
117    // Returns kFALSE in case opening failed.
118
119    Close();
120
121    if (!Create(fileName)) return kFALSE;
122    return kTRUE;
123 }
124
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
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];
158    const char *fs = fFS;
159
160    // check that fs exists (crude check fails if fs is a file)
161    gSystem->MakeDirectory(fs);
162
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    }
169
170    char hostname[64];
171    strcpy(hostname, gSystem->HostName());
172
173    char *s;
174    if ((s = strchr(hostname, '.')))
175      *s = 0;
176
177    TTimeStamp ts;
178
179    sprintf(fname, "%s/Run%d.%s_%d_%d_%d.RAW.tag.root", fs, runNumber, hostname,
180            ts.GetDate(), ts.GetTime(), ts.GetNanoSec());
181
182    return fname;
183 }