1 | /*
|
---|
2 | * ResultContainer_impl.hpp
|
---|
3 | *
|
---|
4 | * Created on: Apr 22, 2014
|
---|
5 | * Author: heber
|
---|
6 | */
|
---|
7 |
|
---|
8 | #ifndef RESULTCONTAINER_IMPL_HPP_
|
---|
9 | #define RESULTCONTAINER_IMPL_HPP_
|
---|
10 |
|
---|
11 | // include config.h
|
---|
12 | #ifdef HAVE_CONFIG_H
|
---|
13 | #include <config.h>
|
---|
14 | #endif
|
---|
15 |
|
---|
16 | #include "Fragmentation/Automation/ResultContainer.hpp"
|
---|
17 |
|
---|
18 | #include "CodePatterns/Assert.hpp"
|
---|
19 | #include "CodePatterns/Log.hpp"
|
---|
20 | #include "CodePatterns/toString.hpp"
|
---|
21 |
|
---|
22 | template <typename T>
|
---|
23 | void ResultContainer<T>::ConvertFragmentResultTo(
|
---|
24 | const std::vector<FragmentResult::ptr> &results,
|
---|
25 | std::vector<T> &fragmentData) const
|
---|
26 | {
|
---|
27 | // extract results
|
---|
28 | fragmentData.clear();
|
---|
29 | fragmentData.reserve(results.size());
|
---|
30 |
|
---|
31 | LOG(2, "DEBUG: Parsing now through " << results.size() << " results.");
|
---|
32 | for (std::vector<FragmentResult::ptr>::const_iterator iter = results.begin();
|
---|
33 | iter != results.end(); ++iter) {
|
---|
34 | //LOG(1, "RESULT: job #"+toString((*iter)->getId())+": "+toString((*iter)->result));
|
---|
35 | T extractedData;
|
---|
36 | std::stringstream inputstream((*iter)->result);
|
---|
37 | LOG(2, "DEBUG: First 50 characters FragmentResult's string: "+(*iter)->result.substr(0, 50));
|
---|
38 | boost::archive::text_iarchive ia(inputstream);
|
---|
39 | ia >> extractedData;
|
---|
40 | LOG(1, "INFO: extracted data of #" << (*iter)->getId() << " is " << extractedData << ".");
|
---|
41 | fragmentData.push_back(extractedData);
|
---|
42 | }
|
---|
43 |
|
---|
44 | ASSERT( results.size() == fragmentData.size(),
|
---|
45 | "ResultContainer::ConvertFragmentResultTo() - the number of extracted data differs from the number of results.");
|
---|
46 | }
|
---|
47 |
|
---|
48 | template <typename T>
|
---|
49 | void ResultContainer<T>::insertResults(
|
---|
50 | const std::vector<FragmentResult::ptr> &fragmentresults,
|
---|
51 | std::vector<T> &fragmentData)
|
---|
52 | {
|
---|
53 | std::vector<FragmentResult::ptr>::const_iterator resultiter = fragmentresults.begin();
|
---|
54 | typename std::vector<T>::const_iterator dataiter = fragmentData.begin();
|
---|
55 | for(;resultiter != fragmentresults.end(); ++resultiter, ++dataiter) {
|
---|
56 | const JobId_t _id = (*resultiter)->getId();
|
---|
57 | if ((*resultiter)->exitflag == 0) {
|
---|
58 | #ifndef NDEBUG
|
---|
59 | std::pair<typename std::map<JobId_t, T>::iterator, bool> inserter =
|
---|
60 | #endif
|
---|
61 | IdData.insert( std::make_pair( _id, *dataiter) );
|
---|
62 | ASSERT( inserter.second,
|
---|
63 | "ResultContainer::insertResults() - result id "
|
---|
64 | +toString(inserter.first->first)+" already present.");
|
---|
65 | }
|
---|
66 | }
|
---|
67 | ASSERT( dataiter == fragmentData.end(),
|
---|
68 | "ResultContainer::insertResults() - fragmentresults and fragmentdata differ in size.");
|
---|
69 | }
|
---|
70 |
|
---|
71 |
|
---|
72 | #endif /* RESULTCONTAINER_IMPL_HPP_ */
|
---|