9#include "daq/dqm/HistoManager2.h"
20HistoManager2::HistoManager2(std::string name)
27HistoManager2::~HistoManager2()
31bool HistoManager2::add(
const string& subdir,
const string& name,
int pid, TH1* histo)
37 if (m_subdir.find(subdir) == m_subdir.end()) {
39 map<string, map<int, TH1*>>* newsubdir =
new map<string, map<int, TH1*>>;
40 map<int, TH1*>* newhlist =
new map<int, TH1*> ;
41 (*newsubdir)[name] = *newhlist;
42 m_subdir[subdir] = *newsubdir;
44 map<string, TH1*>* newmergedir =
new map<string, TH1*>;
45 (*newmergedir)[name] = NULL;
46 m_mergedir[subdir] = *newmergedir;
47 printf(
"HistoManager2: new list created for subdir %s\n", subdir.c_str());
54 map<string, map<int, TH1*>>& dirlist = m_subdir[subdir];
55 map<int, TH1*>& hlist = dirlist[name];
56 if (hlist.find(pid) == hlist.end()) {
66bool HistoManager2::update(
const string& subdir,
const string& name,
int pid, TH1* histo)
69 if (add(subdir, name, pid, histo))
return true;
73 map<string, map<int, TH1*>>& dirlist = m_subdir[subdir];
74 map<int, TH1*>& hlist = dirlist[name];
77 TH1* prevhisto = hlist[pid];
78 if (prevhisto != NULL)
delete prevhisto;
87TH1* HistoManager2::get(
const string& subdir,
const string& name,
int pid)
89 const map<string, map<int, TH1*>>& dirlist = m_subdir[subdir];
90 const map<int, TH1*>& hlist = dirlist.at(name);
91 TH1* hist = hlist.at(pid);
95bool HistoManager2::merge()
100 for (map<
string, map<
string, map<int, TH1*>>>::iterator is =
101 m_subdir.begin(); is != m_subdir.end(); ++is) {
102 map<string, map<int, TH1*>>& dirlist = is->second;
103 map<string, TH1*>& mergelist = m_mergedir[is->first];
119 for (map<
string, std::map<int, TH1*> >::iterator it = dirlist.begin();
120 it != dirlist.end(); ++it) {
121 string name = it->first;
122 map<int, TH1*>& hmap = it->second;
123 if (mergelist[name] != NULL) {
124 TH1* merge_hist = mergelist[name];
129 for (map<int, TH1*>::iterator ih = hmap.begin(); ih != hmap.end();
132 TH1* hist = ih->second;
136 if (mergelist[name] == NULL) {
141 newname = subdir +
"/" + string(hist->GetName());
143 newname = string(hist->GetName());
144 hist->SetName(newname.c_str());
145 TH1* mhist = (TH1*)hist->Clone();
146 mergelist[name] = mhist;
153 TH1* merge_hist = mergelist[name];
154 merge_hist->Add(hist);
155 merge_hist->SetTitle(hist->GetTitle());
162 fh =
new TFile((
"/dev/shm/tmp_" + m_name).c_str(),
"RECREATE");
165 printf(
"HistoManager2 cannot open file : %s\n", (
"/dev/shm/tmp_" + m_name).c_str());
170 for (map<
string, map<
string, map<int, TH1*>>>::iterator is =
171 m_subdir.begin(); is != m_subdir.end(); ++is) {
172 map<string, map<int, TH1*>>& dirlist = is->second;
173 map<string, TH1*>& mergelist = m_mergedir[is->first];
175 for (map<
string, std::map<int, TH1*> >::iterator it = dirlist.begin();
176 it != dirlist.end(); ++it) {
177 string name = it->first;
178 TH1* merge_hist = mergelist[name];
179 if (merge_hist) merge_hist->Write();
186 if (rename((
"/dev/shm/tmp_" + m_name).c_str(), (
"/dev/shm/" + m_name).c_str())) {
187 perror(
"Rename dhm file failed ");
194void HistoManager2::clear()
196 for (map<
string, map<
string, map<int, TH1*>>>::iterator is = m_subdir.begin(); is != m_subdir.end(); ++is) {
197 map<string, map<int, TH1*>>& dirlist = is->second;
199 for (map<
string, std::map<int, TH1*> >::iterator it = dirlist.begin(); it != dirlist.end(); ++it) {
200 map<int, TH1*>& hmap = it->second;
202 for (map<int, TH1*>::iterator ih = hmap.begin(); ih != hmap.end(); ++ih) {
203 TH1* hist = ih->second;
204 if (hist != NULL)
delete hist;
213 for (map<
string, map<string, TH1*> >::iterator is = m_mergedir.begin(); is != m_mergedir.end(); ++is) {
214 map<string, TH1*>& dirlist = is->second;
216 for (map<string, TH1*>::iterator it = dirlist.begin(); it != dirlist.end(); ++it) {
217 TH1* hist = it->second;
218 if (hist != NULL)
delete hist;
227 unlink((
"/dev/shm/tmp_" + m_name).c_str());
228 unlink((
"/dev/shm/" + m_name).c_str());
229 printf(
"HistoManager2: clear\n");
233void HistoManager2::filedump(std::string outfile)
235 printf(
"dump to dqm file = %s\n", outfile.c_str());
238 filesystem::copy_file(
"/dev/shm/" + m_name, outfile, filesystem::copy_options::overwrite_existing);
Abstract base class for different kinds of events.