00001 /** 00002 * \file LogOptimizerState.h 00003 * \brief Write geometry to a file during optimization 00004 * 00005 * Copyright 2007-2010 IMP Inventors. All rights reserved. 00006 */ 00007 00008 #ifndef IMPDISPLAY_LOG_OPTIMIZER_STATE_H 00009 #define IMPDISPLAY_LOG_OPTIMIZER_STATE_H 00010 00011 #include "display_config.h" 00012 #include "Writer.h" 00013 #include <IMP/OptimizerState.h> 00014 #include <IMP/SingletonContainer.h> 00015 #include <IMP/display/geometry.h> 00016 #include <IMP/Pointer.h> 00017 #include <IMP/FailureHandler.h> 00018 #include <IMP/internal/utility.h> 00019 #include <vector> 00020 00021 IMPDISPLAY_BEGIN_NAMESPACE 00022 00023 //! Write geometry to a container periodically 00024 /** The State writes a series of files generated from a 00025 printf-style format string. The added geometry objects 00026 are stored by reference internally. 00027 \verbinclude display_log.py 00028 \ingroup logging 00029 */ 00030 class IMPDISPLAYEXPORT LogOptimizerState: public OptimizerState 00031 { 00032 mutable IMP::internal::OwnerPointer<Writer> writer_; 00033 std::string name_template_; 00034 00035 Geometries gdata_; 00036 00037 public: 00038 //! Write files using name_template as a template (must have a %d in it) 00039 LogOptimizerState(Writer *writer, std::string name_template); 00040 void add_geometry(Geometry* g); 00041 00042 void add_geometry(const Geometries& g); 00043 00044 //! Force writing the a file with the given name 00045 void write(TextOutput file_name) const; 00046 00047 IMP_PERIODIC_OPTIMIZER_STATE(LogOptimizerState); 00048 }; 00049 00050 00051 00052 /** \brief Dump the state of the model to a file on an error and then 00053 go on the the other handlers. 00054 00055 When an error (check or assertion failure) occurs, the model is 00056 dumped to the specified using the geometry given in the 00057 LogOptimizerState. 00058 */ 00059 class IMPDISPLAYEXPORT DisplayModelOnFailure: public FailureHandler { 00060 IMP::internal::OwnerPointer<LogOptimizerState> s_; 00061 std::string file_name_; 00062 public: 00063 DisplayModelOnFailure(LogOptimizerState *m, std::string file_name); 00064 IMP_FAILURE_HANDLER(DisplayModelOnFailure); 00065 }; 00066 00067 IMPDISPLAY_END_NAMESPACE 00068 00069 #endif /* IMPDISPLAY_LOG_OPTIMIZER_STATE_H */