OpenWalnut  1.5.0dev
WBatchLoader.cpp
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #include <memory>
26 #include <string>
27 #include <vector>
28 
29 #include "WBatchLoader.h"
30 #include "WDataModuleInputFile.h"
31 #include "WModule.h"
32 #include "WModuleContainer.h"
33 #include "WModuleFactory.h"
34 
35 WBatchLoader::WBatchLoader( std::vector< std::string > filenames, std::shared_ptr< WModuleContainer > targetContainer ):
37  std::enable_shared_from_this< WBatchLoader >(),
38  m_filenamesToLoad( filenames ),
39  m_targetContainer( targetContainer ),
40  m_suppressColormaps( false )
41 {
42  // initialize members
43 }
44 
46 {
47  // cleanup
48 }
49 
51 {
52  // the module needs to be added here, as it else could be freed before the thread finishes ( remember: it is a shared_ptr).
53  m_targetContainer->addPendingThread( shared_from_this() );
54 
55  // actually run
57 }
58 
60 {
61  // add a new data module for each file to load
62  for( std::vector< std::string >::iterator iter = m_filenamesToLoad.begin(); iter != m_filenamesToLoad.end(); ++iter )
63  {
64  // This needs to be re-thought. Refer to #32.
65  // TODO(ebaum): change this to create WDataModuleInput using a matching WDataModuleInputFilter
67  std::vector< WDataModule::SPtr > dataModules = WModuleFactory::getModuleFactory()->getDataModulePrototypesByInput(
68  // NOTE: right now, we only support file based inputs. Will change with issue #32
69  input
70  );
71 
72  if( dataModules.empty() )
73  {
74  wlog::warn( "WBatchLoader" ) << "File type of " << *iter << " not supported. Ignoring.";
75  continue;
76  }
77 
78  std::shared_ptr< WModule > mod = WModuleFactory::getModuleFactory()->create(
79  dataModules[0]
80  );
81  WDataModule::SPtr dmod = std::static_pointer_cast< WDataModule >( mod );
82 
83  // set the input
84  dmod->setSuppressColormaps( m_suppressColormaps );
85  dmod->setInput( input );
86 
87  m_targetContainer->add( mod );
88  dmod->isReadyOrCrashed().wait();
89 
90  // add module to the list
91  m_dataModules.push_back( dmod );
92  }
93 
94  m_targetContainer->finishedPendingThread( shared_from_this() );
95 }
96 
98 {
100 }
101 
103 {
104  m_suppressColormaps = suppress;
105 }
106 
108 {
109  return m_suppressColormaps;
110 }
111 
Class for loading many datasets.
Definition: WBatchLoader.h:43
virtual void run()
Run thread and load the data.
DataModuleList m_dataModules
The list of modules that have been added.
Definition: WBatchLoader.h:123
virtual void threadMain()
Function that has to be overwritten for execution.
DataModuleList::ReadTicket getDataModuleList() const
Returns a ticket to the list of data modules that have been added so far.
std::vector< std::string > m_filenamesToLoad
List of files to load.
Definition: WBatchLoader.h:113
bool m_suppressColormaps
If true, data modules are instructed to suppress colormap registration.
Definition: WBatchLoader.h:128
virtual ~WBatchLoader()
Destructor.
std::shared_ptr< WModuleContainer > m_targetContainer
The container which later will contain the loaded datasets.
Definition: WBatchLoader.h:118
WBatchLoader(std::vector< std::string > filenames, std::shared_ptr< WModuleContainer > targetContainer)
Initializes the batchloader but does not start it.
void setSuppressColormaps(bool suppress=true)
Allows suppression of colormap registration in data modules.
bool getSuppressColormaps() const
Checks whether suppression of colormaps is active.
Implements a file based input for the WDataModule.
std::shared_ptr< WDataModuleInputFile > SPtr
Convenience typedef for a std::shared_ptr< WDataModuleInputFile >.
std::shared_ptr< WDataModule > SPtr
Convenience typedef for a std::shared_ptr< WDataModule >.
Definition: WDataModule.h:52
static SPtr getModuleFactory()
Returns instance of the module factory to use to create modules.
std::shared_ptr< WSharedObjectTicketRead< T > > ReadTicket
Type for read tickets.
Definition: WSharedObject.h:65
ReadTicket getReadTicket() const
Returns a ticket to get read access to the contained data.
void push_back(const typename S::value_type &x)
Adds a new element at the end of the container.
Base class for all classes needing to be executed in a separate thread.
virtual void run()
Run thread.
WStreamedLogger warn(const std::string &source)
Logging a warning message.
Definition: WLogger.h:309