HistoSource.cxx
Go to the documentation of this file.
2 #include <iostream>
3 #include "TFile.h"
8 using namespace om;
9 
10 void HistoSourceBase::FindAllMatches(const char* include_pattern,
11  const char* exclude_pattern,
12  std::list<std::string>& objs)
13 {
14  std::string include_p(include_pattern);
15  std::string exclude_p(exclude_pattern);
16  bool in, ex;
17 
18  std::list<std::string> h;
19  this->GetHistogramList(h);
20 
21  std::list<std::string>::iterator i(h.begin());
22  std::list<std::string>::iterator iend(h.end());
23  for (; i!=iend; ++i) {
24  in = (regex_match(*i, include_p)==0);
25  ex = (regex_match(*i, exclude_p)==0);
26  if (in && !ex) objs.push_back(*i);
27  }
28 }
29 
30 //......................................................................
31 
32 HistoFile::HistoFile(const char* n) : fFile(0)
33 {
34  if (n) this->SetName(n);
35 }
36 
37 //......................................................................
38 
40 {
41  if (fFile) { delete fFile; fFile = 0; }
42 }
43 
44 //......................................................................
45 
46 void HistoFile::SetName(const char* nm)
47 {
48  if (fFile) { delete fFile; fFile = 0; }
49  fFile = new TFile(nm, "READ");
50  if (fFile==0) {
51  om::cout << "Unable to open root file " << nm << " for read." << "";
52  }
53 }
54 
55 //......................................................................
56 
57 TH1F* HistoFile::GetTH1FCopy(const char* n)
58 {
59  TObject* obj = fFile->FindObjectAny(n);
60  if (obj==0) return 0;
61  return (TH1F*)obj;
62 }
63 
64 //......................................................................
65 
66 TH2F* HistoFile::GetTH2FCopy(const char* n)
67 {
68  TObject* obj = fFile->FindObjectAny(n);
69  if (obj==0) return 0;
70  return (TH2F*)obj;
71 }
72 
73 //......................................................................
74 
75 void HistoFile::GetHistogramList(std::list<std::string>& h)
76 {
77  TIter next(fFile->GetListOfKeys());
78  TObject* obj = 0;
79  while ((obj = next())) {
80  h.push_back(obj->GetName());
81  }
82 }
83 
84 //......................................................................
85 
86 HistoSHM::HistoSHM(const char* n) : fIPC(0)
87 {
88  this->SetName(n);
89 }
90 
91 //......................................................................
92 
94 {
95  if (fIPC) { delete fIPC; fIPC = 0; }
96 }
97 
98 //......................................................................
99 
101  unsigned int* run,
102  unsigned int* subrun,
103  unsigned int* event,
104  pid_t* pid,
105  long* stime,
106  long* utime,
107  long* cpu,
108  long* rsize,
109  time_t* t)
110 {
111  nm = fIPC->fShmHdl;
112  if (run) *run = fIPC->fIPC->fProcessResources.fRun;
113  if (subrun) *subrun = fIPC->fIPC->fProcessResources.fSubrun;
114  if (event) *event = fIPC->fIPC->fProcessResources.fEvent;
115  if (pid) *pid = fIPC->fIPC->fProcessResources.fPID;
116  if (stime) *stime = fIPC->fIPC->fProcessResources.fSTIME;
117  if (utime) *utime = fIPC->fIPC->fProcessResources.fUTIME;
118  if (cpu) *cpu = fIPC->fIPC->fProcessResources.fCPU;
119  if (rsize) *rsize = fIPC->fIPC->fProcessResources.fRSIZE;
120  if (t) *t = fIPC->fIPC->fProcessResources.fCLOCK;
121 }
122 
123 //......................................................................
124 
125 void HistoSHM::SetName(const char* nm)
126 {
127  if (fIPC) { delete fIPC; fIPC=0; }
128  fIPC = new IPC(kIPC_CLIENT, nm);
129 }
130 
131 //......................................................................
132 
133 TH1F* HistoSHM::GetTH1FCopy(const char* n)
134 {
135  return fIPC->RequestTH1F(n);
136 }
137 
138 //......................................................................
139 
140 TH2F* HistoSHM::GetTH2FCopy(const char* n)
141 {
142  return fIPC->RequestTH2F(n);
143 }
144 
145 //......................................................................
146 
147 void HistoSHM::GetHistogramList(std::list<std::string>& h)
148 {
150 }
151 
152 //......................................................................
153 
154 HistoSource::HistoSource(const char* n) : fSource(0)
155 {
156  this->SetName(n);
157 }
158 
159 //......................................................................
160 
162 {
163  if (fSource) {
164  delete fSource;
165  fSource = 0;
166  }
167 }
168 
169 //......................................................................
170 
171 void HistoSource::SetName(const char* nm)
172 {
173  std::string s(nm);
174  bool is_root = s.find(".root")<s.length();
175  bool is_shm = s.find(".shm")< s.length();
176  if (is_root&&is_shm) abort();
177 
178  if (is_root) fSource = new HistoFile(nm);
179  if (is_shm) fSource = new HistoSHM(nm);
180 }
181 
182 //......................................................................
183 
184 TH1F* HistoSource::GetTH1FCopy(const char* n)
185 {
186  if (fSource) return fSource->GetTH1FCopy(n);
187  return 0;
188 }
189 
190 //......................................................................
191 
192 TH2F* HistoSource::GetTH2FCopy(const char* n)
193 {
194  if (fSource) return fSource->GetTH2FCopy(n);
195  return 0;
196 }
197 
198 //......................................................................
199 
200 void HistoSource::GetHistogramList(std::list<std::string>& h)
201 {
203 }
204 
205 //......................................................................
206 
208  unsigned int* run,
209  unsigned int* subrun,
210  unsigned int* event,
211  pid_t* pid,
212  long* stime,
213  long* utime,
214  long* cpu,
215  long* rsize,
216  time_t* t)
217 {
218  if (fSource) {
219  fSource->GetStatus(nm, run, subrun, event,
220  pid, stime, utime, cpu, rsize, t);
221  }
222 }
223 
224 ////////////////////////////////////////////////////////////////////////
unsigned int fSubrun
Subrun number of last update.
Definition: IPCBlock.h:39
virtual void GetStatus(std::string &nm, unsigned int *run, unsigned int *subrun, unsigned int *event, pid_t *pid, long *stime, long *utime, long *cpu, long *rsize, time_t *t)
Get the histogram server status.
Definition: HistoSource.h:36
long fSTIME
System time.
Definition: IPCBlock.h:42
void SetName(const char *nm)
Set the source name.
Definition: HistoSource.cxx:46
void GetStatus(std::string &nm, unsigned int *run, unsigned int *subrun, unsigned int *event, pid_t *pid, long *stime, long *utime, long *cpu, long *rsize, time_t *t)
Get the histogram server status.
time_t fCLOCK
Time of update.
Definition: IPCBlock.h:46
void GetHistogramList(std::list< std::string > &h)
Get a list of all histograms held by this source.
void SetName(const char *nm)
Set the source name.
long fCPU
Process CPU usage.
Definition: IPCBlock.h:44
Class to manage the shared memory segment.
void FindAllMatches(const char *include_pattern, const char *exclude_pattern, std::list< std::string > &objs)
Definition: HistoSource.cxx:10
HistoFile(const char *n)
Definition: HistoSource.cxx:32
long fRSIZE
Process size.
Definition: IPCBlock.h:45
virtual TH1F * GetTH1FCopy(const char *n)=0
static constexpr Double_t nm
Definition: Munits.h:133
struct IPCBlock * fIPC
Pointer to struct.
Definition: IPC.h:151
int RequestHistoList(std::list< std::string > &hlist)
Definition: IPC.cxx:225
TFile * fFile
The root histogram file.
Definition: HistoSource.h:74
HistoSource(const char *n)
virtual void GetHistogramList(std::list< std::string > &h)=0
Get a list of all histograms held by this source.
static const int kIPC_CLIENT
Definition: IPC.h:24
IPC * fIPC
Shared memory handler.
Definition: HistoSource.h:101
TH2F * GetTH2FCopy(const char *n)
Definition: HistoSource.cxx:66
char fShmHdl[kHdlSz]
Shared memory handle.
Definition: IPC.h:149
const XML_Char * s
Definition: expat.h:262
void GetStatus(std::string &nm, unsigned int *run, unsigned int *subrun, unsigned int *event, pid_t *pid, long *stime, long *utime, long *cpu, long *rsize, time_t *t)
Get the histogram server status.
TH2F * GetTH2FCopy(const char *n)
pid_t fPID
Process ID.
Definition: IPCBlock.h:41
TH2F * GetTH2FCopy(const char *n)
HistoSourceBase * fSource
Definition: HistoSource.h:129
unsigned int fRun
Run number of last update.
Definition: IPCBlock.h:38
Definition: run.py:1
OStream cout
Definition: OStream.cxx:6
TH1F * GetTH1FCopy(const char *n)
Definition: HistoSource.cxx:57
Definition: IPC.h:29
ifstream in
Definition: comparison.C:7
TH1F * GetTH1FCopy(const char *n)
unsigned int fEvent
Event number of last update.
Definition: IPCBlock.h:40
void GetHistogramList(std::list< std::string > &h)
Get a list of all histograms held by this source.
virtual TH2F * GetTH2FCopy(const char *n)=0
int regex_match(const std::string &s, const std::string &p)
Definition: RegexMatch.cxx:7
HistoSHM(const char *n)
Definition: HistoSource.cxx:86
TH1F * RequestTH1F(const char *n)
Definition: IPC.cxx:109
TH1F * GetTH1FCopy(const char *n)
void GetHistogramList(std::list< std::string > &h)
Get a list of all histograms held by this source.
Definition: HistoSource.cxx:75
TH2F * RequestTH2F(const char *n)
Definition: IPC.cxx:165
void next()
Definition: show_event.C:84
long fUTIME
User time.
Definition: IPCBlock.h:43
ProducerResources fProcessResources
Definition: IPCBlock.h:131
Online Monitoring package header.
void SetName(const char *nm)
Set the source name.
enum BeamMode string