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