1 #ifndef RECOTOOL_CMERGEBOOKKEEPER_CXX 2 #define RECOTOOL_CMERGEBOOKKEEPER_CXX 18 std::vector<unsigned short>::reserve(nclusters);
20 for(
size_t i=0; i<nclusters; ++i) {
32 throw CMTException(Form(
"<<%s>> Two input clusters identical (%d)",__FUNCTION__,index1));
35 if( index1 >= this->size() || index2 >= this->size() )
37 throw CMTException(Form(
"Input cluster index (%d and/or %d) out of range",index1,index2));
39 auto out_index1 = this->at(index1);
40 auto out_index2 = this->at(index2);
42 if(out_index1 == out_index2)
43 throw CMTException(Form(
"Cluster %d and %d already merged!",index1,index2));
45 if(out_index2 < out_index1) std::swap(out_index1,out_index2);
52 unsigned short index2)
57 throw CMTException(Form(
"<<%s>> Two input clusters identical (%d)",__FUNCTION__,index1));
60 if( index1 >= this->size() || index2 >= this->size() )
62 throw CMTException(Form(
"Input cluster index (%d and/or %d) out of range",index1,index2));
64 auto out_index1 = this->at(index1);
65 auto out_index2 = this->at(index2);
67 if(out_index1 == out_index2)
return true;
69 if(out_index2 < out_index1) std::swap(out_index1,out_index2);
80 throw CMTException(Form(
"<<%s>> Two input clusters identical (%d)",__FUNCTION__,index1));
83 if( index1 >= this->size() || index2 >= this->size() )
85 throw CMTException(Form(
"Input cluster index (%d and/or %d) out of range",index1,index2));
87 auto out_index1 = this->at(index1);
88 auto out_index2 = this->at(index2);
90 if(out_index1 == out_index2)
return;
92 if(out_index2 < out_index1) std::swap(out_index1,out_index2);
96 throw CMTException(Form(
"Clusters (%d,%d) correspond to output (%d,%d) which is prohibited to merge",
98 out_index1,out_index2));
103 for(
auto &v : (*
this)) {
105 if( v == out_index1 || v == out_index2 )
107 else if( v > out_index2 )
115 for(
size_t index=0; index < out_index1; ++index) {
117 size_t tmp_out_index1 = out_index1 - index;
118 size_t tmp_out_index2 = out_index2 - index;
125 for(
size_t in_index=tmp_out_index2;
146 for(
size_t in_index = 1;
150 if( (in_index + out_index1) < out_index2 ) {
159 _prohibit_merge.at(in_index + out_index1).at(out_index2 - (in_index+out_index1))
185 for(
size_t index = out_index1+1;
188 for(
size_t in_index = (out_index2 - index);
199 for(
size_t index = out_index2;
204 for(
size_t in_index = 0;
222 std::cout<<
"Merge Result:"<<std::endl;
223 for(
auto const& v : *
this)
225 std::cout<<std::endl<<std::endl;
227 std::cout<<
"Prohibit Status:"<<std::endl;
230 for(
auto const &b : bs) {
232 if(b) std::cout<<
"\033[93mT\033[00m ";
233 else std::cout<<
"\033[95mF\033[00m ";
236 std::cout<<std::endl;
238 std::cout<<std::endl;
244 if( index1 >= this->size() || index2 >= this->size() )
245 throw CMTException(Form(
"Invalid cluster index: %d or %d",index1,index2));
247 return this->at(index1) == this->at(index2);
254 if( index1 >= this->size() )
255 throw CMTException(Form(
"Invalid cluster index: %d ",index1));
257 auto out_index = this->at(index1);
258 std::vector<unsigned short> result;
260 for(
size_t i=0; i<this->size(); ++i)
261 if( this->at(i) == out_index ) result.push_back(i);
272 for(
size_t i=0; i<this->size(); ++i)
273 result.at(this->at(i)).push_back(i);
279 std::vector<std::vector<unsigned short> > my_result;
281 if(my_result.size() != another.size()) {
282 throw CMTException(Form(
"Input has an incompatible size (%zu != %zu)",
290 std::vector<std::vector<unsigned short> > another_result;
292 if(another_result.size() >= my_result.size())
293 throw CMTException(Form(
"The input has equal or more number of output clusters (%zu>=%zu)",
294 another_result.size(),
299 for(
auto const& ares : another_result) {
301 if(ares.size()==1)
continue;
304 unsigned short target = my_result.at(ares.at(0)).at(0);
306 for(
auto const &res_index : ares) {
308 for(
auto const &orig_index : my_result.at(res_index)) {
310 if(target == orig_index)
continue;
312 else this->
Merge(target,orig_index);
cout<< "-> Edep in the target
Class def header for a class CMergeBookKeeper.
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.