#include "PhysicsTools/StatPatternRecognition/interface/SprExperiment.hh"
#include "PhysicsTools/StatPatternRecognition/interface/SprAbsTrainedClassifier.hh"
#include "PhysicsTools/StatPatternRecognition/interface/SprTrainedBagger.hh"
#include "PhysicsTools/StatPatternRecognition/interface/SprClassifierReader.hh"
#include "PhysicsTools/StatPatternRecognition/interface/SprStringParser.hh"
#include <stdlib.h>
#include <unistd.h>
#include <iostream>
#include <cassert>
Go to the source code of this file.
Functions | |
void | help (const char *prog) |
int | main (int argc, char **argv) |
void help | ( | const char * | prog | ) |
Definition at line 17 of file SprAddBaggersApp.cc.
References GenMuonPlsPt100GeV_cfg::cout, and lat::endl().
00018 { 00019 cout << "Usage: " << prog 00020 << " list_of_bagger_configuration_files" 00021 << " output_file_for_overall_bagger" 00022 << endl; 00023 cout << "Example: " << prog 00024 << " \'bagger_1.spr,bagger_2.spr,bagger_3.spr\'" 00025 << " bagger_total.spr" << endl; 00026 cout << "\t Options: " << endl; 00027 cout << "\t-h --- help " << endl; 00028 cout << "\t-v verbosity level " << endl; 00029 }
Definition at line 32 of file SprAddBaggersApp.cc.
References c, TestMuL1L2Filter_cff::cerr, GenMuonPlsPt100GeV_cfg::cout, lat::endl(), help(), i, and merge::inputFiles.
00033 { 00034 // check command line 00035 if( argc < 3 ) { 00036 help(argv[0]); 00037 return 1; 00038 } 00039 00040 // init 00041 int verbose = 0; 00042 00043 // decode command line 00044 int c; 00045 extern char* optarg; 00046 // extern int optind; 00047 while((c = getopt(argc,argv,"hv:")) != EOF ) { 00048 switch( c ) 00049 { 00050 case 'h' : 00051 help(argv[0]); 00052 return 1; 00053 case 'v' : 00054 verbose = (optarg==0 ? 0 : atoi(optarg)); 00055 break; 00056 } 00057 } 00058 00059 // Must have 2 arguments on the command line 00060 string inputFileList = argv[argc-2]; 00061 string outputFile = argv[argc-1]; 00062 if( inputFileList.empty() ) { 00063 cerr << "No input Bagger configuration files are specified." << endl; 00064 return 1; 00065 } 00066 if( outputFile.empty() ) { 00067 cerr << "No output Bagger file is specified." << endl; 00068 return 1; 00069 } 00070 00071 // get classifier files 00072 vector<vector<string> > inputFiles; 00073 SprStringParser::parseToStrings(inputFileList.c_str(),inputFiles); 00074 if( inputFiles.empty() || inputFiles[0].empty() ) { 00075 cerr << "Unable to parse input file list: " 00076 << inputFileList.c_str() << endl; 00077 return 1; 00078 } 00079 int nTrained = inputFiles[0].size(); 00080 00081 // read classifier configuration 00082 SprTrainedBagger* total = 0; 00083 for( int i=0;i<nTrained;i++ ) { 00084 00085 // read 00086 SprAbsTrainedClassifier* absTrained 00087 = SprClassifierReader::readTrained(inputFiles[0][i].c_str(),verbose); 00088 if( absTrained == 0 ) { 00089 cerr << "Unable to read classifier configuration from file " 00090 << inputFiles[0][i].c_str() << endl; 00091 delete absTrained; 00092 delete total; 00093 return 2; 00094 } 00095 00096 // check type and downcast 00097 SprTrainedBagger* current = 0; 00098 if( absTrained->name() == "Bagger" ) 00099 current = static_cast<SprTrainedBagger*>(absTrained); 00100 else { 00101 cerr << "Fetched classifier is not Bagger. Cannot add." << endl; 00102 delete absTrained; 00103 delete total; 00104 return 2; 00105 } 00106 cout << "Read classifier " << current->name().c_str() 00107 << " with dimensionality " << current->dim() 00108 << " and " << current->nClassifiers() << " classifiers." << endl; 00109 00110 // add current to total 00111 if( i > 0 ) { 00112 *total += *current; 00113 delete current; 00114 } 00115 else 00116 total = current; 00117 } 00118 00119 // show the result 00120 assert( total != 0 ); 00121 cout << "Obtained final Bagger with " << total->nClassifiers() 00122 << " classifiers." << endl; 00123 00124 // store the final bagger 00125 if( !total->store(outputFile.c_str()) ) { 00126 cerr << "Unable to store final Bagger into file " 00127 << outputFile.c_str() << endl; 00128 return 3; 00129 } 00130 cout << "Final Bagger has been stored in file " 00131 << outputFile.c_str() << endl; 00132 00133 // cleanup 00134 delete total; 00135 00136 // exit 00137 return 0; 00138 }