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