LCOV - code coverage report
Current view: top level - RAW/MDC - AliTagDB.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 56 75 74.7 %
Date: 2016-06-14 17:26:59 Functions: 8 10 80.0 %

          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             : // AliTagDB                                                             //
      22             : //                                                                      //
      23             : //////////////////////////////////////////////////////////////////////////
      24             : 
      25             : #include <errno.h>
      26             : 
      27             : #include <TSystem.h>
      28             : #include <TTimeStamp.h>
      29             : #include <TBranch.h>
      30             : 
      31             : #include "AliESD.h"
      32             : 
      33             : #include "AliRawDB.h"
      34             : #include "AliRawEventTag.h"
      35             : #include "AliTagDB.h"
      36             : #include "AliRawEventHeaderBase.h"
      37             : 
      38             : 
      39           2 : ClassImp(AliTagDB)
      40             : 
      41             : 
      42             : //______________________________________________________________________________
      43           1 : AliTagDB::AliTagDB(AliRawEventTag *eventTag, const char* fileName) :
      44           1 :   fTagDB(NULL),
      45           1 :   fTree(NULL),
      46           1 :   fEventTag(eventTag),
      47           1 :   fMaxSize(-1),
      48           1 :   fFS(""),
      49           1 :   fDeleteFiles(kFALSE)
      50           5 : {
      51             :    // Create tag DB.
      52             : 
      53           1 :    if (fileName) {
      54           0 :       if (!Create(fileName))
      55           0 :          MakeZombie();
      56             :    }
      57           2 : }
      58             : 
      59             : static void BranchResetBit(TBranch *b) 
      60             : {
      61             :   // Reset MapObject on this branch and all the sub-branches
      62             : 
      63          10 :   b->ResetBit( kBranchObject | kBranchAny ); // Or in newer ROOT: b->ResetBit( kMapObject )
      64           5 :   TIter next( b->GetListOfBranches() );
      65             :   TBranch *sub = 0;
      66          23 :   while ( (sub = (TBranch*)next() ) ) {
      67           4 :     BranchResetBit( sub );
      68             :   }
      69           5 : }
      70             : 
      71             : //______________________________________________________________________________
      72             : Bool_t AliTagDB::Create(const char* fileName)
      73             : {
      74             :    // Create a new tag DB.
      75             : 
      76             :    const char *name = fileName;
      77           3 :    if (!name) name = GetFileName();
      78           3 :    fTagDB = new TFile(name, "RECREATE",
      79           2 :                       Form("ALICE tag DB (%s)", AliRawDB::GetAliRootTag()), 1);
      80           1 :    if (fTagDB->IsZombie()) {
      81           0 :       Error("Create", "error opening tag DB");
      82           0 :       fTagDB = 0;
      83           0 :       return kFALSE;
      84             :    }
      85             :    // Put wide read-write permissions
      86           1 :    if(gSystem->Chmod(name,438)) {
      87           0 :      Error("Create", "can't set permissions for tag DB file");
      88           0 :      fTagDB = 0;
      89           0 :      return kFALSE;
      90             :    }
      91             : 
      92             :    // Create ROOT Tree object container
      93           4 :    fTree = new TTree("T", Form("ALICE raw-data tag tree (%s)", AliRawDB::GetAliRootTag()));
      94           1 :    fTree->SetAutoSave(100000000);  // autosave when 100 Mbyte written
      95             : 
      96             :    Int_t bufsize = 32000;
      97             :    Int_t split   = 1;
      98           1 :    const char *tagname = fEventTag->GetName();
      99           1 :    TBranch * b = fTree->Branch("TAG", tagname, &fEventTag, bufsize, split);
     100           1 :    BranchResetBit(b);
     101             : 
     102             :    return kTRUE;
     103           1 : }
     104             : 
     105             : //______________________________________________________________________________
     106             : void AliTagDB::Close()
     107             : {
     108             :    // Close tag DB.
     109             : 
     110           2 :    if (!fTagDB) return;
     111             : 
     112           1 :    fTagDB->cd();
     113             : 
     114             :    // Write the tree.
     115           1 :    fTree->Write();
     116             : 
     117             :    // Close DB, this also deletes the fTree
     118           1 :    fTagDB->Close();
     119             : 
     120           1 :    if (fDeleteFiles)
     121           0 :       gSystem->Unlink(fTagDB->GetName());
     122             : 
     123           2 :    delete fTagDB;
     124           1 :    fTagDB = 0;
     125           2 : }
     126             : 
     127             : //______________________________________________________________________________
     128             : Bool_t AliTagDB::NextFile(const char* fileName)
     129             : {
     130             :    // Close te current file and open a new one.
     131             :    // Returns kFALSE in case opening failed.
     132             : 
     133           0 :    Close();
     134             : 
     135           0 :    if (!Create(fileName)) return kFALSE;
     136           0 :    return kTRUE;
     137           0 : }
     138             : 
     139             : //______________________________________________________________________________
     140             : void AliTagDB::SetFS(const char* fs)
     141             : {
     142             : // set the file system location
     143             : 
     144           2 :   fFS = fs;
     145           1 :   if (fs) {
     146           1 :     gSystem->ResetErrno();
     147           1 :     gSystem->MakeDirectory(fs);
     148           2 :     if (gSystem->GetErrno() && gSystem->GetErrno() != EEXIST) {
     149           0 :       SysError("SetFS", "mkdir %s", fs);
     150           0 :     }
     151             :   }
     152           1 : }
     153             : 
     154             : //______________________________________________________________________________
     155             : Float_t AliTagDB::GetCompressionFactor() const
     156             : {
     157             :    // Return compression factor.
     158             : 
     159           0 :    if (fTree->GetZipBytes() == 0.)
     160           0 :       return 1.0;
     161             :    else
     162           0 :       return fTree->GetTotBytes()/fTree->GetZipBytes();
     163           0 : }
     164             : 
     165             : //______________________________________________________________________________
     166             : const char *AliTagDB::GetFileName() const
     167             : {
     168             :    // Return filename based on hostname and date and time. This will make
     169             :    // each file unique. The tags will be stored in the /data1/tags directory.
     170             : 
     171           5 :    static TString fname;
     172           1 :    const char *fs = fFS;
     173             : 
     174             :    // check that fs exists (crude check fails if fs is a file)
     175           1 :    gSystem->MakeDirectory(fs);
     176             : 
     177             :    // Get the run number
     178             :    Int_t runNumber = -1;
     179           1 :    if (fEventTag) {
     180           1 :      AliRawEventHeaderBase *header = fEventTag->GetHeader();
     181           2 :      if (header) runNumber = header->Get("RunNb");
     182           1 :    }
     183             : 
     184           1 :    TString hostname;
     185           2 :    hostname.Form("%s",gSystem->HostName());
     186           4 :    if ( hostname.First('.') > 0 ) hostname.Resize(hostname.First('.'));
     187             : 
     188           1 :    TTimeStamp ts;
     189             : 
     190           2 :    fname.Form("%s/Run%d.%s_%d_%d_%d.RAW.tag.root", fs, runNumber, hostname.Data(),
     191           3 :               ts.GetDate(), ts.GetTime(), ts.GetNanoSec());
     192             : 
     193           1 :    return fname.Data();
     194           1 : }

Generated by: LCOV version 1.11