ROOT logo
#ifndef __HSTLTOOL_H__
#define __HSTLTOOL_H__

#include "TObject.h"

#include <vector>
#include <map>
#include <iterator>
#include <algorithm>
#include <numeric>
#include <iostream>

using namespace std;

class HSTLTool : public TObject {

public:

    HSTLTool();
    ~HSTLTool();

    //-------------------------------------------------------------
    // min / max element index
    template<typename T> static Int_t maxIndex(vector<T>& v){
	return v.empty() ? -1 : max_element(v.begin(), v.end()) - v.begin();
    }
    template<typename T> static Int_t minIndex(vector<T>& v){
	return v.empty() ? -1 : min_element(v.begin(), v.end()) - v.begin();
    }
    //-------------------------------------------------------------
    // min max element
    template<typename T> static T maxVal(vector<T>& v){
	return v.empty() ? -1 : *max_element(v.begin(), v.end());
    }
    template<class T> static T minVal(vector<T>& v){
	return v.empty() ? -1 : *min_element(v.begin(), v.end());
    }
    //-------------------------------------------------------------
    // sum up range
    template<typename T> static T sum(vector<T>& v,Int_t ind1 = -1,Int_t ind2 =-1){
	Int_t size = v.size();
	T sum = 0;
	Int_t start = ind1 >=0 && ind1 < size ? ind1 : 0;
	Int_t end   = ind2 >=0 && ind2 < size ? ind2 : size;
	for(Int_t i = start; i < end; i ++){
	    sum += v[i];
	}
	return sum;
    }

    //-------------------------------------------------------------
    // find in range
    template<typename T> static Int_t find(vector<T>& v,T val){
	typename vector<T>::iterator result = std::find(v.begin(), v.end(), val);
	if(result == v.end()) return -1;
	else {
	    return result - v.begin();
	}
    }

    /*
     //-------------------------------------------------------------
     // find in range
     template<typename T> static Int_t find(vector<T>& v,T val, Int_t ind1=-1, Int_t ind2=-1){
     Int_t size = v.size();
     Int_t start = ind1 >=0 && ind1 < size-1 ? ind1 : 0;
     Int_t end   = ind2 >=0 && ind2 < size-1 ? ind2 : size;
     if(size == 0 || ind2 < ind1) return -1;

     typename vector<T>::iterator i1 = (v.begin() + start);
     typename vector<T>::iterator i2 = (v.begin() + end);

     cout<<v.begin()<<" "<<v.end()<<" "<<i1<<" "<<i2<<endl;

     typename vector<T>::iterator result = std::find( (v.begin() + start), (v.begin() + end), val);
     cout<<"test "<<*result<<endl;
     if(result == v.end()) return -1;
     else {
     return result - v.begin();
     }
     }
     */
    //-------------------------------------------------------------
    // print range
    template<typename T> static T print(vector<T>& v,Int_t ind1 = -1,Int_t ind2 =-1){
	Int_t size = v.size();
	T sum = 0;
	Int_t start = ind1 >=0 && ind1 < size ? ind1 : 0;
	Int_t end   = ind2 >=0 && ind2 < size ? ind2 : size;
	for(Int_t i = start; i < end; i ++){
	    cout<<i<<" \t: "<<v[i]<<endl;
	}
	return sum;
    }

    ClassDef(HSTLTool,0)
};

#endif //__HSTLTOOL_H__
 hstltool.h:1
 hstltool.h:2
 hstltool.h:3
 hstltool.h:4
 hstltool.h:5
 hstltool.h:6
 hstltool.h:7
 hstltool.h:8
 hstltool.h:9
 hstltool.h:10
 hstltool.h:11
 hstltool.h:12
 hstltool.h:13
 hstltool.h:14
 hstltool.h:15
 hstltool.h:16
 hstltool.h:17
 hstltool.h:18
 hstltool.h:19
 hstltool.h:20
 hstltool.h:21
 hstltool.h:22
 hstltool.h:23
 hstltool.h:24
 hstltool.h:25
 hstltool.h:26
 hstltool.h:27
 hstltool.h:28
 hstltool.h:29
 hstltool.h:30
 hstltool.h:31
 hstltool.h:32
 hstltool.h:33
 hstltool.h:34
 hstltool.h:35
 hstltool.h:36
 hstltool.h:37
 hstltool.h:38
 hstltool.h:39
 hstltool.h:40
 hstltool.h:41
 hstltool.h:42
 hstltool.h:43
 hstltool.h:44
 hstltool.h:45
 hstltool.h:46
 hstltool.h:47
 hstltool.h:48
 hstltool.h:49
 hstltool.h:50
 hstltool.h:51
 hstltool.h:52
 hstltool.h:53
 hstltool.h:54
 hstltool.h:55
 hstltool.h:56
 hstltool.h:57
 hstltool.h:58
 hstltool.h:59
 hstltool.h:60
 hstltool.h:61
 hstltool.h:62
 hstltool.h:63
 hstltool.h:64
 hstltool.h:65
 hstltool.h:66
 hstltool.h:67
 hstltool.h:68
 hstltool.h:69
 hstltool.h:70
 hstltool.h:71
 hstltool.h:72
 hstltool.h:73
 hstltool.h:74
 hstltool.h:75
 hstltool.h:76
 hstltool.h:77
 hstltool.h:78
 hstltool.h:79
 hstltool.h:80
 hstltool.h:81
 hstltool.h:82
 hstltool.h:83
 hstltool.h:84
 hstltool.h:85
 hstltool.h:86
 hstltool.h:87
 hstltool.h:88
 hstltool.h:89
 hstltool.h:90
 hstltool.h:91
 hstltool.h:92
 hstltool.h:93
 hstltool.h:94
 hstltool.h:95
 hstltool.h:96
 hstltool.h:97
 hstltool.h:98
 hstltool.h:99