master
a Code for the Combination of Indirect and Direct Constraints on High Energy Physics Models
Loading...
Searching...
No Matches
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
13
#include "
InputFileToOutputFileClaimer.hpp
"
14
15
namespace
BOL
16
{
17
std::string
const
InputFileToOutputFileClaimer::claimedSuffix
(
".claimed"
);
18
19
InputFileToOutputFileClaimer::InputFileToOutputFileClaimer
() :
20
matchedFilePairs(),
21
fileNumber( -1 ),
22
claimedFilename(
""
),
23
copyCommand(
"cp"
),
24
removeCommand(
"rm"
)
25
{
26
// just an initialization list.
27
}
28
29
InputFileToOutputFileClaimer::InputFileToOutputFileClaimer
(
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
41
InputFileToOutputFileClaimer::~InputFileToOutputFileClaimer
()
42
{
43
// does nothing.
44
}
45
46
47
bool
48
InputFileToOutputFileClaimer::claimNextUnclaimedFile
(
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
{
62
if
( !(
UsefulStuff::fileExists
(
matchedFilePairs
[
fileNumber
].second )) )
63
{
64
claimedFilename
.assign(
matchedFilePairs
[
fileNumber
].second );
65
claimedFilename
.append(
claimedSuffix
);
66
if
( !(
UsefulStuff::fileExists
(
claimedFilename
)) )
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 */
InputFileToOutputFileClaimer.hpp
BOL::InputFileToOutputFileClaimer::InputFileToOutputFileClaimer
InputFileToOutputFileClaimer()
Definition
InputFileToOutputFileClaimer.cpp:19
BOL::InputFileToOutputFileClaimer::claimedFilename
std::string claimedFilename
Definition
InputFileToOutputFileClaimer.hpp:74
BOL::InputFileToOutputFileClaimer::~InputFileToOutputFileClaimer
~InputFileToOutputFileClaimer()
Definition
InputFileToOutputFileClaimer.cpp:41
BOL::InputFileToOutputFileClaimer::matchedFilePairs
std::vector< std::pair< std::string, std::string > > matchedFilePairs
Definition
InputFileToOutputFileClaimer.hpp:72
BOL::InputFileToOutputFileClaimer::fileNumber
int fileNumber
Definition
InputFileToOutputFileClaimer.hpp:73
BOL::InputFileToOutputFileClaimer::claimedSuffix
static std::string const claimedSuffix
Definition
InputFileToOutputFileClaimer.hpp:26
BOL::InputFileToOutputFileClaimer::claimNextUnclaimedFile
bool claimNextUnclaimedFile(std::string const claimString="claimed, but not ready!")
Definition
InputFileToOutputFileClaimer.cpp:48
BOL::UsefulStuff::fileExists
static bool fileExists(std::string const &fileName)
Definition
UsefulStuff.hpp:129
BOL
Definition
ArgumentParser.hpp:23
LHPC
include
BOLlib
source
InputFileToOutputFileClaimer.cpp
Generated on Tue Aug 4 2026 for $\texttt{HEPfit}$ using
1.9.8