LCOV - code coverage report
Current view: top level - MUON/MUONmapping - AliMpDataStreams.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 29 46 63.0 %
Date: 2016-06-14 17:26:59 Functions: 9 13 69.2 %

          Line data    Source code
       1             : /**************************************************************************
       2             :  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
       3             :  *                                                                        *
       4             :  * Author: The ALICE Off-line Project.                                    *
       5             :  * Contributors are mentioned in the code where appropriate.              *
       6             :  *                                                                        *
       7             :  * Permission to use, copy, modify and distribute this software and its   *
       8             :  * documentation strictly for non-commercial purposes is hereby granted   *
       9             :  * without fee, provided that the above copyright notice appears in all   *
      10             :  * copies and that both the copyright notice and this permission notice   *
      11             :  * appear in the supporting documentation. The authors make no claims     *
      12             :  * about the suitability of this software for any purpose. It is          *
      13             :  * provided "as is" without express or implied warranty.                  *
      14             :  **************************************************************************/
      15             : 
      16             : // $Id$
      17             : // $MpId: AliMpDataStreams.cxx,v 1.12 2006/05/23 13:09:54 ivana Exp $
      18             : // Category: basic
      19             : 
      20             : //-----------------------------------------------------------------------------
      21             : // Class AliMpDataStreams
      22             : // ----------------------
      23             : // Class for providing mapping data streams
      24             : // See detailed description in the header file.
      25             : // Author: Ivana Hrivnacova; IPN Orsay
      26             : //-----------------------------------------------------------------------------
      27             : 
      28             : #include "AliMpDataStreams.h"
      29             : #include "AliMpDataMap.h"
      30             : #include "AliMpFiles.h"
      31             : 
      32             : #include "AliLog.h"
      33             : 
      34             : #include <TMap.h>
      35             : #include <TFile.h>
      36             : #include <TObjString.h>
      37             : #include <TString.h>
      38             : #include <Riostream.h>
      39             : 
      40             : #include <string>
      41             : 
      42             : /// \cond CLASSIMP
      43          18 : ClassImp(AliMpDataStreams)
      44             : /// \endcond
      45             : 
      46             : 
      47             : //______________________________________________________________________________
      48             : AliMpDataStreams::AliMpDataStreams(AliMpDataMap* map) 
      49           5 :   : TObject(),
      50           5 :     fMap(map),
      51           5 :     fReadFromFiles(kTRUE)
      52          25 : {
      53             : /// Standard and default constructor
      54             : 
      55          10 :   if ( map ) fReadFromFiles = kFALSE;
      56          10 : }
      57             : 
      58             : //______________________________________________________________________________
      59             : AliMpDataStreams::AliMpDataStreams(TRootIOCtor* /*ioCtor*/) 
      60           0 :   : TObject(),
      61           0 :     fMap(0),
      62           0 :     fReadFromFiles()
      63           0 : {
      64             : /// Root IO constructor
      65             : 
      66           0 : }
      67             : 
      68             : //______________________________________________________________________________
      69             : AliMpDataStreams::~AliMpDataStreams() 
      70          10 : {
      71             : /// Destructor
      72             : 
      73             :   // delete fMap;
      74             :        // Do not delete data map as it is a CDB object 
      75             :        // which is cached
      76          15 : }
      77             : 
      78             : //
      79             : // private methods
      80             : //
      81             : 
      82             : //______________________________________________________________________________
      83             : void AliMpDataStreams::CutDataPath(string& dataPath) const
      84             : { 
      85             : /// Cut the path defined in AliMpFiles as Top() + one more directory
      86             : 
      87       35076 :   string top = AliMpFiles::GetTop().Data();
      88       17538 :   if ( dataPath.find(top) != string::npos ) dataPath.erase(0, top.size()+1);
      89        8769 :   dataPath.erase(0,dataPath.find('/')+1); 
      90        8769 : }
      91             :   
      92             : 
      93             : 
      94             : //
      95             : // public methods
      96             : //
      97             : 
      98             : //______________________________________________________________________________
      99             : istream& AliMpDataStreams::CreateDataStream(const TString& path) const
     100             : {
     101             : /// Return the string with data in the mapping file spcified with path.
     102             : /// Both full path in the file system and a short path (without 
     103             : /// $LICE_ROOT/mapping/data string) can be used.
     104             : 
     105             : 
     106       26235 :   if ( fReadFromFiles ) {                                                                
     107        8745 :     AliDebugStream(2) << "Opening file " << path.Data() << endl;
     108           0 :     ifstream* fileBuffer = new ifstream();
     109           0 :     fileBuffer->open(path.Data());
     110           0 :     if ( ! fileBuffer->good() ) {    
     111           0 :        AliErrorStream() 
     112           0 :          << "Cannot open file " << path.Data() << endl;
     113           0 :     }     
     114           0 :     return *fileBuffer;
     115             :   }
     116             :   else {
     117        8745 :     AliDebugStream(2) << "Opening stream " << path.Data() << endl;
     118             : 
     119             :     // Cut top from the path 
     120        8745 :     string dataPath = path.Data();
     121        8745 :     CutDataPath(dataPath);
     122             : 
     123             :     istringstream* stringBuffer 
     124       61215 :       = new istringstream(fMap->Get(dataPath).Data());
     125        8745 :     return *stringBuffer;
     126        8745 :    }    
     127        8745 : }
     128             : 
     129             : //______________________________________________________________________________
     130             : Bool_t  AliMpDataStreams::IsDataStream(const TString& path) const
     131             : {
     132             : /// Return true, if data with given path exists
     133             : 
     134          48 :   if ( fReadFromFiles ) {                                                                
     135           0 :     ifstream fileBuffer(path.Data());
     136           0 :     return fileBuffer.good();
     137           0 :   }
     138             :   else {
     139             :     // Cut top from the path 
     140          24 :     string dataPath = path.Data();
     141          24 :     CutDataPath(dataPath);
     142             : 
     143          96 :     return ( fMap->Get(dataPath, kFALSE) != "" );
     144          24 :   }
     145          24 : }      
     146             : 
     147             : //______________________________________________________________________________
     148             : void  AliMpDataStreams::SetReadFromFiles()
     149             : {
     150             : /// Set option to read data from files
     151             : 
     152           0 :   fReadFromFiles = kTRUE;
     153           0 : }  
     154             : 
     155             : //______________________________________________________________________________
     156             : Bool_t AliMpDataStreams::GetReadFromFiles() const
     157             : { 
     158             : /// Return the info where the data are loaded from
     159             : 
     160          22 :   return fReadFromFiles; 
     161             : }  

Generated by: LCOV version 1.11