Commit 24152565 authored by Floris Berendsen's avatar Floris Berendsen
Browse files

ENH: Blueprint uses logger at reading json #121

parent fba61dbe
......@@ -95,6 +95,7 @@ main( int ac, char * av[] )
// create empty blueprint
selx::Blueprint::Pointer blueprint = selx::Blueprint::New();
blueprint->SetLogger(logger);
for (const auto & configurationPath : configurationPaths)
{
blueprint->MergeFromFile(configurationPath.string());
......
......@@ -22,6 +22,7 @@
#include "itkDataObject.h"
#include "itkObjectFactory.h"
#include "selxLogger.h"
#include <string>
#include <vector>
......@@ -101,9 +102,11 @@ public:
void MergeFromFile(const std::string& filename);
void SetLogger( Logger::Pointer logger );
private:
BlueprintImplPointer m_Blueprint;
Logger::Pointer m_Logger;
};
}
......
......@@ -26,7 +26,14 @@ namespace selx
Blueprint
::Blueprint()
{
this->m_Blueprint = BlueprintImplPointer( new BlueprintImpl() );
// Create default logger which redirects to std::cout
this->m_Logger = Logger::New();
//TODO: cannot have independent loggers redirecting to cout.
//this->m_Logger->AddStream("cout", std::cout);
this->m_Logger->SetLogLevel(selx::LogLevel::INF);
this->m_Blueprint = BlueprintImplPointer( new BlueprintImpl( this->m_Logger->GetLoggerImpl() ) );
}
const BlueprintImpl &
......@@ -144,20 +151,20 @@ Blueprint
this->m_Blueprint->Write( filename );
}
/*
void
Blueprint
::FromFile( const std::string& filename )
::MergeFromFile( const std::string& filename )
{
this->m_Blueprint->FromFile( filename );
this->m_Blueprint->MergeFromFile( filename );
}
*/
void
Blueprint
::MergeFromFile( const std::string& filename )
::SetLogger( Logger::Pointer logger )
{
this->m_Blueprint->MergeFromFile( filename );
this->m_Logger = logger;
this->m_Blueprint->SetLoggerImpl( logger->GetLoggerImpl() );
}
} // namespace selx
......@@ -94,6 +94,15 @@ make_edge_label_writer( ParameterMapType p )
return edge_label_writer< ParameterMapType >( p );
}
// TODO: remove this argumentless constructor
BlueprintImpl::BlueprintImpl( void ) : m_LoggerImpl(&(Logger::New()->GetLoggerImpl()))
{
}
BlueprintImpl::BlueprintImpl( LoggerImpl & loggerImpl ) : m_LoggerImpl(&loggerImpl)
{
}
bool
BlueprintImpl
......@@ -427,28 +436,33 @@ void
BlueprintImpl::MergeFromFile(const std::string & fileNameString)
{
PathType fileName(fileNameString);
LoggerImpl logger;
logger.Log(LogLevel::INF, "Loading {0} ... ", fileName);
this->m_LoggerImpl->Log(LogLevel::INF, "Loading {0} ... ", fileName);
auto propertyTree = ReadPropertyTree(fileName);
logger.Log(LogLevel::INF, "Loading {0} ... Done", fileName);
this->m_LoggerImpl->Log(LogLevel::INF, "Loading {0} ... Done", fileName);
logger.Log(LogLevel::INF, "Checking {0} for include files ... ", fileName);
this->m_LoggerImpl->Log(LogLevel::INF, "Checking {0} for include files ... ", fileName);
auto includesList = FindIncludes(propertyTree);
if (includesList.size() > 0)
{
for (auto const & includePath : includesList)
{
logger.Log(LogLevel::INF, "Including file {0} ... ", includePath);
this->m_LoggerImpl->Log(LogLevel::INF, "Including file {0} ... ", includePath);
this->MergeFromFile(includePath.string());
}
}
logger.Log(LogLevel::INF, "Checking {0} for include files ... done", fileName);
this->m_LoggerImpl->Log(LogLevel::INF, "Checking {0} for include files ... done", fileName);
this->MergeProperties(propertyTree);
return;
}
void
BlueprintImpl::SetLoggerImpl( LoggerImpl & loggerImpl )
{
this->m_LoggerImpl = &loggerImpl;
}
BlueprintImpl::PropertyTreeType
BlueprintImpl::ReadPropertyTree(const PathType & filename)
{
......@@ -496,7 +510,6 @@ BlueprintImpl::FindIncludes(const PropertyTreeType & propertyTree)
Blueprint::Pointer
BlueprintImpl::FromPropertyTree(const PropertyTreeType & pt)
{
LoggerImpl logger;
Blueprint::Pointer blueprint = Blueprint::New();
BOOST_FOREACH(const PropertyTreeType::value_type & v, pt.equal_range("Component"))
......@@ -526,7 +539,7 @@ BlueprintImpl::FromPropertyTree(const PropertyTreeType & pt)
if (connectionName != "")
{
// TODO: Why is it ignored?
logger.Log(LogLevel::WRN, "Connection {0} is ignored.", connectionName);
this->m_LoggerImpl->Log(LogLevel::WRN, "Connection {0} is ignored.", connectionName);
}
std::string outName;
std::string inName;
......@@ -548,7 +561,7 @@ BlueprintImpl::FromPropertyTree(const PropertyTreeType & pt)
}
else if (connectionKey == "Name")
{
logger.Log(LogLevel::WRN, "Connections with key 'Name' are ignored.");
this->m_LoggerImpl->Log(LogLevel::WRN, "Connections with key 'Name' are ignored.");
continue;
}
else
......@@ -567,7 +580,6 @@ BlueprintImpl::FromPropertyTree(const PropertyTreeType & pt)
void
BlueprintImpl::MergeProperties(const PropertyTreeType & pt)
{
LoggerImpl logger;
BOOST_FOREACH(const PropertyTreeType::value_type & v, pt.equal_range("Component"))
{
std::string componentName;
......@@ -641,7 +653,7 @@ BlueprintImpl::MergeProperties(const PropertyTreeType & pt)
std::string connectionName = v.second.data();
if (connectionName != "")
{
logger.Log(LogLevel::WRN, "Connection {0} is ignored.", connectionName);
this->m_LoggerImpl->Log(LogLevel::WRN, "Connection {0} is ignored.", connectionName);
}
std::string outName;
std::string inName;
......@@ -663,7 +675,7 @@ BlueprintImpl::MergeProperties(const PropertyTreeType & pt)
}
else if (connectionKey == "Name")
{
logger.Log(LogLevel::WRN, "Connections with key 'Name' are ignored.");
this->m_LoggerImpl->Log(LogLevel::WRN, "Connections with key 'Name' are ignored.");
continue;
}
else
......
......@@ -42,6 +42,7 @@
#include "selxBlueprint.h"
#include "selxLoggerImpl.h"
namespace selx
{
......@@ -98,6 +99,12 @@ public:
typedef boost::graph_traits< GraphType >::out_edge_iterator OutputIteratorType;
typedef std::pair< OutputIteratorType, OutputIteratorType > OutputIteratorPairType;
// TODO: remove this argumentless constructor
BlueprintImpl();
BlueprintImpl( LoggerImpl & loggerImpl);
bool SetComponent( ComponentNameType, ParameterMapType parameterMap );
ParameterMapType GetComponent( ComponentNameType componentName ) const;
......@@ -129,6 +136,8 @@ public:
void MergeFromFile(const std::string & filename);
void SetLoggerImpl( LoggerImpl & loggerImpl );
private:
typedef boost::property_tree::ptree PropertyTreeType;
......@@ -148,6 +157,8 @@ private:
void MergeProperties(const PropertyTreeType &);
GraphType m_Graph;
LoggerImpl * m_LoggerImpl;
};
} // namespace selx
......
......@@ -79,7 +79,7 @@ public:
AnyFileWriterType::Pointer GetOutputFileWriter( const DataObjectIdentifierType & );
/** SetInput accepts any input data as long as it is derived from itk::DataObject */
void SetInput( const DataObjectIdentifierType &, InputDataType * ) override;
void SetInput(const DataObjectIdentifierType &, InputDataType *) ITK_OVERRIDE;
/** Non type-specific GetOutput */
OutputDataType * GetOutput( const DataObjectIdentifierType & );
......@@ -108,9 +108,11 @@ public:
return newOutput;
}
void Update( void ) ITK_OVERRIDE;
// The default logger redirects to std::cout
void SetLogger( Logger::Pointer logger );
protected:
// default constructor initialized with an empty NetworkBuilder
......@@ -126,7 +128,6 @@ protected:
private:
//TODO make const correct
BlueprintPointer m_Blueprint;
bool m_IsConnected;
......
......@@ -33,7 +33,13 @@ SuperElastixFilterBase
m_AllUniqueComponents( false )
{
this->m_Blueprint = nullptr;
// Create default logger which redirects to std::cout
this->m_Logger = Logger::New();
//TODO: cannot have independent loggers redirecting to cout.
//this->m_Logger->AddStream("cout", std::cout);
this->m_Logger->SetLogLevel(selx::LogLevel::INF);
} // end Constructor
bool
......@@ -42,7 +48,7 @@ SuperElastixFilterBase
{
if( ( this->m_Blueprint->GetMTime() > this->GetMTime() || !this->m_NetworkBuilder ) )
{
m_NetworkBuilder = m_NetworkBuilderFactory->New( this->m_Logger->GetLogger(), this->m_Blueprint->GetBlueprintImpl() );
m_NetworkBuilder = m_NetworkBuilderFactory->New( this->m_Logger->GetLoggerImpl(), this->m_Blueprint->GetBlueprintImpl() );
this->m_AllUniqueComponents = this->m_NetworkBuilder->Configure();
}
return this->m_AllUniqueComponents;
......@@ -272,4 +278,12 @@ SuperElastixFilterBase
this->GenerateData();
}
} // namespace elx
void
SuperElastixFilterBase
::SetLogger( Logger::Pointer logger )
{
this->m_Logger = logger;
// no need to call Modified, since logging doesn't change any calculations.
}
}// namespace elx
......@@ -76,7 +76,7 @@ public:
void Log( const LogLevel& level, const std::string& message );
LoggerImpl& GetLogger( void );
LoggerImpl& GetLoggerImpl( void );
private:
......
......@@ -114,7 +114,7 @@ Logger
LoggerImpl&
Logger
::GetLogger( void )
::GetLoggerImpl( void )
{
return *this->m_LoggerImpl;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment