9#include "daq/dqm/HistoManager.h"
23HistoManager::~HistoManager()
27bool HistoManager::add(
const string& subdir,
const string& name,
int pid, TH1* histo)
33 if (m_subdir.find(subdir) == m_subdir.end()) {
35 map<string, map<int, TH1*>>* newsubdir =
new map<string, map<int, TH1*>>;
36 map<int, TH1*>* newhlist =
new map<int, TH1*> ;
37 (*newsubdir)[name] = *newhlist;
38 m_subdir[subdir] = *newsubdir;
40 map<string, TH1*>* newmergedir =
new map<string, TH1*>;
41 (*newmergedir)[name] = NULL;
42 m_mergedir[subdir] = *newmergedir;
43 printf(
"HistoManager: new list created for subdir %s\n", subdir.c_str());
50 map<string, map<int, TH1*>>& dirlist = m_subdir[subdir];
51 map<int, TH1*>& hlist = dirlist[name];
52 if (hlist.find(pid) == hlist.end()) {
62bool HistoManager::update(
const string& subdir,
const string& name,
int pid, TH1* histo)
65 if (add(subdir, name, pid, histo))
return true;
69 map<string, map<int, TH1*>>& dirlist = m_subdir[subdir];
70 map<int, TH1*>& hlist = dirlist[name];
73 TH1* prevhisto = hlist[pid];
74 if (prevhisto != NULL)
delete prevhisto;
83TH1* HistoManager::get(
const string& subdir,
const string& name,
int pid)
85 const map<string, map<int, TH1*>>& dirlist = m_subdir[subdir];
86 const map<int, TH1*>& hlist = dirlist.at(name);
87 TH1* hist = hlist.at(pid);
91bool HistoManager::merge()
95 for (map<
string, map<
string, map<int, TH1*>>>::iterator is =
96 m_subdir.begin(); is != m_subdir.end(); ++is) {
97 map<string, map<int, TH1*>>& dirlist = is->second;
98 map<string, TH1*>& mergelist = m_mergedir[is->first];
101 if (m_memfile->GetMemFile() == NULL) exit(-99);
102 (m_memfile->GetMemFile())->cd();
115 for (map<
string, std::map<int, TH1*> >::iterator it = dirlist.begin();
116 it != dirlist.end(); ++it) {
117 string name = it->first;
118 map<int, TH1*>& hmap = it->second;
119 if (mergelist[name] != NULL) {
120 TH1* merge_hist = mergelist[name];
125 for (map<int, TH1*>::iterator ih = hmap.begin(); ih != hmap.end();
128 TH1* hist = ih->second;
132 if (mergelist[name] == NULL) {
137 newname = subdir +
"/" + string(hist->GetName());
139 newname = string(hist->GetName());
140 hist->SetName(newname.c_str());
141 TH1* mhist = (TH1*)hist->Clone();
142 mergelist[name] = mhist;
149 TH1* merge_hist = mergelist[name];
150 merge_hist->Add(hist);
151 merge_hist->SetTitle(hist->GetTitle());
157 m_memfile->UpdateSharedMem();
164void HistoManager::clear()
166 for (map<
string, map<
string, map<int, TH1*>>>::iterator is = m_subdir.begin(); is != m_subdir.end(); ++is) {
167 map<string, map<int, TH1*>>& dirlist = is->second;
169 for (map<
string, std::map<int, TH1*> >::iterator it = dirlist.begin(); it != dirlist.end(); ++it) {
170 map<int, TH1*>& hmap = it->second;
172 for (map<int, TH1*>::iterator ih = hmap.begin(); ih != hmap.end(); ++ih) {
173 TH1* hist = ih->second;
174 if (hist != NULL)
delete hist;
183 for (map<
string, map<string, TH1*> >::iterator is = m_mergedir.begin(); is != m_mergedir.end(); ++is) {
184 map<string, TH1*>& dirlist = is->second;
186 for (map<string, TH1*>::iterator it = dirlist.begin(); it != dirlist.end(); ++it) {
187 TH1* hist = it->second;
188 if (hist != NULL)
delete hist;
196 printf(
"HistoManager: clear\n");
197 m_memfile->ClearSharedMem();
201void HistoManager::filedump(std::string outfile)
203 printf(
"dump to dqm file = %s\n", outfile.c_str());
205 m_memfile->SaveToFile(outfile);
Abstract base class for different kinds of events.