AliRoot Core  edcc906 (edcc906)
AliMpDataStreams.cxx
Go to the documentation of this file.
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 
43 ClassImp(AliMpDataStreams)
45 
46 
47 //______________________________________________________________________________
49  : TObject(),
50  fMap(map),
51  fReadFromFiles(kTRUE)
52 {
54 
55  if ( map ) fReadFromFiles = kFALSE;
56 }
57 
58 //______________________________________________________________________________
59 AliMpDataStreams::AliMpDataStreams(TRootIOCtor* /*ioCtor*/)
60  : TObject(),
61  fMap(0),
62  fReadFromFiles()
63 {
65 
66 }
67 
68 //______________________________________________________________________________
70 {
72 
73  // delete fMap;
74  // Do not delete data map as it is a CDB object
75  // which is cached
76 }
77 
78 //
79 // private methods
80 //
81 
82 //______________________________________________________________________________
83 void AliMpDataStreams::CutDataPath(string& dataPath) const
84 {
86 
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);
90 }
91 
92 
93 
94 //
95 // public methods
96 //
97 
98 //______________________________________________________________________________
99 istream& AliMpDataStreams::CreateDataStream(const TString& path) const
100 {
104 
105 
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() ) {
111  AliErrorStream()
112  << "Cannot open file " << path.Data() << endl;
113  }
114  return *fileBuffer;
115  }
116  else {
117  AliDebugStream(2) << "Opening stream " << path.Data() << endl;
118 
119  // Cut top from the path
120  string dataPath = path.Data();
121  CutDataPath(dataPath);
122 
123  istringstream* stringBuffer
124  = new istringstream(fMap->Get(dataPath).Data());
125  return *stringBuffer;
126  }
127 }
128 
129 //______________________________________________________________________________
130 Bool_t AliMpDataStreams::IsDataStream(const TString& path) const
131 {
133 
134  if ( fReadFromFiles ) {
135  ifstream fileBuffer(path.Data());
136  return fileBuffer.good();
137  }
138  else {
139  // Cut top from the path
140  string dataPath = path.Data();
141  CutDataPath(dataPath);
142 
143  return ( fMap->Get(dataPath, kFALSE) != "" );
144  }
145 }
146 
147 //______________________________________________________________________________
149 {
151 
152  fReadFromFiles = kTRUE;
153 }
154 
155 //______________________________________________________________________________
157 {
159 
160  return fReadFromFiles;
161 }
#define AliErrorStream()
Definition: AliLog.h:630
istream & CreateDataStream(const TString &path) const
void CutDataPath(string &dataPath) const
const char * path
AliMpDataMap * fMap
data map
TString Get(const TString &path, Bool_t warn=kTRUE) const
Bool_t IsDataStream(const TString &path) const
AliMpDataStreams(AliMpDataMap *map=0x0)
virtual ~AliMpDataStreams()
TObject class containing a map of strings to strings.
Definition: AliMpDataMap.h:21
static TString GetTop()
Definition: AliMpFiles.cxx:504
Bool_t fReadFromFiles
option for reading data from files
#define AliDebugStream(level)
Definition: AliLog.h:388
Bool_t GetReadFromFiles() const
Mapping data streams provider.