#include "myutility.h" #include #include "TClass.h" using namespace std; // Greetings messages TH1D* getHist( TFile* f, string name, bool full ) { TList* l = f -> GetListOfKeys(); if ( !l ) { cout << "[analiticTopics] Error: no keys in file " << f -> GetName() << "." << endl; exit(1); } TIter n( l ); TKey* k; TObject* o; while ( ( k = (TKey*)n() ) ) { o = k -> ReadObj(); vector< string > bn = parseString( o -> GetName() , "_" ); if ( strcmp( o -> IsA() -> GetName(), "TH1D" ) == 0 ) { if( full ) { if ( strcmp( o -> GetName(), name.c_str() ) == 0 ) { cout << "[analiticTopics] Using " << o -> GetName() << "." << endl; return (TH1D*) f -> Get( o -> GetName() ); } } else { if ( strcmp( bn[ bn.size() -1 ].c_str(), name.c_str() ) == 0 ) { cout << "[analiticTopics] Using " << o -> GetName() << "." << endl; return (TH1D*) f -> Get( o -> GetName() ); } } } } cout << "[analiticTopics] Histogram " << name << " not found in file " << f -> GetName() << "." << endl; return NULL; } TProfile* getProf( TFile* f, string name, bool full ) { TList* l = f -> GetListOfKeys(); if ( !l ) { cout << "[analiticTopics] Error: no keys in file " << f -> GetName() << "." << endl; exit(1); } TIter n( l ); TKey* k; TObject* o; while ( ( k = (TKey*)n() ) ) { o = k -> ReadObj(); vector< string > bn = parseString( o -> GetName() , "_" ); if ( strcmp( o -> IsA() -> GetName() , "TProfile" ) == 0 ) { if( full ) { if ( strcmp( o -> GetName(), name.c_str() ) == 0 ) { cout << "[analiticTopics] Using " << o -> GetName() << "." << endl; return (TProfile*) f -> Get( o -> GetName() ); } } else { if ( strcmp( bn[ bn.size() -1 ].c_str(), name.c_str() ) == 0 ) { cout << "[analiticTopics] Using " << o -> GetName() << "." << endl; return (TProfile*) f -> Get( o -> GetName() ); } } } } cout << "[analiticTopics] Histogram " << name << " not found in file " << f -> GetName() << "." << endl; return NULL; } void greetingMessages ( int argc, char* argv[] ) { // Sending 'start of program' message if(argv[1] != NULL && *argv[1] == *"v") cout << "\n------------ Hello! I'm gonna be your program today, and I'm starting! ----------\n" << endl; // Help menu if((argv[1] != NULL && *argv[1] == *"h") || argc < 1){ cout << "\nUsage: ./data.exe\n" << endl; cout << "Example: ./data.exe\n" << endl; exit(0); } } // Goodbyes messages void goodbyeMessages ( clock_t ti, clock_t tf, char* argv[] ) { // Final outputs // Sending 'end of program' message. if(argv[1] != NULL && *argv[1] == *"v") cout << "\n------------ End of Program ----------\n" << endl; // Sending 'runtime' message if(argv[1] != NULL && *argv[1] == *"v") { if ( (tf-ti)/CLOCKS_PER_SEC < 60 ) cout << "\nThe code ran in " << (tf-ti)/CLOCKS_PER_SEC << " seconds\n" << endl; else if ( (tf-ti)/CLOCKS_PER_SEC < 3600 ) cout << "\nThe code ran in " << (int)( ( (tf-ti)/CLOCKS_PER_SEC ) / 60) << " minutes and " << (tf-ti)/CLOCKS_PER_SEC - 60 * (int)( ( (tf-ti)/CLOCKS_PER_SEC ) / 60) << " seconds\n" << endl; else if ( (tf-ti)/CLOCKS_PER_SEC < 86400 ) cout << "\nThe code ran in " << (int)( ( (tf-ti)/CLOCKS_PER_SEC ) / 3600) << " hours, " << (int)( ( (tf-ti)/CLOCKS_PER_SEC ) / 60) - 60 * (int)( ( (tf-ti)/CLOCKS_PER_SEC ) / 3600 ) << " minutes and " << (tf-ti)/CLOCKS_PER_SEC - 60 * ( (int)( ( (tf-ti)/CLOCKS_PER_SEC ) / 60) ) - 3600 * (int)( ( (tf-ti)/CLOCKS_PER_SEC ) / 3600) << " seconds\n" << endl; else if ( (tf-ti)/CLOCKS_PER_SEC < 604800 ) cout << "\nThe code ran in " << (int)( ( (tf-ti)/CLOCKS_PER_SEC ) / 86400 ) << " days, " << (int)( ( (tf-ti)/CLOCKS_PER_SEC ) / 3600 ) - 24 * ( (int)( ( (tf-ti)/CLOCKS_PER_SEC ) / 86400 ) ) << " hours, " << (int)( ( (tf-ti)/CLOCKS_PER_SEC ) / 60 ) - 1440 * ( (int)( ( (tf-ti)/CLOCKS_PER_SEC ) / 86400 ) ) - 60 * ( (int)( ( (tf-ti)/CLOCKS_PER_SEC ) / 3600 ) ) << " minutes and " << (tf-ti)/CLOCKS_PER_SEC - 86400 * ( (int)( ( (tf-ti)/CLOCKS_PER_SEC ) / 86400 ) ) - 3600 * ( (int)( ( (tf-ti)/CLOCKS_PER_SEC ) / 3600 ) ) - 60 * ( (int)( ( (tf-ti)/CLOCKS_PER_SEC ) / 60 ) ) << " seconds\n" << endl; else cout << "Your code took more than a day to write. You should optimize that." << endl; } } // Progress bar void printProgBar( int percent, string name ) { string bar; for(int i = 0; i < 50; i++){ if( i < (percent/2)){ bar.replace(i,1,"="); }else if( i == (percent/2)){ bar.replace(i,1,">"); }else{ bar.replace(i,1," "); } } cout<< "\r" << name << " [" << bar << "] "; cout.width( 3 ); if ( percent == 100 ) cout<< percent << "% " << endl; else cout<< percent << "% " << flush; } vector< string > getFileList( const string path ) { vector< string > m_file_list; if (!path.empty()) { namespace fs = boost::filesystem; fs::path apk_path(path); fs::recursive_directory_iterator end; for (fs::recursive_directory_iterator i(apk_path); i != end; ++i) { const fs::path cp = (*i); m_file_list.push_back(cp.string()); } } return m_file_list; } vector< string > parseString( string line, string deli) { vector< string > out; string aux = line; size_t pos = 0; while( ( pos = aux.find( deli ) ) != string::npos ) { out.push_back( aux.substr( 0, pos ) ); aux.erase( 0, pos + deli.length() ); } out.push_back( aux ); return out; } double GetCorrectedAngleDif0Pi( const double & angle ) { double oangle; if(angle > M_PI){ oangle = 2*M_PI - angle; } else if(angle < 0 && angle > -M_PI){ oangle = abs(angle); } else if(angle < -M_PI){ oangle = 2*M_PI - abs(angle); } else { oangle = angle; } return oangle; }