GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SpecViewer.h
Go to the documentation of this file.
1 #include "TH1.h"
2 #include "TH2I.h"
3 #include "TGraph.h"
4 
5 template <typename T>
6 void read_1d_data(std::istream &in, TH1 *hist)
7 {
8  std::vector<T> buffer(hist->GetNbinsX());
9  in.read((char*)&buffer[0], buffer.size()*sizeof(T));
10  for (unsigned i = 0; i < buffer.size(); ++i)
11  hist->SetBinContent(i+1, buffer[i]);
12 }
13 
14 template <typename T>
15 void read_1d_data_to_graph(std::istream &in, TGraph *graph)
16 {
17  std::vector<T> buffer(graph->GetN());
18  in.read((char*)&buffer[0], buffer.size()*sizeof(T));
19  for (unsigned i = 0; i < buffer.size(); ++i)
20  graph->SetPoint(i,i*10.,buffer[i]);
21 }
22 
23 template <typename T>
24 void read_2d_data(std::istream &in, TH2I *hist)
25 {
26  std::vector<T> buffer(hist->GetNbinsX()* hist->GetNbinsY());
27  in.read((char*)&buffer[0], buffer.size()*sizeof(T));
28  for (int j = 0; j < hist->GetNbinsY(); ++j)
29  for (int i = 0; i < hist->GetNbinsX(); ++i)
30  {
31  hist->SetBinContent(i+1,j+1, buffer[j+i*hist->GetNbinsY()]);
32  }
33 }
34 
36 {
37  // basename__n1-n2-n3-n4-...-nN-datatype__specifier.type
38  std::string basename;
39  std::string specifier;
40  std::string format;
41  std::string histtype;
42  std::string datatype;
43  std::vector<int> number_stack;
44 
45  explicit DinoFileInfo(const std::string &filename)
46  {
47  // cut the proceeding directory information from the filename
48  std::string workname(filename, filename.find_last_of("/")+1);
49  for (uint i = 0; i < workname.size(); ++i)
50  if (workname[i] == '_' || workname[i] == '.')
51  workname[i] = ' ';
52 
53  std::istringstream workin(workname);
54 
55  workin >> basename >> format >> specifier >> histtype;
56 
57  std::istringstream format_in(format);
58  // read the numbers from the format string
59  for (;;)
60  {
61  int num;
62  char c;
63  format_in >> c;
64  format_in.putback(c);
65  if (!isdigit(c))
66  {
67  format_in >> datatype;
68  break;
69  }
70  else
71  format_in >> num >> c;
72  if (!format_in || c != '-')
73  break;
74  number_stack.push_back(num);
75  }
76  }
77 };
std::string histtype
Definition: SpecViewer.h:41
std::string format
Definition: SpecViewer.h:40
void read_2d_data(std::istream &in, TH2I *hist)
Definition: SpecViewer.h:24
std::string basename
Definition: SpecViewer.h:38
void read_1d_data(std::istream &in, TH1 *hist)
Definition: SpecViewer.h:6
std::string datatype
Definition: SpecViewer.h:42
void read_1d_data_to_graph(std::istream &in, TGraph *graph)
Definition: SpecViewer.h:15
std::string specifier
Definition: SpecViewer.h:39
DinoFileInfo(const std::string &filename)
Definition: SpecViewer.h:45
std::vector< int > number_stack
Definition: SpecViewer.h:43