// ************************************************************************** // This file is property of and copyright by the ALICE HLT Project * // ALICE Experiment at CERN, All rights reserved. * // * // Primary Authors: Sergey Gorbunov * // Ivan Kisel * // for The ALICE HLT Project. * // * // Developed by: Maksym Zyzak * // * // Permission to use, copy, modify and distribute this software and its * // documentation strictly for non-commercial purposes is hereby granted * // without fee, provided that the above copyright notice appears in all * // copies and that both the copyright notice and this permission notice * // appear in the supporting documentation. The authors make no claims * // about the suitability of this software for any purpose. It is * // provided "as is" without express or implied warranty. * // * //*************************************************************************** #include "KFPHistogram/KFPHistogram.h" #include "KFTopoPerformance.h" #include #include #include #include #include using namespace std; #ifndef HLTCA_STANDALONE #include "TStopwatch.h" typedef TStopwatch Stopwatch; #else #include "Stopwatch.h" #endif #include "TFile.h" #include "TDirectory.h" #include "dirent.h" void ReadDirectory(string prefix, KFPHistogram& histograms) { DIR* currentDir = 0; dirent *ent; currentDir = opendir(prefix.data()); if(!currentDir) { std::cout << "Error: \"" << prefix.data() << "\" is not a directory." << std::endl; return; } KFPHistogram tmpHisto; while ((ent = readdir (currentDir)) != NULL) { std::string name(ent->d_name); std::string nameCheck = "KFPHistogram"; std::string curdir = "."; std::string upperdir = ".."; if(name == curdir || name == upperdir) continue; std::string newPrefix = prefix; newPrefix += "/"; newPrefix += ent->d_name; int nameLength = strlen(ent->d_name); if(nameLength < 10) ReadDirectory(newPrefix, histograms); if(nameLength >= 10) { std::size_t found = name.find(nameCheck); if( (found!=std::string::npos) && ent->d_name[nameLength-4] == '.' && ent->d_name[nameLength-3] == 't' && ent->d_name[nameLength-2] == 'x' && ent->d_name[nameLength-1] == 't' ) { std::cout << newPrefix << std::endl; if (!tmpHisto.FillFromFile(newPrefix)) { cout << "Data from File \"" << newPrefix.data() << "\" can't be read." << std::endl; continue; } histograms += tmpHisto; } else ReadDirectory(newPrefix, histograms); } } closedir(currentDir); } void SaveFile( TObject *obj ) { //* recursive function to write down all created in the file histos if ( !obj->IsFolder() ) obj->Write(); else { TDirectory *cur = gDirectory; ((TDirectory*)obj)->cd(); TList *listSub = ( ( TDirectory* )obj )->GetList(); TIter it( listSub ); while ( TObject *obj1 = it() ) SaveFile( obj1 ); cur->cd(); } } int main(int argc, char **argv) { string filePrefix = "./KFPHistograms"; for( int i=1; i < argc; i++ ){ if ( !std::strcmp( argv[i], "-h" ) || !std::strcmp( argv[i], "--help" ) || !std::strcmp( argv[i], "-help" ) ) { std::cout << "Please look in readme.txt" << std::endl; return 0; } else if ( !std::strcmp( argv[i], "-dir" ) && ++i < argc ) { filePrefix = argv[i]; } } KFPHistogram histograms; ReadDirectory(filePrefix, histograms); TFile* outFile = new TFile("KFParticlePerformance.root","RECREATE"); KFTopoPerformance topoPerformance; topoPerformance.CreateHistos("KFTopoReconstructor",outFile); topoPerformance.FillHistos(&histograms); SaveFile(outFile); if(outFile) delete outFile; return 0; }