9 #include "daq/dqm/HistoManager.h"
16 HistoManager::HistoManager(
DqmMemFile* memfile)
21 HistoManager::~HistoManager()
25 bool HistoManager::add(
string& subdir,
string& name,
int pid, TH1* histo)
31 if (m_subdir.find(subdir) == m_subdir.end()) {
33 map<string, map<int, TH1*>>* newsubdir =
new map<string, map<int, TH1*>>;
34 map<int, TH1*>* newhlist =
new map<int, TH1*> ;
35 (*newsubdir)[name] = *newhlist;
36 m_subdir[subdir] = *newsubdir;
38 map<string, TH1*>* newmergedir =
new map<string, TH1*>;
39 (*newmergedir)[name] = NULL;
40 m_mergedir[subdir] = *newmergedir;
41 printf(
"HistoManager: new list created for subdir %s\n", subdir.c_str());
48 map<string, map<int, TH1*>>& dirlist = m_subdir[subdir];
49 map<int, TH1*>& hlist = dirlist[name];
50 if (hlist.find(pid) == hlist.end()) {
60 bool HistoManager::update(
string& subdir,
string& name,
int pid, TH1* histo)
63 if (add(subdir, name, pid, histo))
return true;
67 map<string, map<int, TH1*>>& dirlist = m_subdir[subdir];
68 map<int, TH1*>& hlist = dirlist[name];
71 TH1* prevhisto = hlist[pid];
72 if (prevhisto != NULL)
delete prevhisto;
81 TH1* HistoManager::get(
string& subdir,
string& name,
int pid)
83 map<string, map<int, TH1*>>& dirlist = m_subdir[subdir];
84 map<int, TH1*>& hlist = dirlist[name];
85 TH1* hist = hlist[pid];
89 bool HistoManager::merge()
93 for (map<
string, map<
string, map<int, TH1*>>>::iterator is =
94 m_subdir.begin(); is != m_subdir.end(); ++is) {
95 map<string, map<int, TH1*>>& dirlist = is->second;
96 map<string, TH1*>& mergelist = m_mergedir[is->first];
99 if (m_memfile->GetMemFile() == NULL) exit(-99);
100 (m_memfile->GetMemFile())->cd();
113 for (map<
string, std::map<int, TH1*> >::iterator it = dirlist.begin();
114 it != dirlist.end(); ++it) {
115 string name = it->first;
116 map<int, TH1*>& hmap = it->second;
117 if (mergelist[name] != NULL) {
118 TH1* merge_hist = mergelist[name];
123 for (map<int, TH1*>::iterator ih = hmap.begin(); ih != hmap.end();
126 TH1* hist = ih->second;
130 if (mergelist[name] == NULL) {
135 newname = subdir +
"/" + string(hist->GetName());
137 newname = string(hist->GetName());
138 hist->SetName(newname.c_str());
139 TH1* mhist = (TH1*)hist->Clone();
140 mergelist[name] = mhist;
147 TH1* merge_hist = mergelist[name];
148 merge_hist->Add(hist);
149 merge_hist->SetTitle(hist->GetTitle());
155 m_memfile->UpdateSharedMem();
162 void HistoManager::clear()
164 for (map<
string, map<
string, map<int, TH1*>>>::iterator is = m_subdir.begin(); is != m_subdir.end(); ++is) {
165 map<string, map<int, TH1*>>& dirlist = is->second;
167 for (map<
string, std::map<int, TH1*> >::iterator it = dirlist.begin(); it != dirlist.end(); ++it) {
168 map<int, TH1*>& hmap = it->second;
170 for (map<int, TH1*>::iterator ih = hmap.begin(); ih != hmap.end(); ++ih) {
171 TH1* hist = ih->second;
172 if (hist != NULL)
delete hist;
181 for (map<
string, map<string, TH1*> >::iterator is = m_mergedir.begin(); is != m_mergedir.end(); ++is) {
182 map<string, TH1*>& dirlist = is->second;
184 for (map<string, TH1*>::iterator it = dirlist.begin(); it != dirlist.end(); ++it) {
185 TH1* hist = it->second;
186 if (hist != NULL)
delete hist;
194 printf(
"HistoManager: clear\n");
195 m_memfile->ClearSharedMem();
Abstract base class for different kinds of events.