Alida-C++ 0.5
|
00001 /* 00002 * This file is part of Alida-C++ library for 00003 * 00004 * Automatic Logging of Process Information in Data Analysis. 00005 * 00006 * Copyright (C) 2012 - @YEAR@ 00007 * 00008 * This program is free software: you can redistribute it and/or modify 00009 * it under the terms of the GNU General Public License as published by 00010 * the Free Software Foundation, either version 3 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * This program is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License 00019 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00020 * 00021 * Fore more information on Alida, visit 00022 * 00023 * http://www.informatik.uni-halle.de/alida/ 00024 * 00025 */ 00026 00027 /* 00028 * Most recent change(s): 00029 * 00030 * $Rev: 71 $ 00031 * $Date: 2012-03-07 11:29:55 +0100 (Mi, 07 Mrz 2012) $ 00032 * $Author: moeller $ 00033 * 00034 */ 00035 00041 #include <math.h> 00042 #include <stdio.h> 00043 00044 #include <fstream> 00045 #include <iostream> 00046 #include <map> 00047 #include <string> 00048 00049 #include "dataio/ioManagerCmdline.h" 00050 #include "operator/aldOperatorManager.h" 00051 00052 using namespace std; 00053 00054 using namespace Alida; 00055 00057 00067 int main( int argc, const char* argv[] ) 00068 { 00069 printf( "\nAlidaOpRunner is running...\n\n" ); 00070 00071 if (argc < 2) { 00072 cout << "Please choose an operator!\n" << endl; 00073 ALDOperatorManager::Instance().printOperatorHash(); 00074 exit(-1); 00075 } 00076 00077 // get operator object 00078 ALDOperator *op = ALDOperatorManager::Instance().getOperator(argv[1]); 00079 if (op == NULL) { 00080 cout << "Unknown operator \"" << argv[1] << "\"... check the spelling!" 00081 << endl; 00082 exit(-1); 00083 } 00084 00085 // list parameters 00086 cout << "Chosen operator : " << argv[1] << endl; 00087 00088 // get list of parameters 00089 map<string, ALDOpParameterDescriptor*> params = op->getParameters(); 00090 00091 // print parameters if none is provided 00092 if (argc==2) { 00093 map<string, ALDOpParameterDescriptor*>::const_iterator it; 00094 string directionName; 00095 cout << "Operator parameters: " << endl; 00096 for (it = params.begin(); it != params.end(); ++it) { 00097 switch(it->second->direction) 00098 { 00099 case 0: 00100 directionName = "IN"; 00101 break; 00102 case 1: 00103 directionName = "OUT"; 00104 break; 00105 case 2: 00106 directionName = "INOUT"; 00107 break; 00108 } 00109 cout << " Name = " << it->first 00110 << " , type = " << it->second->typeNiceName 00111 << " , explanation = " << it->second->explanation 00112 << " , direction = " << directionName << std::endl; 00113 } 00114 cout << endl; 00115 cout << "Please specify appropriate values!" << endl << endl; 00116 exit(0); 00117 } 00118 00119 // parse input parameters 00120 cout << "Configuration: " << endl; 00121 for (int i = 2; i < argc; ++i) { 00122 // convert argument to string 00123 string argument(argv[i]); 00124 unsigned int equalSignPos = argument.find('='); 00125 if (equalSignPos == string::npos) { 00126 cout << i << " th parameter argument (" << argv[i] << ")" 00127 << " - error in argument string, skipping!" << endl; 00128 continue; 00129 } 00130 // get parameter name and value string 00131 string param= argument.substr(0,equalSignPos); 00132 string value= argument.substr(equalSignPos+1); 00133 00134 // check if the parameter is really an input parameter 00135 if (params[param]->direction == ALDOpParameterDescriptor::OUT) 00136 continue; 00137 00138 // read parameter value 00139 void *paramVal= 00140 IOManagerCmdline::Instance().readData(value,params[param]->typeIdStr); 00141 // set parameter 00142 op->setParameter(param, paramVal); 00143 cout << "Parameter \"" << param << "\" set.." << endl; 00144 } 00145 00146 // run the operator 00147 cout << endl << "AlidaOpRunner - running the operator..." << endl; 00148 op->runOp(); 00149 cout << endl << "AlidaOpRunner - finished operator execution!" << endl; 00150 00151 // display/save the result data 00152 cout << endl << "Displaying / saving results..." << endl << endl; 00153 for (int i = 2; i < argc; ++i) { 00154 // convert argument to string 00155 string argument(argv[i]); 00156 unsigned int equalSignPos = argument.find('='); 00157 if (equalSignPos == string::npos) { 00158 cout << i << " th parameter argument (" << argv[i] << ")" 00159 << " - error in argument string, skipping!" << endl; 00160 continue; 00161 } 00162 // get parameter name and value string 00163 string param= argument.substr(0,equalSignPos); 00164 string value= argument.substr(equalSignPos+1); 00165 00166 // check if the parameter is really an input parameter 00167 if (params[param]->direction == ALDOpParameterDescriptor::IN) 00168 continue; 00169 00170 // write output parameter result value 00171 string resultval = IOManagerCmdline::Instance().writeData( 00172 value,params[param]->typeIdStr, op->getParameter(param)); 00173 if (!resultval.empty()) 00174 cout << "Parameter \"" << param << "\" - value = " << resultval << endl; 00175 else 00176 cout << "Parameter \"" << param << "\" - <internal handling>" << endl; 00177 } 00178 printf("\n... AlidaOpRunner finished completely!\n\n"); 00179 } 00180