LCOV - code coverage report
Current view: top level - spectrallines/Splatalogue - SearcherFactory.cc (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 0 47 0.0 %
Date: 2024-10-04 16:51:10 Functions: 0 5 0.0 %

          Line data    Source code
       1             : //# Copyright (C) 2004
       2             : //# Associated Universities, Inc. Washington DC, USA.
       3             : //#
       4             : //# This library is free software; you can redistribute it and/or modify it
       5             : //# under the terms of the GNU Library General Public License as published by
       6             : //# the Free Software Foundation; either version 2 of the License, or (at your
       7             : //# option) any later version.
       8             : //#
       9             : //# This library is distributed in the hope that it will be useful, but WITHOUT
      10             : //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
      11             : //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
      12             : //# License for more details.
      13             : //#
      14             : //# You should have received a copy of the GNU Library General Public License
      15             : //# along with this library; if not, write to the Free Software Foundation,
      16             : //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
      17             : //#
      18             : //# Correspondence concerning AIPS++ should be addressed as follows:
      19             : //#        Internet email: casa-feedback@nrao.edu.
      20             : //#        Postal address: AIPS++ Project Office
      21             : //#                        National Radio Astronomy Observatory
      22             : //#                        520 Edgemont Road
      23             : //#                        Charlottesville, VA 22903-2475 USA
      24             : #include "SearcherFactory.h"
      25             : #include <spectrallines/Splatalogue/Searcher.h>
      26             : #include <spectrallines/Splatalogue/SQLiteSearch/SearcherSQLite.h>
      27             : #include <casatools/Config/State.h>
      28             : #include <casacore/casa/Logging/LogIO.h>
      29             : #include <iostream>
      30             : using namespace std;
      31             : 
      32             : using namespace casacore;
      33             : namespace casa {
      34             : 
      35           0 : String SearcherFactory::getLocation( bool local ) {
      36           0 :         String defaultDatabasePath;
      37           0 :         if ( local ){
      38             : 
      39             :                 //Note:: When the SQLite code (and database get put into its
      40             :                 //own library, finding the location of the database should be
      41             :                 //removed from here and put into the DatabaseConnector.
      42           0 :                 const string splatdb = "ephemerides/splatalogue.db";
      43           0 :                 Bool foundDatabase = false;
      44           0 :                 string resolvepath;
      45           0 :                 resolvepath = casatools::get_state( ).resolve(splatdb);
      46           0 :                 if ( resolvepath != splatdb ) {
      47           0 :                         foundDatabase = true;
      48           0 :                         defaultDatabasePath = resolvepath;
      49             :                 } else {
      50           0 :                         const string splatable = "ephemerides/SplatDefault.tbl";
      51           0 :                         foundDatabase = Aipsrc::find(defaultDatabasePath, "user.ephemerides.SplatDefault.tbl");
      52           0 :                         if( !foundDatabase ){
      53           0 :                                 foundDatabase = Aipsrc::findDir(defaultDatabasePath, "data/" + splatable);
      54             :                         }
      55             : 
      56           0 :                         if ( foundDatabase ) {
      57           0 :                                 const String tableName = "SplatDefault.tbl";
      58           0 :                                 int index = defaultDatabasePath.find(tableName, 0);
      59           0 :                                 int tableNameSize = tableName.length();
      60           0 :                                 defaultDatabasePath.replace(index, tableNameSize, "splatalogue.db");
      61           0 :                         }
      62           0 :                 }
      63           0 :         }
      64             : 
      65             :         static bool logged = false;
      66           0 :         if ( logged == false ) {
      67           0 :                 logged = true;
      68           0 :                 LogIO os (LogOrigin ("SearcherFactory", "getLocation"));
      69           0 :                 if ( defaultDatabasePath.size( ) == 0 ) {
      70             :                         os << LogIO::WARN <<
      71             :                           "could not find splatalog offline database" <<
      72           0 :                           LogIO::POST;
      73             :                 } else {
      74             :                         os <<
      75             :                           "found splatalog offline database: " <<
      76             :                           defaultDatabasePath <<
      77           0 :                           LogIO::POST;
      78             :                 }
      79           0 :         }
      80           0 :         return defaultDatabasePath;
      81           0 : }
      82             : 
      83           0 : Searcher* SearcherFactory::getSearcher( bool local ){
      84           0 :         Searcher* searcher = NULL;
      85           0 :         if ( local ){
      86           0 :                 String defaultDatabasePath = getLocation( local );
      87           0 :                 if (! defaultDatabasePath.empty()){
      88           0 :                         searcher = new SearcherSQLite(defaultDatabasePath.c_str() );
      89           0 :                         if ( !searcher->isConnected()){
      90           0 :                                 delete searcher;
      91           0 :                                 searcher = NULL;
      92             :                         }
      93             :                 }
      94           0 :         }
      95             :         else {
      96           0 :                 cout << "Only local database searches are currently supported"<<endl;
      97             :         }
      98           0 :         return searcher;
      99             : }
     100             : 
     101           0 : SearcherFactory::SearcherFactory(){
     102           0 : }
     103             : 
     104           0 : SearcherFactory::~SearcherFactory(){
     105           0 : }
     106             : 
     107             : using namespace casacore;
     108             : } /* namespace casa */

Generated by: LCOV version 1.16