1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 // $MpId: AliMpDataStreams.cxx,v 1.12 2006/05/23 13:09:54 ivana Exp $
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 //-----------------------------------------------------------------------------
28 #include "AliMpDataStreams.h"
29 #include "AliMpDataMap.h"
30 #include "AliMpFiles.h"
36 #include <TObjString.h>
38 #include <Riostream.h>
43 ClassImp(AliMpDataStreams)
47 //______________________________________________________________________________
48 AliMpDataStreams::AliMpDataStreams(AliMpDataMap* map)
53 /// Standard and default constructor
55 if ( map ) fReadFromFiles = kFALSE;
58 //______________________________________________________________________________
59 AliMpDataStreams::AliMpDataStreams(TRootIOCtor* /*ioCtor*/)
64 /// Root IO constructor
68 //______________________________________________________________________________
69 AliMpDataStreams::~AliMpDataStreams()
74 // Do not delete data map as it is a CDB object
82 //______________________________________________________________________________
83 void AliMpDataStreams::CutDataPath(string& dataPath) const
85 /// Cut the path defined in AliMpFiles as Top() + one more directory
87 string top = AliMpFiles::GetTop().Data();
88 if ( dataPath.find(top) != string::npos ) dataPath.erase(0, top.size()+1);
89 dataPath.erase(0,dataPath.find('/')+1);
98 //______________________________________________________________________________
99 istream& AliMpDataStreams::CreateDataStream(const TString& path) const
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.
106 if ( fReadFromFiles ) {
107 AliDebugStream(2) << "Opening file " << path.Data() << endl;
108 ifstream* fileBuffer = new ifstream();
109 fileBuffer->open(path.Data());
110 if ( ! fileBuffer->good() ) {
112 << "Cannot open file " << path.Data() << endl;
117 AliDebugStream(2) << "Opening stream " << path.Data() << endl;
119 // Cut top from the path
120 string dataPath = path.Data();
121 CutDataPath(dataPath);
123 istringstream* stringBuffer
124 = new istringstream(fMap->Get(dataPath).Data());
125 return *stringBuffer;
129 //______________________________________________________________________________
130 Bool_t AliMpDataStreams::IsDataStream(const TString& path) const
132 /// Return true, if data with given path exists
134 if ( fReadFromFiles ) {
135 ifstream fileBuffer(path.Data());
136 return fileBuffer.good();
139 // Cut top from the path
140 string dataPath = path.Data();
141 CutDataPath(dataPath);
143 return ( fMap->Get(dataPath, kFALSE) != "" );
147 //______________________________________________________________________________
148 void AliMpDataStreams::SetReadFromFiles()
150 /// Set option to read data from files
152 fReadFromFiles = kTRUE;
155 //______________________________________________________________________________
156 Bool_t AliMpDataStreams::GetReadFromFiles() const
158 /// Return the info where the data are loaded from
160 return fReadFromFiles;