Belle II Software development
HistoManager Class Reference

Public Member Functions

 HistoManager (DqmMemFile *mapfile)
 
bool add (const std::string &subdir, const std::string &name, int pid, TH1 *histo)
 
bool update (const std::string &subdir, const std::string &name, int pid, TH1 *histo)
 
TH1 * get (const std::string &subdir, const std::string &name, int pid)
 
bool merge (void)
 
void clear (void)
 
void filedump (const std::string &outfile)
 

Private Attributes

std::map< std::string, std::map< std::string, std::map< int, TH1 * > > > m_subdir
 
std::map< std::string, std::map< std::string, TH1 * > > m_mergedir
 
DqmMemFile * m_memfile
 

Detailed Description

Definition at line 24 of file HistoManager.h.

Constructor & Destructor Documentation

◆ HistoManager()

HistoManager ( DqmMemFile * mapfile)
explicit

Definition at line 16 of file HistoManager.cc.

17{
18 m_memfile = memfile;
19 clear();
20 merge();
21}

◆ ~HistoManager()

Definition at line 23 of file HistoManager.cc.

24{
25}

Member Function Documentation

◆ add()

bool add ( const std::string & subdir,
const std::string & name,
int pid,
TH1 * histo )

Definition at line 27 of file HistoManager.cc.

28{
29 // printf ( "HistoManager: adding %s to subdir %s from id %d\n",
30 // name.c_str(), subdir.c_str(), pid );
31
32 // Check for subdirectory
33 if (m_subdir.find(subdir) == m_subdir.end()) {
34 // Work dir and hist
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;
39 // Merge dir and hist
40 map<string, TH1*>* newmergedir = new map<string, TH1*>;
41 (*newmergedir)[name] = NULL; // TH1 is not yet created
42 m_mergedir[subdir] = *newmergedir;
43 printf("HistoManager: new list created for subdir %s\n", subdir.c_str());
44 delete newsubdir;
45 delete newhlist;
46 delete newmergedir;
47 }
48
49 // Get histogram map of subdir
50 map<string, map<int, TH1*>>& dirlist = m_subdir[subdir];
51 map<int, TH1*>& hlist = dirlist[name];
52 if (hlist.try_emplace(pid, histo).second) {
53 // printf("HistoManager: histogram %s from %d registered in %s\n",
54 // histo->GetName(), pid, subdir.c_str());
55 // histo->Print();
56 return true;
57 }
58 return false;
59}

◆ clear()

void clear ( void )

Definition at line 163 of file HistoManager.cc.

164{
165 for (map<string, map<string, map<int, TH1*>>>::iterator is = m_subdir.begin(); is != m_subdir.end(); ++is) {
166 map<string, map<int, TH1*>>& dirlist = is->second;
167
168 for (map<string, std::map<int, TH1*> >::iterator it = dirlist.begin(); it != dirlist.end(); ++it) {
169 map<int, TH1*>& hmap = it->second;
170
171 for (map<int, TH1*>::iterator ih = hmap.begin(); ih != hmap.end(); ++ih) {
172 TH1* hist = ih->second;
173 if (hist != NULL) delete hist;
174 //if (hist != NULL) hist->Reset();
175 }
176 hmap.clear();
177 }
178 dirlist.clear();
179 }
180 m_subdir.clear();
181
182 for (map<string, map<string, TH1*> >::iterator is = m_mergedir.begin(); is != m_mergedir.end(); ++is) {
183 map<string, TH1*>& dirlist = is->second;
184
185 for (map<string, TH1*>::iterator it = dirlist.begin(); it != dirlist.end(); ++it) {
186 TH1* hist = it->second;
187 if (hist != NULL) delete hist;
188 //it->second = NULL;
189 //if (hist != NULL) hist->Reset();
190 }
191 dirlist.clear();
192 }
193 m_mergedir.clear();
194
195 printf("HistoManager: clear\n");
196 m_memfile->ClearSharedMem();
197}

◆ filedump()

void filedump ( const std::string & outfile)

Definition at line 200 of file HistoManager.cc.

201{
202 printf("dump to dqm file = %s\n", outfile.c_str());
203 merge(); // Smart move to first merge, but necessary?
204 m_memfile->SaveToFile(outfile);
205}

◆ get()

TH1 * get ( const std::string & subdir,
const std::string & name,
int pid )

Definition at line 82 of file HistoManager.cc.

83{
84 const map<string, map<int, TH1*>>& dirlist = m_subdir[subdir];
85 const map<int, TH1*>& hlist = dirlist.at(name);
86 TH1* hist = hlist.at(pid);
87 return hist;
88}

◆ merge()

bool merge ( void )

Definition at line 90 of file HistoManager.cc.

91{
92 // Loop over subdir list
93 string subdir;
94 for (map<string, map<string, map<int, TH1*>>>::iterator is =
95 m_subdir.begin(); is != m_subdir.end(); ++is) {
96 map<string, map<int, TH1*>>& dirlist = is->second;
97 map<string, TH1*>& mergelist = m_mergedir[is->first];
98 // Move to the root directory of TMapFile
99 // printf("TMemFile = %8.8x\n", m_memfile->GetMemFile());
100 if (m_memfile->GetMemFile() == NULL) exit(-99);
101 (m_memfile->GetMemFile())->cd();
102 // cd to subdirectory if defined
103 subdir = is->first;
104 /*
105 if ( is->first != "root" ) {
106 TDirectory* fdir = (m_memfile->GetmemFile())->GetDirectory();
107 fdir->mkdir ( (is->first).c_str() );
108 fdir->cd ( (is->first).c_str() );
109 printf ( "TMemFile: subdir set to %s\n", (is->first).c_str() );
110 fdir->ls();
111 }
112 */
113 // Loop over histogram list
114 for (map<string, std::map<int, TH1*> >::iterator it = dirlist.begin();
115 it != dirlist.end(); ++it) {
116 string name = it->first;
117 map<int, TH1*>& hmap = it->second;
118 if (mergelist[name] != NULL) {
119 TH1* merge_hist = mergelist[name];
120 merge_hist->Reset();
121
122 }
123 // Loop over pid list
124 for (map<int, TH1*>::iterator ih = hmap.begin(); ih != hmap.end();
125 ++ih) {
126 // int pid = ih->first;
127 TH1* hist = ih->second;
128 // printf ( "Retrieving histo %s from pid = %d\n", hist->GetName(), pid );
129 // hist->Print();
130 // Create new histogram in merge list if not exist yet
131 if (mergelist[name] == NULL) {
132 // printf ( "HistoManager: adding %s (class %s) to mergelist\n",
133 // hist->GetName(), hist->ClassName() );
134 string newname;
135 if (subdir != "")
136 newname = subdir + "/" + string(hist->GetName());
137 else
138 newname = string(hist->GetName());
139 hist->SetName(newname.c_str());
140 TH1* mhist = static_cast<TH1*>(hist->Clone());
141 mergelist[name] = mhist;
142 // mergelist[name] = (TH1*)hist->Clone();
143 // m_mapfile->Add(mergelist[name]);
144 // delete hist;
145 }
146 // Add histogram if exist
147 else {
148 TH1* merge_hist = mergelist[name];
149 merge_hist->Add(hist);
150 merge_hist->SetTitle(hist->GetTitle());
151 }
152 }
153 }
154 }
155 // m_mapfile->Update();
156 m_memfile->UpdateSharedMem();
157
158 // m_mapfile->ls();
159 // printf ( "HistoManager: merge called and mapfile updated!!!!!\n" );
160 return true;
161}

◆ update()

bool update ( const std::string & subdir,
const std::string & name,
int pid,
TH1 * histo )

Definition at line 61 of file HistoManager.cc.

62{
63 // Register the histogram if not yet done
64 if (add(subdir, name, pid, histo)) return true;
65
66
67 // Retrieve the histogram list for the name
68 map<string, map<int, TH1*>>& dirlist = m_subdir[subdir];
69 map<int, TH1*>& hlist = dirlist[name];
70
71 // Replace histogram
72 TH1* prevhisto = hlist[pid];
73 if (prevhisto != NULL) delete prevhisto;
74 hlist[pid] = histo;
75 // printf ( "HistoManager: histogram %s replaced in subdir %s, entry = %f\n",
76 // name.c_str(), subdir.c_str(), histo->GetEntries());
77 // hlist[pid]->Print();
78 // Return
79 return true;
80}

Member Data Documentation

◆ m_memfile

DqmMemFile* m_memfile
private

Definition at line 49 of file HistoManager.h.

◆ m_mergedir

std::map<std::string, std::map<std::string, TH1*> > m_mergedir
private

Definition at line 46 of file HistoManager.h.

◆ m_subdir

std::map<std::string, std::map<std::string, std::map<int, TH1*> > > m_subdir
private

Definition at line 42 of file HistoManager.h.


The documentation for this class was generated from the following files: