PhoenixClockMock  1.0.0
Tool to manipulate mock of clock
Loading...
Searching...
No Matches
main_split.cpp
Go to the documentation of this file.
1/***************************************
2 Auteur : Pierre Aubert
3 Mail : pierre.aubert@lapp.in2p3.fr
4 Licence : CeCILL-C
5****************************************/
6
7#include "PPath.h"
8#include "OptionParser.h"
9
10#include "phoenix_clock_mock.h"
11
13
15OptionParser createOptionParser(){
16 OptionParser parser(true, __PROGRAM_VERSION__);
17 parser.setExampleLongOption("phoenix_clock_mock_split --input=file.clockmock --output=split.clockmock");
18 parser.setExampleShortOption("phoenix_clock_mock_split -i file2.clockmock file2.clockmock -o split.clockmock");
19
20 parser.addOption("input", "i", OptionType::FILENAME, true, "List of input mock to be split");
21
22 PPath defaultOutputFile("./split.clockmock");
23 parser.addOption("output", "o", defaultOutputFile, "Name of the output split mock file");
24
25 size_t defaultOffset(0lu), defaultSizePart(1lu), defaultNbPart(0lu);
26 parser.addOption("offset", "f", defaultOffset, "Offset of the first message to be extracted in a split mock");
27 parser.addOption("sizepart", "s", defaultSizePart, "Size of each split part (number of messages in each part to be split)");
28 parser.addOption("nbpart", "n", defaultNbPart, "Number of output mock to be created (0 means automatic by respect to --offset and --sizepart)");
29 return parser;
30}
31
33
38PPath phoenix_mockMakeOutputFile(const PPath & baseFileName, size_t indexFile, const PPath & extentionFile){
39 PPath extention(extentionFile);
40 if(extention == ""){
41 extention = PPath("clockmock");
42 }
43 return PPath(baseFileName + PString("_") + PString::toString(indexFile) + PString(".") + extention);
44}
45
47
54bool splitMock(const std::vector<PPath> & vecInputFile, const PPath & outputFile,
55 size_t offsetPart, size_t sizePart, size_t nbPart)
56{
57 if(sizePart == 0lu && nbPart == 0lu){
58 std::cerr << "Error sizePart cannot be 0 id nbPart == 0, aborting split" << std::endl;
59 return false;
60 }
61 PPath outputExtension(outputFile.getExtension()), baseOutputFile(outputFile.eraseExtension());
62 bool b(true);
63 for(std::vector<PPath>::const_iterator itFile(vecInputFile.begin()); itFile != vecInputFile.end() && b; ++itFile){
64 VecTime vecTmpFile;
65 if(data_load(*itFile, vecTmpFile)){
66 size_t nbTimeIn(vecTmpFile.size());
67 if(sizePart == 0lu){
68 if(offsetPart <= nbTimeIn){
69 sizePart = (nbTimeIn - offsetPart)/nbPart;
70 if(sizePart == 0lu){
71 std::cerr << "splitMock : cannot split nbTimeIn = " << nbTimeIn << ", into nbPart = "<<nbPart<<" of size sizePart = "<<sizePart<<" and offset offsetPart = " << offsetPart << std::endl;
72 b = false;
73 }else{
74 for(size_t i(0lu); i < nbPart; ++i){
75 VecTime vecMessage;
76 splitVecTime(vecMessage, vecTmpFile, offsetPart + i*sizePart, sizePart);
77 b &= data_save(phoenix_mockMakeOutputFile(baseOutputFile, i, outputExtension), vecMessage);
78 }
79 }
80 }else{
81 VecTime vecMessage;
82// splitVecTime(vecMessage, vecTmpFile, offsetPart, sizePart);
83 b &= data_save(phoenix_mockMakeOutputFile(baseOutputFile, 0lu, outputExtension), vecMessage);
84 }
85
86 }else if(nbPart == 0lu){
87 if((sizePart + offsetPart) <= nbTimeIn){
88 nbPart = (nbTimeIn-offsetPart)/sizePart;
89 for(size_t i(0lu); i < nbPart; ++i){
90 VecTime vecMessage;
91 splitVecTime(vecMessage, vecTmpFile, offsetPart + i*sizePart, sizePart);
92 b &= data_save(phoenix_mockMakeOutputFile(baseOutputFile, i, outputExtension), vecMessage);
93 }
94 }else{
95 VecTime vecMessage;
96// splitVecTime(vecMessage, vecTmpFile, offsetPart, sizePart);
97 b &= data_save(phoenix_mockMakeOutputFile(baseOutputFile, 0lu, outputExtension), vecMessage);
98 }
99 }else{
100 if((sizePart*nbPart + offsetPart) <= nbTimeIn){
101 for(size_t i(0lu); i < nbPart; ++i){
102 VecTime vecMessage;
103 splitVecTime(vecMessage, vecTmpFile, offsetPart + i*sizePart, sizePart);
104 b &= data_save(phoenix_mockMakeOutputFile(baseOutputFile, i, outputExtension), vecMessage);
105 }
106 }else{
107 std::cerr << "splitMock : cannot split nbTimeIn = " << nbTimeIn << ", into nbPart = "<<nbPart<<" of size sizePart = "<<sizePart<<" and offset offsetPart = " << offsetPart << std::endl;
108 b = false;
109 }
110 }
111 }else{
112 b = false;
113 }
114 }
115 return b;
116}
117
118int main(int argc, char** argv){
119 OptionParser parser = createOptionParser();
120 parser.parseArgument(argc, argv);
121
122 const OptionMode & defaultMode = parser.getDefaultMode();
123 std::vector<PPath> vecInputFile;
124 PPath outputFile("");
125 defaultMode.getValue(vecInputFile, "input");
126 defaultMode.getValue(outputFile, "output");
127
128 size_t offsetPart(0lu), sizePart(1lu), nbPart(0lu);
129 defaultMode.getValue(offsetPart, "offset");
130 defaultMode.getValue(sizePart, "sizepart");
131 defaultMode.getValue(nbPart, "nbpart");
132
133 return splitMock(vecInputFile, outputFile, offsetPart, sizePart, nbPart) - 1;
134}
135
136
bool splitMock(const std::vector< PPath > &vecInputFile, const PPath &outputFile, size_t offsetPart, size_t sizePart, size_t nbPart)
Merge mock files.
int main(int argc, char **argv)
PPath phoenix_mockMakeOutputFile(const PPath &baseFileName, size_t indexFile, const PPath &extentionFile)
Make the output file name.
OptionParser createOptionParser()
Create the OptionParser of this program.
void splitVecTime(VecTime &vecOutput, const VecTime vecInput, size_t offsetPart, size_t sizePart)
Split a vector of messages into an other.