ATLAS Offline Software
Loading...
Searching...
No Matches
Contour.h
Go to the documentation of this file.
1/* emacs: this is -*- c++ -*- */
10
11
12#ifndef CONTOUR_H
13#define CONTOUR_H
14
15#include <iostream>
16#include <vector>
17#include <cstdlib>
18#include <cstdio>
19
21
22
23template<typename T>
24class Contour : public std::vector< std::pair<double, T*> > {
25
26 typedef std::pair<double, T*> value_type;
27
28public:
29
30 Contour(const std::string& s) : mname(s), mdir(s) { }
31
32 virtual ~Contour() {
33 for ( unsigned i=this->size()-1 ; i-- ; ) if ( this->at(i).second ) delete this->at(i).second;
34 }
35
36 void ranges( const std::vector<double>& d, T* t ) {
37 if ( d.empty() ) return;
38 ranges( &d[0], d.size(), t );
39 }
40
41 void ranges( const double* d, unsigned N, T* t ) {
42 mdir.push();
43 for ( unsigned i=1 ; i<N ; i++ ) {
44 this->push_back( value_type( d[i-1], new T(*t) ) );
45 }
46 this->push_back( value_type( d[N-1], 0 ) );
47 mdir.pop();
48 }
49
50 T* find( double d ) {
51 if ( this->empty() ) return 0;
52 for ( unsigned i=this->size()-1 ; i-- ; ) {
53 if ( d>=this->at(i).first && d<this->at(i+1).first ) return this->at(i).second;
54 }
55 return 0;
56 }
57
58 std::string name() const { return mname; }
59
60 void Write(const std::string& s="") {
61 mdir.push();
62 for ( unsigned i=this->size()-1 ; i-- ; ) {
63 if ( this->at(i).second ) {
64 char _name[64];
65 if ( s=="" ) std::sprintf( _name, "%s_%d", mname.c_str(), i-1 );
66 else std::sprintf( _name, "%s_%d", s.c_str(), i-1 );
67 this->at(i).second->Bayes()->Write(_name);
68 }
69 }
70 mdir.pop();
71 }
72
73 TIDDirectory* dir() { return &mdir; }
74
75private:
76
77 std::string mname;
78
80
81};
82
83template<typename T>
84inline std::ostream& operator<<( std::ostream& s, const Contour<T>& _c ) {
85 s << "Contour : " << _c.name() << "\n";
86 for ( unsigned i=0 ; i<_c.size() ; i++ ) s << "\t d " << _c[i].first << "\n";
87 return s;
88}
89
90
91#endif // CONTOUR_H
92
93
94
95
96
97
98
99
100
101
std::ostream & operator<<(std::ostream &s, const Contour< T > &_c)
Definition Contour.h:84
static const Attributes_t empty
T * find(double d)
Definition Contour.h:50
std::string mname
Definition Contour.h:77
std::pair< double, T * > value_type
Definition Contour.h:26
Contour(const std::string &s)
Definition Contour.h:30
TIDDirectory * dir()
Definition Contour.h:73
virtual ~Contour()
Definition Contour.h:32
void ranges(const double *d, unsigned N, T *t)
Definition Contour.h:41
void ranges(const std::vector< double > &d, T *t)
Definition Contour.h:36
void Write(const std::string &s="")
Definition Contour.h:60
std::string name() const
Definition Contour.h:58
TIDDirectory mdir
Definition Contour.h:79