9#include "daq/dqm/HistoManager2.h"
19HistoManager2::HistoManager2(std::string name)
26HistoManager2::~HistoManager2()
30bool HistoManager2::add(
const string& subdir,
const string& name,
int pid, TH1* histo)
36 if (m_subdir.find(subdir) == m_subdir.end()) {
38 map<string, map<int, TH1*>>* newsubdir =
new map<string, map<int, TH1*>>;
39 map<int, TH1*>* newhlist =
new map<int, TH1*> ;
40 (*newsubdir)[name] = *newhlist;
41 m_subdir[subdir] = *newsubdir;
43 map<string, TH1*>* newmergedir =
new map<string, TH1*>;
44 (*newmergedir)[name] = NULL;
45 m_mergedir[subdir] = *newmergedir;
46 printf(
"HistoManager2: new list created for subdir %s\n", subdir.c_str());
53 map<string, map<int, TH1*>>& dirlist = m_subdir[subdir];
54 map<int, TH1*>& hlist = dirlist[name];
55 if (hlist.find(pid) == hlist.end()) {
65bool HistoManager2::update(
const string& subdir,
const string& name,
int pid, TH1* histo)
68 if (add(subdir, name, pid, histo))
return true;
72 map<string, map<int, TH1*>>& dirlist = m_subdir[subdir];
73 map<int, TH1*>& hlist = dirlist[name];
76 TH1* prevhisto = hlist[pid];
77 if (prevhisto != NULL)
delete prevhisto;
86TH1* HistoManager2::get(
const string& subdir,
const string& name,
int pid)
88 const map<string, map<int, TH1*>>& dirlist = m_subdir[subdir];
89 const map<int, TH1*>& hlist = dirlist.at(name);
90 TH1* hist = hlist.at(pid);
94bool HistoManager2::merge()
99 for (map<
string, map<
string, map<int, TH1*>>>::iterator is =
100 m_subdir.begin(); is != m_subdir.end(); ++is) {
101 map<string, map<int, TH1*>>& dirlist = is->second;
102 map<string, TH1*>& mergelist = m_mergedir[is->first];
118 for (map<
string, std::map<int, TH1*> >::iterator it = dirlist.begin();
119 it != dirlist.end(); ++it) {
120 string name = it->first;
121 map<int, TH1*>& hmap = it->second;
122 if (mergelist[name] != NULL) {
123 TH1* merge_hist = mergelist[name];
128 for (map<int, TH1*>::iterator ih = hmap.begin(); ih != hmap.end();
131 TH1* hist = ih->second;
135 if (mergelist[name] == NULL) {
140 newname = subdir +
"/" + string(hist->GetName());
142 newname = string(hist->GetName());
143 hist->SetName(newname.c_str());
144 TH1* mhist = (TH1*)hist->Clone();
145 mergelist[name] = mhist;
152 TH1* merge_hist = mergelist[name];
153 merge_hist->Add(hist);
154 merge_hist->SetTitle(hist->GetTitle());
161 fh =
new TFile((
"/dev/shm/tmp_" + m_name).c_str(),
"RECREATE");
164 printf(
"HistoManager2 cannot open file : %s\n", (
"/dev/shm/tmp_" + m_name).c_str());
169 for (map<
string, map<
string, map<int, TH1*>>>::iterator is =
170 m_subdir.begin(); is != m_subdir.end(); ++is) {
171 map<string, map<int, TH1*>>& dirlist = is->second;
172 map<string, TH1*>& mergelist = m_mergedir[is->first];
174 for (map<
string, std::map<int, TH1*> >::iterator it = dirlist.begin();
175 it != dirlist.end(); ++it) {
176 string name = it->first;
177 TH1* merge_hist = mergelist[name];
178 if (merge_hist) merge_hist->Write();
185 if (rename((
"/dev/shm/tmp_" + m_name).c_str(), (
"/dev/shm/" + m_name).c_str())) {
186 perror(
"Rename dhm file failed ");
193void HistoManager2::clear()
195 for (map<
string, map<
string, map<int, TH1*>>>::iterator is = m_subdir.begin(); is != m_subdir.end(); ++is) {
196 map<string, map<int, TH1*>>& dirlist = is->second;
198 for (map<
string, std::map<int, TH1*> >::iterator it = dirlist.begin(); it != dirlist.end(); ++it) {
199 map<int, TH1*>& hmap = it->second;
201 for (map<int, TH1*>::iterator ih = hmap.begin(); ih != hmap.end(); ++ih) {
202 TH1* hist = ih->second;
203 if (hist != NULL)
delete hist;
212 for (map<
string, map<string, TH1*> >::iterator is = m_mergedir.begin(); is != m_mergedir.end(); ++is) {
213 map<string, TH1*>& dirlist = is->second;
215 for (map<string, TH1*>::iterator it = dirlist.begin(); it != dirlist.end(); ++it) {
216 TH1* hist = it->second;
217 if (hist != NULL)
delete hist;
226 unlink((
"/dev/shm/tmp_" + m_name).c_str());
227 unlink((
"/dev/shm/" + m_name).c_str());
228 printf(
"HistoManager2: clear\n");
232void HistoManager2::filedump(std::string outfile)
234 printf(
"dump to dqm file = %s\n", outfile.c_str());
237 filesystem::copy_file(
"/dev/shm/" + m_name, outfile, filesystem::copy_options::overwrite_existing);
Abstract base class for different kinds of events.