NCBI C++ ToolKit
obj_conv_profile.cpp
Go to the documentation of this file.
00001 /*  $Id: obj_conv_profile.cpp 21400 2010-05-18 14:39:02Z katargir $
00002  * ===========================================================================
00003  *
00004  *                            PUBLIC DOMAIN NOTICE
00005  *               National Center for Biotechnology Information
00006  *
00007  *  This software/database is a "United States Government Work" under the
00008  *  terms of the United States Copyright Act.  It was written as part of
00009  *  the author's official duties as a United States Government employee and
00010  *  thus cannot be copyrighted.  This software/database is freely available
00011  *  to the public for use. The National Library of Medicine and the U.S.
00012  *  Government have not placed any restriction on its use or reproduction.
00013  *
00014  *  Although all reasonable efforts have been taken to ensure the accuracy
00015  *  and reliability of the software and data, the NLM and the U.S.
00016  *  Government do not and cannot warrant the performance or results that
00017  *  may be obtained by using this software or data. The NLM and the U.S.
00018  *  Government disclaim all warranties, express or implied, including
00019  *  warranties of performance, merchantability or fitness for any particular
00020  *  purpose.
00021  *
00022  *  Please cite the author in any work or product based on this material.
00023  *
00024  * ===========================================================================
00025  *
00026  * Authors:  Roman Katargin
00027  *
00028  * File Description:
00029  *
00030  */
00031 
00032 
00033 #include "/usr/local/valgrind-3.5.0/include/valgrind/callgrind.h"
00034 
00035 #include <ncbi_pch.hpp>
00036 #include <corelib/ncbiapp.hpp>
00037 #include <corelib/ncbiargs.hpp>
00038 #include <corelib/ncbienv.hpp>
00039 #include <corelib/ncbitime.hpp>
00040 #include <serial/objistr.hpp>
00041 
00042 #include <objmgr/object_manager.hpp>
00043 #include <gui/objutils/obj_convert.hpp>
00044 #include <gui/objutils/init.hpp>
00045 #include <gui/utils/init_registrar.hpp>
00046 
00047 
00048 BEGIN_NCBI_SCOPE
00049 USING_SCOPE(objects);
00050 
00051 /////////////////////////////////////////////////////////////////////////////
00052 //  CObjConvProfile::
00053 
00054 
00055 class CObjConvProfile : public CNcbiApplication
00056 {
00057 public:
00058     CObjConvProfile();
00059 
00060 private:
00061     virtual void Init(void);
00062     virtual int  Run(void);
00063     virtual void Exit(void);
00064 
00065     void x_CreateRelatedMap(TConstScopedObjects& input, const string& type, TRelatedObjectsMap& map);
00066 
00067     CRef<CObjectManager> m_ObjectManager;
00068 };
00069 
00070 
00071 CObjConvProfile::CObjConvProfile()
00072 {
00073 }
00074 
00075 
00076 /////////////////////////////////////////////////////////////////////////////
00077 //  Init test for all different types of arguments
00078 
00079 
00080 void CObjConvProfile::Init(void)
00081 {
00082     // Create command - line argument descriptions class
00083     auto_ptr<CArgDescriptions> arg_desc(new CArgDescriptions);
00084 
00085     // Specify USAGE context
00086     arg_desc->SetUsageContext(GetArguments().GetProgramBasename(),
00087                               "Math library test app");
00088 
00089     // Setup arg.descriptions for this application
00090     SetupArgDescriptions(arg_desc.release());
00091 
00092     
00093     CInitRegistrar::Init();
00094 }
00095 
00096 
00097 
00098 /////////////////////////////////////////////////////////////////////////////
00099 
00100 
00101 int CObjConvProfile::Run(void)
00102 {
00103 
00104     m_ObjectManager = CObjectManager::GetInstance();
00105     
00106     auto_ptr<CObjectIStream> istr(
00107             CObjectIStream::Open(eSerial_AsnText,
00108                "/net/snowman/vol/export2/win-coremake/App/Ncbi/gbench/data/test_for_cleanup.asn"));
00109 
00110     string header = istr->ReadFileHeader();
00111     TTypeInfo type_info = CClassTypeInfo::GetClassInfoByName(header);
00112     CRef<CSerialObject> so((CSerialObject*)type_info->Create());
00113     istr->ReadObject(so.GetPointer(), type_info);
00114 
00115     CRef<CScope> scope(new CScope(*m_ObjectManager));
00116     scope->AddDefaults();
00117 
00118     TConstScopedObjects input;
00119     input.push_back(SConstScopedObject(*so, *scope));
00120 
00121 
00122     CStopWatch sw;
00123     sw.Start();
00124             
00125     TRelatedObjectsMap map;
00126     CALLGRIND_START_INSTRUMENTATION;
00127     x_CreateRelatedMap(input, CSeq_loc::GetTypeInfo()->GetName(), map); 
00128     CALLGRIND_STOP_INSTRUMENTATION;
00129     CALLGRIND_DUMP_STATS;
00130 
00131     string t = NStr::DoubleToString(sw.Elapsed(), 3);
00132     cout << "Converted in " << t << " sec" << endl;
00133 
00134     ITERATE(TRelatedObjectsMap, it, map) {
00135         cout << it->first << ": " << it->second.size() << " Seq-locs" << endl;
00136     }
00137     
00138     return 0;
00139 }
00140 
00141 
00142 void CObjConvProfile::x_CreateRelatedMap( 
00143         TConstScopedObjects& input,
00144         const string& type,
00145         TRelatedObjectsMap& map 
00146         ){
00147     map.clear();
00148 
00149     set<const CObject*> objects_used;
00150     ITERATE( TConstScopedObjects, it, input ){
00151         const CObject* p_obj = it->object;
00152         objects::CScope* p_scope = const_cast<objects::CScope*>(it->scope.GetPointer());
00153         if( !p_obj || !p_scope || objects_used.find( p_obj ) != objects_used.end() ){
00154             continue;
00155         }
00156         const CObject& object = *p_obj;
00157         objects::CScope& scope = *p_scope;
00158 
00159         CObjectConverter::TRelationVector relations;
00160         CObjectConverter::FindRelations( scope, object, type, relations );
00161 
00162         ITERATE( CObjectConverter::TRelationVector, itr, relations ){
00163             if( relations.size() > 1 && itr == relations.begin() ){
00164                 continue;
00165             }
00166 
00167             const CRelation& rel = **itr;
00168             string relName = rel.GetProperty( type );
00169 
00170             CRelation::TObjects related;
00171             rel.GetRelated( scope, object, related, CRelation::fConvert_NoExpensive );
00172 
00173             if( !related.empty() ){
00174                 TConstScopedObjects& rel_vec = map[relName];
00175 
00176                 ITERATE( CRelation::TObjects, rel_itr, related ){
00177                     rel_vec.push_back( 
00178                             SConstScopedObject( rel_itr->GetObject(), scope ) 
00179                             );
00180                 }
00181             }
00182         }
00183     }
00184 }
00185 
00186 //  Cleanup
00187 
00188 
00189 void CObjConvProfile::Exit(void)
00190 {
00191     SetDiagStream(0);
00192 }
00193 
00194 END_NCBI_SCOPE
00195 
00196 USING_SCOPE(ncbi);
00197 
00198 /////////////////////////////////////////////////////////////////////////////
00199 //  MAIN
00200 
00201 
00202 int main(int argc, const char* argv[])
00203 {
00204     // Execute main application function
00205     return CObjConvProfile().AppMain(argc, argv, 0, eDS_Default, 0);
00206 }
Modified on Wed May 23 12:53:31 2012 by modify_doxy.py rev. 337098