34 #include <TObjString.h>
36 #include <Riostream.h>
50 static const TString kHeaderFileName =
"add.h";
51 return kHeaderFileName;
58 static const TString kImplFileName =
"add.cxx";
100 AliDebugStream(2) <<
"ProcessDirectory " << path.Data() << endl;
107 gSystem->Exec(
"ls > /tmp/mpfiles.txt");
109 ifstream mpfiles(
"/tmp/mpfiles.txt");
112 while ( mpfiles >> fileName ) {
113 mpfilesStr += fileName.Data();
117 istringstream mpFilesStream(mpfilesStr.Data());
118 while ( mpFilesStream >> fileName ) {
119 TString filePath = path +
"/" + fileName;
120 if ( gSystem->OpenDirectory(filePath.Data()) )
126 AliDebugStream(2) <<
"ProcessDirectory done " << path.Data() << endl;
137 string fullDataPath = path.Data();
138 string dataPath = fullDataPath;
139 if ( dataPath.find(top) != string::npos ) dataPath.erase(0, top.size()+1);
140 dataPath.erase(0,dataPath.find(
'/')+1);
142 AliDebugStream(2) <<
"Processing file " << dataPath << endl;
145 if ( dataPath.find(
".C") != std::string::npos ||
146 dataPath.find(
".h") != std::string::npos )
return;
148 ifstream input(path.Data(), ios::in);
149 if ( ! input.is_open() ) {
150 cerr <<
"Cannot open input file " << path.Data() << endl;
158 getline(input, line);
159 if ( ! input.eof() ) {
164 while ( ! input.eof() );
166 dataMap->
Add(dataPath, fileString);
177 AliDebugStream(2) <<
"Processing path " << path.Data() << endl;
188 <<
"//_____________________________________________________________________________" << endl
189 <<
"void AliMpDataMap::AddData" <<
fCounter <<
"()" << endl
191 <<
"/// Automatically generated function for data file: " << endl
192 <<
"/// " << path << endl
194 <<
" string path = \"" << path <<
"\";" << endl << endl;
200 <<
" fMap[path] = data;" << endl
210 istringstream in(data.Data());
217 if ( in.eof() )
return;
222 fImplFile << endl <<
" data = data + \"";
227 while ( ! in.eof() );
242 <<
"//_____________________________________________________________________________" << endl
243 <<
"void AliMpDataMap::Fill()" << endl
245 <<
"/// Automatically generated function for calling all generated functions " << endl
249 fImplFile <<
" AddData" << i <<
"();" << endl;
266 TString curDir = gSystem->pwd();
281 const TString& outputDataDir)
285 TString curDir = gSystem->pwd();
288 if ( gSystem->OpenDirectory(outputDataPath.Data()) ) {
290 <<
"Directory " << outputDataPath.Data() <<
" already exists" << endl;
294 AliDebugStream(2) <<
"Making directory " << outputDataPath.Data() << endl;
295 gSystem->mkdir(outputDataPath.Data());
309 const TMap& kMap = dataMap->
GetMap();
312 while ( ( keyObj = it.Next() ) ) {
314 TString tpath = ((TObjString*)keyObj)->String();
316 TObject* dataObj = kMap.GetValue(keyObj);
319 <<
"Cannot find value when iterating over map." << endl;
322 TString tdata = ((TObjString*)dataObj)->String();
324 string path = tpath.Data();
325 string data = tdata.Data();
327 string::size_type slashPos = path.find_last_of(
"/");
328 if ( slashPos != string::npos ) {
329 string dataDir(path, 0, slashPos);
331 = outputDataPath +
"/" + dataDir.c_str();
332 if ( ! gSystem->OpenDirectory(dataDirPath.Data()) ) {
333 AliDebugStream(2) <<
"Making directory " << dataDirPath.Data() << endl;
334 gSystem->mkdir(dataDirPath.Data(), kTRUE);
339 = outputDataPath +
"/" + path.c_str();
341 ofstream out(dataPath.Data(), ios::out);
342 if ( ! out.good() ) {
344 <<
"Cannot open output file " << outputDataPath.Data() << endl;
379 const TMap& kMap = dataMap->
GetMap();
382 while ( ( keyObj = it.Next() ) ) {
384 TString tpath = ((TObjString*)keyObj)->String();
386 TObject* dataObj = kMap.GetValue(keyObj);
389 <<
"Cannot find value when iterating over map." << endl;
392 TString tdata = ((TObjString*)dataObj)->String();
virtual ~AliMpDataProcessor()
AliMpDataMap * CreateDataMap(const TString &dataDir="data")
void GenerateFunction(const TString &path, const TString &data)
void ProcessDirectory(const TString &path, AliMpDataMap *map)
void GenerateFileCode(const TString &path)
ofstream fHeaderFile
header file
static const TString & GetImplFileName()
ofstream fImplFile
implementation file
const TMap & GetMap() const
Return the map constant reference.
Int_t fCounter
data files counter
TObject class containing a map of strings to strings.
void ProcessFile(const TString &path, AliMpDataMap *map)
Bool_t GenerateData(AliMpDataMap *dataMap, const TString &outputDataDir="data_new")
static const TString & GetHeaderFileName()
void Add(const TString &path, const TString &data)
Bool_t GenerateCode(AliMpDataMap *dataMap)