Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FileExistFilter.cc
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file protocols/simple_filters/FileExistFilter.cc
11 /// @brief
12 /// @author Sarel Fleishman
13 
14 
15 //Unit Headers
18 #include <utility/tag/Tag.hh>
19 //Project Headers
20 #include <basic/Tracer.hh>
21 #include <fstream>
22 #include <iostream>
23 namespace protocols{
24 namespace simple_filters {
25 
26 using namespace core;
27 using namespace core::scoring;
28 
29 static basic::Tracer TR( "protocols.simple_filters.FileExistFilter" );
30 
33 
35 FileExistFilterCreator::keyname() const { return "FileExist"; }
36 
37 //default ctor
39 protocols::filters::Filter( "FileExist" ),
40 filename_( "" ),
41 ignore_zero_byte_( false )
42 {}
43 
45 
46 void
48 {
49  filename_ = tag->getOption< std::string >( "filename" );
50  ignore_zero_byte( tag->getOption< bool >( "ignore_zero_byte", false ) );
51 }
52 
53 bool
55  return compute( pose );
56 }
57 
58 void
59 FileExistFilter::report( std::ostream & out, core::pose::Pose const & pose ) const {
60  out<<"File "<<filename_<<" exists? " << compute( pose )<<'\n';
61 }
62 
65  return( compute( pose ) );
66 }
67 
70  core::pose::Pose const & /*pose*/
71 ) const {
72  using namespace std;
73 
74  ifstream infile;
75  infile.open( filename_.c_str(), ios::in );
76  if( !infile.good() )
77  return false;
78 
79  if( !ignore_zero_byte() )
80  return true;
81 
82 /// if the file is there and we're ignoring zero-byte files, we return true only if the file contains information
83  core::Size const begin = infile.tellg();
84  infile.seekg( 0, ios::end );
85  core::Size const end = infile.tellg();
86  return( end - begin > 0 );
87 }
88 
90 {
91  filename_ = f;
92 }
93 
95 {
96  return filename_;
97 }
98 
99 }
100 }