Fix
[u/mrichter/AliRoot.git] / RAW / AliRawRFIODB.cxx
CommitLineData
d04aea32 1// @(#) $Id$
a197a4ce 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// AliRawRFIODB //
22// //
23//////////////////////////////////////////////////////////////////////////
24
25#include <TSystem.h>
26#include <TUrl.h>
27
a197a4ce 28#include "AliRawRFIODB.h"
29
30
31ClassImp(AliRawRFIODB)
32
33
34//______________________________________________________________________________
33314186 35AliRawRFIODB::AliRawRFIODB(AliRawEventV2 *event,
af885e0f 36 AliESDEvent *esd,
e10815f1 37 Int_t compress,
8ec37122 38 const char* fileName,Int_t basketsize)
39 : AliRawDB(event, esd, compress, fileName, basketsize)
a197a4ce 40{
41 // Create a new raw DB that will be accessed via RFIO.
42
a197a4ce 43 static int init = 0;
44 // Set STAGE_POOL environment variable to current host
45 if (!init) {
46 // THESE ENVIRONMENT SYMBOLS ARE NOW DEFINED BY THE ALICE DATE SETUP
47 // THEREFORE WE SHALL NOT USE ANY HARDCODED VALUES BUT RATHER USE
48 // WHATEVER HAS BEEN SET IN THE DATE SITE
49 //gSystem->Setenv("STAGE_POOL", "lcg00");
50 //gSystem->Setenv("STAGE_HOST", "stage013");
51
52 // however for sanity we check if they are really set
53 if (!gSystem->Getenv("STAGE_POOL"))
54 Error("AliRawRFIODB", "STAGE_POOL not set");
55 if (!gSystem->Getenv("STAGE_HOST"))
56 Error("AliRawRFIODB", "STAGE_HOST not set");
57 init = 1;
58 }
33ebe062 59#if ROOT_VERSION_CODE < ROOT_VERSION(5,99,0)
e10815f1 60 if (fRawDB) fRawDB->UseCache(50, 0x200000); //0x100000 = 1MB)
33ebe062 61#endif
a197a4ce 62}
63
64//______________________________________________________________________________
65const char *AliRawRFIODB::GetFileName() const
66{
67 // Return filename based on hostname and date and time. This will make
68 // each file unique. Also the directory will be made unique for each
69 // day by adding the date to the fs. Assumes there is always enough
70 // space on the device.
71
72 static TString fname;
73
e10815f1 74 TString fs = fFS1;
a197a4ce 75 TDatime dt;
76
77 // make a new subdirectory for each day
78 fs += "/adc-";
79 fs += dt.GetDate();
80
81 Long_t id, size, flags, time;
82 if (gSystem->GetPathInfo(fs, &id, &size, &flags, &time) == 1) {
83 // directory does not exist, create it
84 if (gSystem->mkdir(fs, kTRUE) == -1) {
85 Error("GetFileName", "cannot create dir %s, using %s", fs.Data(),
e10815f1 86 fFS1.Data());
87 fs = fFS1;
a197a4ce 88 }
89 }
90 // FIXME: should check if fs is a directory
91
92 TString hostname = gSystem->HostName();
93 Int_t pos;
94 if ((pos = hostname.Index(".")) != kNPOS)
95 hostname.Remove(pos);
96
97 fname = fs + "/" + hostname + "_";
98 fname += dt.GetDate();
99 fname += "_";
100 fname += dt.GetTime();
101 fname += ".root";
102
103 return fname;
104}
105
106//______________________________________________________________________________
d2450633 107Long64_t AliRawRFIODB::Close()
a197a4ce 108{
109 // Close raw RFIO DB.
110
f07ec911 111 if (!fRawDB) return 0;
112
113 if (!fRawDB->IsOpen()) return 0;
a197a4ce 114
115 fRawDB->cd();
116
117 // Write the tree.
f07ec911 118 Bool_t error = kFALSE;
33314186 119 if (fTree)
120 if (fTree->Write() == 0)
121 error = kTRUE;
f07ec911 122 if (fESDTree)
123 if (fESDTree->Write() == 0)
124 error = kTRUE;
a197a4ce 125
126 // Close DB, this also deletes the fTree
127 fRawDB->Close();
128
33314186 129 fTree = NULL;
130
d2450633 131 Long64_t filesize = fRawDB->GetEND();
f07ec911 132
e10815f1 133 if (fDeleteFiles) {
a197a4ce 134 TUrl u(fRawDB->GetName());
135 gSystem->Exec(Form("rfrm %s", u.GetFile()));
136 }
137
138 delete fRawDB;
139 fRawDB = 0;
f07ec911 140
141 if(!error)
142 return filesize;
143 else
144 return -1;
a197a4ce 145}