]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RAW/AliRawCastorDB.cxx
fix coding convention violations
[u/mrichter/AliRoot.git] / RAW / AliRawCastorDB.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 // AliRawCastorDB                                                       //
22 //                                                                      //
23 //////////////////////////////////////////////////////////////////////////
24
25 #include <TSystem.h>
26 #include <TUrl.h>
27
28 #include "AliMDC.h"
29
30 #include "AliRawCastorDB.h"
31
32
33 ClassImp(AliRawCastorDB)
34
35
36 //______________________________________________________________________________
37 AliRawCastorDB::AliRawCastorDB(AliRawEvent *event, Double_t maxsize, Int_t compress)
38    : AliRawDB(event, maxsize, compress, kFALSE)
39 {
40    // Create a new raw DB that will be accessed via CASTOR and rootd.
41
42 #ifndef USE_RDM
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    }
59 #endif
60
61    if (!Create())
62       MakeZombie();
63    else
64       fRawDB->UseCache(50, 0x200000);  //0x100000 = 1MB)
65 }
66
67 //______________________________________________________________________________
68 const char *AliRawCastorDB::GetFileName() const
69 {
70    // Return filename based on hostname and date and time. This will make
71    // each file unique. Also the directory will be made unique for each
72    // day by adding the date to the fs. Assumes there is always enough
73    // space on the device.
74
75    static TString fname;
76
77    TString fs  = AliMDC::CastorFS();
78    TString fsr = AliMDC::RFIOFS();
79    TDatime dt;
80
81    // make a new subdirectory for each day
82    fs += "/adc-";
83    fs += dt.GetDate();
84
85    fsr += "/adc-";
86    fsr += dt.GetDate();
87
88    Long_t id, size, flags, time;
89    if (gSystem->GetPathInfo(fsr, &id, &size, &flags, &time) == 1) {
90       // directory does not exist, create it
91       if (gSystem->mkdir(fsr, kTRUE) == -1) {
92          Error("GetFileName", "cannot create dir %s, using %s", fsr.Data(),
93                AliMDC::RFIOFS());
94          fs = AliMDC::CastorFS();
95       }
96    }
97    // FIXME: should check if fs is a directory
98
99    TString hostname = gSystem->HostName();
100    Int_t pos;
101    if ((pos = hostname.Index(".")) != kNPOS)
102       hostname.Remove(pos);
103
104    fname = fs + "/" + hostname + "_";
105    fname += dt.GetDate();
106    fname += "_";
107    fname += dt.GetTime();
108    fname += ".root";
109
110    return fname;
111 }
112
113 //______________________________________________________________________________
114 void AliRawCastorDB::Close()
115 {
116    // Close raw CASTOR/rootd DB.
117
118    if (!fRawDB) return;
119
120    fRawDB->cd();
121
122    // Write the tree.
123    fTree->Write();
124
125    // Close DB, this also deletes the fTree
126    fRawDB->Close();
127
128    if (AliMDC::DeleteFiles()) {
129       TUrl u(fRawDB->GetName());
130       gSystem->Exec(Form("rfrm %s", u.GetFile()));
131    }
132
133    delete fRawDB;
134    fRawDB = 0;
135 }