Line data Source code
1 : // @(#) $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 "AliRawCastorDB.h"
29 :
30 :
31 2 : ClassImp(AliRawCastorDB)
32 :
33 :
34 : //______________________________________________________________________________
35 : AliRawCastorDB::AliRawCastorDB(AliRawEventV2 *event,
36 : AliESDEvent *esd,
37 : Int_t compress,
38 : const char* fileName,Int_t basketsize, Long64_t autoflush)
39 0 : : AliRawDB(event, esd, compress, fileName, basketsize, autoflush)
40 0 : {
41 : // Create a new raw DB that will be accessed via CASTOR and rootd.
42 :
43 : static int init = 0;
44 0 : if (!init) {
45 : // THESE ENVIRONMENT VARIABLES ARE IN PRINCIPLE HARDCODED IN
46 : // THE CASTOR CLIENT LIBRARY
47 : // however for sanity we check if they are set by the user
48 0 : if (!gSystem->Getenv("RH_HOST"))
49 0 : Error("AliRawRFIODB", "RH_HOST not set");
50 0 : if (!gSystem->Getenv("SVCCLASS"))
51 0 : Error("AliRawRFIODB", "SVCCLASS not set");
52 0 : init = 1;
53 0 : }
54 :
55 : #if ROOT_VERSION_CODE < ROOT_VERSION(5,99,0)
56 0 : if (fRawDB) fRawDB->UseCache(50, 0x200000); //0x100000 = 1MB)
57 : #endif
58 0 : }
59 :
60 : //______________________________________________________________________________
61 : const char *AliRawCastorDB::GetFileName() const
62 : {
63 : // Return filename based on hostname and date and time. This will make
64 : // each file unique. Also the directory will be made unique for each
65 : // day by adding the date to the fs. Assumes there is always enough
66 : // space on the device.
67 :
68 0 : static TString fname;
69 :
70 0 : TString fs = fFS1;
71 0 : TString fsr = fs;
72 0 : fsr.ReplaceAll("castor:", "rfio:");
73 0 : TDatime dt;
74 :
75 : // make a new subdirectory for each day
76 0 : fs += "/adc-";
77 0 : fs += dt.GetDate();
78 :
79 0 : fsr += "/adc-";
80 0 : fsr += dt.GetDate();
81 :
82 0 : Long_t id, size, flags, time;
83 0 : if (gSystem->GetPathInfo(fsr, &id, &size, &flags, &time) == 1) {
84 : // directory does not exist, create it
85 0 : if (gSystem->mkdir(fsr, kTRUE) == -1) {
86 0 : Error("GetFileName", "cannot create dir %s, using %s", fsr.Data(),
87 0 : fFS1.Data());
88 0 : fs = fFS1;
89 : }
90 : }
91 : // FIXME: should check if fs is a directory
92 :
93 0 : TString hostname = gSystem->HostName();
94 : Int_t pos;
95 0 : if ((pos = hostname.Index(".")) != kNPOS)
96 0 : hostname.Remove(pos);
97 :
98 0 : fname = fs + "/" + hostname + "_";
99 0 : fname += dt.GetDate();
100 0 : fname += "_";
101 0 : fname += dt.GetTime();
102 0 : fname += ".root";
103 :
104 0 : return fname;
105 0 : }
106 :
107 : //______________________________________________________________________________
108 : Long64_t AliRawCastorDB::Close()
109 : {
110 : // Close raw CASTOR/rootd DB.
111 :
112 0 : if (!fRawDB) return 0;
113 :
114 0 : if (!fRawDB->IsOpen()) return 0;
115 :
116 0 : fRawDB->cd();
117 :
118 : // Write the tree.
119 : Bool_t error = kFALSE;
120 0 : if (fTree)
121 0 : if (fTree->Write() == 0)
122 0 : error = kTRUE;
123 0 : if (fESDTree)
124 0 : if (fESDTree->Write() == 0)
125 0 : error = kTRUE;
126 :
127 : // Close DB, this also deletes the fTree
128 0 : fRawDB->Close();
129 :
130 0 : fTree = NULL;
131 :
132 0 : Long64_t filesize = fRawDB->GetEND();
133 :
134 0 : if (fDeleteFiles) {
135 0 : TUrl u(fRawDB->GetName());
136 0 : gSystem->Exec(Form("rfrm %s", u.GetFile()));
137 0 : }
138 :
139 0 : delete fRawDB;
140 0 : fRawDB = 0;
141 :
142 0 : if(!error)
143 0 : return filesize;
144 : else
145 0 : return -1;
146 0 : }
|