cm_file.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2004 CSIRO ICT Centre
00003  *
00004  * $Id: cm_file.cpp 587 2004-12-03 15:06:33Z nch $
00005  */
00006 
00007 /*
00008  * This is the program used to perform the cross match benchmarking.
00009  *
00010  * At first it may seem an overwhelming number of parameters, but there
00011  * aren't really that many:
00012  *
00013  * The first 5 describe the input file(s):
00014  *
00015  * <a_dir|0>        The directory path containing the input files, 0 for a single file.
00016  * <a_file>         The common file name prefix, or full filename (including path).
00017  * <binary|ascii>   indicates if the file is binary or ascii.
00018  * [merge]          currently only required for 2MASS.
00019  * <a_maxSD>        the max SD value for the input data.
00020  *
00021  * The next 4 (or 5 if "merge" used) are for the other catalogue.
00022  *
00023  * <z_alpha>        We have used a value of 1.96 for our tests.
00024  * <index|list>     Indexed or list for the active list.
00025  * <bb|as>          Bounding Box test with Angular Separation, or just Angular Separation 
00026  * <filter|nested|sweep>
00027  *                  Use CM filter, or generic nested loop, or generic plane sweep.
00028  *
00029  * The output currently reports the number of matches (and non-matches) found.
00030  *
00031  * To write the output to a file, will need to modify the ObjectConsumers
00032  * (uaCons and ubCons) for the unmatched objects, or the various
00033  * ObjectPairConsumers used by the ObjectPairRefineConsumers.
00034  * Examples are included in comments below.
00035  */
00036 
00037 #include <iostream>
00038 #include "String.h"
00039 
00040 #include "ActiveList.h"
00041 #include "AngularSeparationRefine.h"
00042 #include "BoundingBoxRefine.h"
00043 #include "CrossMatch.h"
00044 #include "DecPlaneSweepFilter.h"
00045 #include "FileProducerFactory.h"
00046 #include "FileWriter.h"
00047 #include "FilePairWriter.h"
00048 #include "Filter.h"
00049 #include "IndexedActiveList.h"
00050 #include "Matcher.h"
00051 #include "NestedLoopFilter.h"
00052 #include "Object.h"
00053 #include "ObjectConsumer.h"
00054 #include "ObjectPairConsumer.h"
00055 #include "ObjectPairRefineConsumer.h"
00056 #include "ObjectProducer.h"
00057 #include "Refine.h"
00058 #include "SimpleActiveList.h"
00059 #include "TextFileDatumWriter.h"
00060 #include "Timer.h"
00061 
00062 static void usage(char const * const prog_name)
00063 {
00064   std::cerr << prog_name
00065             << " <a_dir|0> <a_file> <binary|ascii> [merge] <a_maxSD>"
00066             << " <b_dir|0> <b_file> <binary|ascii> [merge] <b_maxSD>"
00067             << " <z_alpha> <index|list> <bb|as> <filter|nested|sweep>" << std::endl;
00068 }
00069 
00070 int main(int argc, char * argv[])
00071 {
00072 #ifdef PLOT_TIMES
00073   Timer::globalTimer()->cont();        // need to start the timer
00074 #endif
00075 
00076   int status = 0;
00077 
00078   if (argc < 13 || argc > 15)
00079   {
00080     usage(argv[0]);
00081     status = 1;
00082   }
00083   else
00084   {
00085     int param = 1;
00086     char * aDir = argv[param++];
00087     char * aName = argv[param++];
00088     bool aBinary = (strcmp(argv[param++], "binary") == 0);
00089     bool aMerge = false;
00090     if (strcmp(argv[param], "merge") == 0)
00091     {
00092       aMerge = true;
00093       param++;
00094     }
00095     double aMaxSD = atof(argv[param++]);
00096 
00097     char * bDir = argv[param++];
00098     char * bName = argv[param++];
00099     bool bBinary = (strcmp(argv[param++], "binary") == 0);
00100     bool bMerge = false;
00101     if (strcmp(argv[param], "merge") == 0)
00102     {
00103       bMerge = true;
00104       param++;
00105     }
00106     double bMaxSD = atof(argv[param++]);
00107 
00108     double z_alpha = atof(argv[param++]);
00109     Object::zAlpha = z_alpha;
00110 
00111     bool useIndex =      (strcmp(argv[param++], "index") == 0);
00112     bool useBB =         (strcmp(argv[param++], "bb") == 0);
00113     bool useFilter =     (strcmp(argv[param], "filter") == 0);
00114     bool useNestedLoop = (!useFilter && strcmp(argv[param++], "nested") == 0);
00115 
00116     if (useFilter)
00117       std::cout << "Using CM filter           : true" << std::endl; 
00118     else if (useNestedLoop)
00119       std::cout << "Using generic nested loop : true" << std::endl;
00120     else
00121       std::cout << "Using generic plane sweep : true" << std::endl;
00122     std::cout << "Using index active list   : " << ((useIndex) ? "true" : "false") << std::endl;
00123     std::cout << "Using full BB refine      : " << ((useBB) ? "true" : "false") << std::endl;
00124 
00125     /* example to consume successful angular separation refine candidates to a file */
00126 /*
00127     ObjectPairConsumer accAngSepPairCons(AngularSeparationRefine::name() + " accept");
00128                          new FilePairWriter(new TextFileDatumWriter(), "ASacc"));
00129 */
00130     ObjectPairConsumer accAngSepPairCons(AngularSeparationRefine::name() + " accept");
00131     ObjectPairConsumer rejAngSepPairCons(AngularSeparationRefine::name() + " reject");
00132 
00133     AngularSeparationRefine angSepRefine(&accAngSepPairCons,
00134                                          &rejAngSepPairCons);
00135 
00136     ObjectPairRefineConsumer angSepConsumer(BoundingBoxRefine::name(),
00137                                             &angSepRefine);
00138 
00139     ObjectPairConsumer rejBBPairCons(BoundingBoxRefine::name() + " reject");
00140 
00141     BoundingBoxRefine bbRefine(&angSepConsumer, &rejBBPairCons);
00142 
00143     // depending on value of useBB, set the CrossMatchRefine
00144     ObjectPairRefineConsumer pairCons(((useNestedLoop) ? NestedLoopFilter::name()
00145                                                        : DecPlaneSweepFilter::name()),
00146                                       ((useBB) ? (Refine*) &bbRefine
00147                                                : (Refine*) &angSepRefine));
00148 
00149     /* example to consume non matches to a file */
00150 /*
00151     ObjectConsumer uaCons("A points reject",
00152                           new FileWriter(new TextFileDatumWriter(), "NMA"));
00153     ObjectConsumer ubCons("B points reject",
00154                           new FileWriter(new TextFileDatumWriter(), "NMB"));
00155 */
00156     ObjectConsumer uaCons("A points reject");
00157     ObjectConsumer ubCons("B points reject");
00158 
00159     ObjectProducer * aProd = FileProducerFactory::instance()->createProducer(
00160                                         aDir, aName, aBinary, aMerge, false, aMaxSD);
00161     ObjectProducer * bProd = FileProducerFactory::instance()->createProducer(
00162                                         bDir, bName, bBinary, bMerge, false, bMaxSD);
00163 
00164     
00165     ActiveList * aList = (useIndex) ? (ActiveList *) new IndexedActiveList()
00166                                     : (ActiveList *) new SimpleActiveList();
00167     Matcher * matcher = new CrossMatch(aProd, bProd, aList , &pairCons, &uaCons, &ubCons);
00168     Filter * filter = 0;
00169 
00170     if (useFilter)
00171       filter = new Filter(matcher);
00172     else if (useNestedLoop)
00173       filter = new NestedLoopFilter(matcher);
00174     else
00175       filter = new DecPlaneSweepFilter(matcher);
00176 
00177     filter->filter();
00178 
00179     delete filter;
00180   }
00181 
00182   return status;
00183 }
Generated on Mon Oct 4 10:39:55 2010 for Matching.kdevelop by  doxygen 1.6.3