Sorter.cpp
Go to the documentation of this file.
1 /*
2  * File: Sorter.cpp
3  * Author: denis
4  *
5  * Created on February 13, 2012, 10:09 AM
6  */
7 
8 #ifdef NOVACMAKE
10 #else
11 #include "MockDataDAQ/Sorter.h"
12 #endif
13 
14 #include <algorithm>
15 #include <boost/bind.hpp>
16 #include <stdio.h>
17 #include <iostream>
18 #include <utility>
19 
20 namespace mcdatadaq{
21 
22 //------------------------------------------------------------------------------
24 
25 //------------------------------------------------------------------------------
27 
28 //------------------------------------------------------------------------------
29 bool Sorter::addNumber(const unsigned long long number){
30 
31  const uint32_t current_index = _numberIndexPair.size();
32 
33  _numberIndexPair.push_back(std::make_pair(number, current_index));
34 
35  return true;
36 }
37 
38 //------------------------------------------------------------------------------
39 bool Sorter::sort(){
40 
41  /// Sorting by the numbers (whuch come first in the pair)
42  std::sort(_numberIndexPair.begin(), _numberIndexPair.end(),
43  boost::bind(&number_index_pair_t::first, _1) <
44  boost::bind(&number_index_pair_t::first, _2));
45 
46  return true;
47 }
48 
49 //------------------------------------------------------------------------------
50 bool Sorter::getIndeces(std::vector <uint32_t>& index_vector) const {
51 
52  for(number_index_pair_vector_t::const_iterator itr = _numberIndexPair.begin(); itr != _numberIndexPair.end(); ++itr)
53  index_vector.push_back((*itr).second); //Fill the true order
54 
55  return true;
56 }
57 
58 //------------------------------------------------------------------------------
59 std::vector <uint32_t> Sorter::getIndeces() const {
60  std::vector <uint32_t> index_vector;
61 
62  getIndeces(index_vector);
63 
64  return index_vector;
65 }
66 
67 //------------------------------------------------------------------------------
68 bool Sorter::print() const{
69 
70  printf("-----------------------------------------------------------------\n");
71  printf("Sorter print:\n");
72  printf("-----------------------------------------------------------------\n");
73 
74  for(number_index_pair_vector_t::const_iterator itr = _numberIndexPair.begin(); itr != _numberIndexPair.end(); ++itr){
75 
76  const unsigned long long first_number = (*itr).first;
77  const uint32_t index = (*itr).second;
78 
79  std::cout<<std::hex<<first_number<<"x";
80  std::cout<<std::dec<<" ("<<first_number<<")";
81  std::cout<<" index="<<index<<std::endl;
82 
83  }// end of loop
84 
85  printf("-----------------------------------------------------------------\n");
86  printf("End of Sorter print:\n");
87  printf("-----------------------------------------------------------------\n");
88 
89  return true;
90 
91 }
92 
93 }// end of namespace
std::pair< Spectrum *, CheatDecomp * > make_pair(SpectrumLoaderBase &loader_data, SpectrumLoaderBase &loader_mc, HistAxis *axis, Cut *cut, const SystShifts &shift, const Var &wei)
Definition: DataMCLoad.C:336
number_index_pair_vector_t _numberIndexPair
Definition: Sorter.h:45
bool addNumber(const unsigned long long)
Add number. The index assigned to the number is the order in which the number is added.
Definition: Sorter.cpp:29
Something conflicts with RandomNumberGenerator. Keep DAQSimulator.h include below Art Framework inclu...
std::vector< uint32_t > getIndeces() const
Get indeces.
Definition: Sorter.cpp:59
printf("%d Experimental points found\n", nlines)
OStream cout
Definition: OStream.cxx:6
bool sort()
Sorting the indeces by numbers.
Definition: Sorter.cpp:39
bool print() const
Print the numbers and current order of indeces.
Definition: Sorter.cpp:68