a Code for the Combination of Indirect and Direct Constraints on High Energy Physics Models Logo
InputFileToOutputFileClaimer.cpp
Go to the documentation of this file.
1/*
2 * InputFileToOutputFileClaimer.cpp
3 *
4 * Created on: Aug 14, 2012
5 * Author: Ben O'Leary (benjamin.oleary@gmail.com)
6 *
7 * This file is part of BOLlib, released under the
8 * GNU General Public License. Please see the accompanying
9 * README.BOLlib.txt file for a full list of files, brief documentation
10 * on how to use these classes, and further details on the license.
11 */
12
14
15namespace BOL
16{
17 std::string const InputFileToOutputFileClaimer::claimedSuffix( ".claimed" );
18
20 matchedFilePairs(),
21 fileNumber( -1 ),
22 claimedFilename( "" ),
23 copyCommand( "cp" ),
24 removeCommand( "rm" )
25 {
26 // just an initialization list.
27 }
28
30 std::vector< std::pair< std::string, std::string > > const&
31 matchedFilePairs ) :
32 matchedFilePairs( matchedFilePairs ),
33 fileNumber( -1 ),
34 claimedFilename( "" ),
35 copyCommand( "cp" ),
36 removeCommand( "rm" )
37 {
38 // just an initialization list.
39 }
40
42 {
43 // does nothing.
44 }
45
46
47 bool
49 std::string const claimString )
50 // this increments fileNumber, & returns false if there is no input file
51 // corresponding to it. otherwise, it updates currentOutputFilename &
52 // sets claimedFilename as the same, then appends claimedFilename with
53 // claimedSuffix. it then creates a file with claimedFilename as its name,
54 // fills it with claimString, & returns true.
55 {
56 // the conditional advances through the list of filename pairs until either
57 // the loop is broken by the early return of true because the next output
58 // file was claimed, or the early return of false because the claimed file
59 // was not openable.
60 while( matchedFilePairs.size() > (unsigned int)(++fileNumber) )
61 {
63 {
67 {
68 std::ofstream outputFile( claimedFilename.c_str() );
69 if( outputFile.good() )
70 {
71 outputFile << claimString << std::endl;
72 outputFile.close();
73 return true;
74 }
75 else
76 {
77 std::cout
78 << std::endl
79 << "BOL::error!"
80 << " InputFileToOutputFileClaimer::claimNextUnclaimedFile( \""
81 << claimString << "\" ) unable to create file \""
82 << claimedFilename << "\"!";
83 std::cout << std::endl;
84 return false;
85 }
86 }
87 }
88 }
89 // if we get to the end of the loop, all the output filenames are taken or
90 // claimed. (I've decided that SESE is a bit redundant these days.)
91 return false;
92 }
93
94} /* namespace BOL */
std::vector< std::pair< std::string, std::string > > matchedFilePairs
bool claimNextUnclaimedFile(std::string const claimString="claimed, but not ready!")
static bool fileExists(std::string const &fileName)