Alida-C++ 0.1
|
00001 /* 00002 * This file is part of the Alida-C++ library, an 00003 * 00004 * Advanced Library for Integrated Development of Data Analysis Applications. 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: 101 $ 00031 * $Date: 2012-03-12 09:47:11 +0100 (Mo, 12 Mrz 2012) $ 00032 * $Author: posch $ 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/ALDDataIOManagerCmdline.h" 00050 #include "operator/ALDOperatorManager.h" 00051 #include "operator/ALDOperator.h" 00052 00053 using namespace std; 00054 00055 using namespace Alida; 00056 00058 00068 int main( int argc, const char* argv[] ) 00069 { 00070 printf( "\nAlidaOpRunner is running...\n\n" ); 00071 00072 if (argc < 2) { 00073 cout << "Please choose an operator!\n" << endl; 00074 ALDOperatorManager::Instance().printOperatorHash(); 00075 exit(-1); 00076 } 00077 00078 // get operator object 00079 ALDOperator *op = ALDOperatorManager::Instance().getOperator(argv[1]); 00080 if (op == NULL) { 00081 cout << "Unknown operator \"" << argv[1] << "\"... check the spelling!" 00082 << endl; 00083 exit(-1); 00084 } 00085 00086 // list parameters 00087 cout << "Chosen operator : " << argv[1] << endl; 00088 00089 // get list of parameters 00090 map<string, ALDOpParameterDescriptor*> params = op->getParameters(); 00091 00092 // print parameters if none is provided 00093 if (argc==2) { 00094 map<string, ALDOpParameterDescriptor*>::const_iterator it; 00095 string directionName; 00096 cout << "Operator parameters: " << endl; 00097 for (it = params.begin(); it != params.end(); ++it) { 00098 switch(it->second->direction) 00099 { 00100 case PARAMETER_IN: 00101 directionName = "IN"; 00102 break; 00103 case PARAMETER_OUT: 00104 directionName = "OUT"; 00105 break; 00106 case PARAMETER_INOUT: 00107 directionName = "INOUT"; 00108 break; 00109 } 00110 cout << " Name = " << it->first 00111 << " , type = " << it->second->typeNiceName 00112 << " , explanation = " << it->second->explanation 00113 << " , direction = " << directionName << std::endl; 00114 } 00115 cout << endl; 00116 cout << "Please specify appropriate values!" << endl << endl; 00117 exit(0); 00118 } 00119 00120 // parse input parameters 00121 cout << "Configuration: " << endl; 00122 for (int i = 2; i < argc; ++i) { 00123 // convert argument to string 00124 string argument(argv[i]); 00125 unsigned int equalSignPos = argument.find('='); 00126 if (equalSignPos == string::npos) { 00127 cout << i << " th parameter argument (" << argv[i] << ")" 00128 << " - error in argument string, skipping!" << endl; 00129 continue; 00130 } 00131 // get parameter name and value string 00132 string param= argument.substr(0,equalSignPos); 00133 string value= argument.substr(equalSignPos+1); 00134 00135 // savety check if parameter is known 00136 if (params[param] == NULL) { 00137 cout << "Parameter unknown, skipping \"" << param << "\"..." << endl; 00138 continue; 00139 } 00140 00141 // check if the parameter is really an input parameter 00142 if (params[param]->direction == PARAMETER_OUT) 00143 continue; 00144 00145 // read parameter value 00146 void *paramVal= 00147 ALDDataIOManagerCmdline::Instance().readData(value,params[param]->typeIdStr); 00148 if (paramVal == NULL) { 00149 cout << endl << "Error reading parameters... exiting!" << endl; 00150 exit(-1); 00151 } 00152 // set parameter 00153 op->setParameter(param, paramVal); 00154 cout << "Parameter \"" << param << "\" set.." << endl; 00155 } 00156 00157 // run the operator 00158 cout << endl << "AlidaOpRunner - running the operator..." << endl; 00159 try { 00160 op->runOp(); 00161 } catch (ALDException ex) { 00162 ex.printMsg(); 00163 exit(-1); 00164 } 00165 cout << endl << "AlidaOpRunner - finished operator execution!" << endl; 00166 00167 // display/save the result data 00168 cout << endl << "Displaying / saving results..." << endl << endl; 00169 for (int i = 2; i < argc; ++i) { 00170 // convert argument to string 00171 string argument(argv[i]); 00172 unsigned int equalSignPos = argument.find('='); 00173 if (equalSignPos == string::npos) { 00174 cout << i << " th parameter argument (" << argv[i] << ")" 00175 << " - error in argument string, skipping!" << endl; 00176 continue; 00177 } 00178 // get parameter name and value string 00179 string param= argument.substr(0,equalSignPos); 00180 string value= argument.substr(equalSignPos+1); 00181 00182 // savety check if parameter is known 00183 if (params[param] == NULL) { 00184 cout << "Parameter unknown, skipping \"" << param << "\"..." << endl; 00185 continue; 00186 } 00187 00188 // check if the parameter is really an input parameter 00189 if (params[param]->direction == PARAMETER_IN) 00190 continue; 00191 00192 // write output parameter result value 00193 string resultval = ALDDataIOManagerCmdline::Instance().writeData( 00194 value,params[param]->typeIdStr, op->getParameter(param)); 00195 if (!resultval.empty()) 00196 cout << "Parameter \"" << param << "\" - value = " << resultval << endl; 00197 else 00198 cout << "Parameter \"" << param << "\" - <internal handling>" << endl; 00199 } 00200 printf("\n... AlidaOpRunner finished completely!\n\n"); 00201 } 00202