9 #include "daq/dqm/DqmMemFile.h"
10 #include <framework/pcore/MsgHandler.h>
20 DqmMemFile::DqmMemFile(
string name,
const string& mode,
int size)
24 if (mode !=
"write" && mode !=
"WRITE")
32 m_buf = (
char*)
new int[size];
39 m_memfile =
new TMemFile(name.c_str(), m_buf, size *
sizeof(
int),
"RECREATE");
41 m_memfile->CopyTo((
char*)(m_shm->ptr()), m_memfile->GetSize());
43 printf(
"DqmMemFile : TMemFile is opened in WRITE mode.\n");
45 printf(
"DqmMemFile : TMemFile is opend in READ mode.\n");
49 DqmMemFile::DqmMemFile(
int shm_id,
int sem_id,
const string& mode,
int size)
53 if (mode !=
"write" && mode !=
"WRITE")
57 m_name =
"dqm_mem_file";
61 m_buf = (
char*)
new int[size];
68 m_memfile =
new TMemFile(m_name.c_str(), m_buf, size *
sizeof(
int),
"RECREATE");
69 printf(
"DqmMemFile : TMemFile is opened in WRITE mode.\n");
71 printf(
"DqmMemFile : TMemFile is opend in READ mode.\n");
76 DqmMemFile::~DqmMemFile()
78 if (m_memfile != NULL)
85 TMemFile* DqmMemFile::GetMemFile()
91 int DqmMemFile::UpdateSharedMem()
93 if (!m_writeMode)
return -1;
94 m_memfile->Write(0, TObject::kOverwrite);
96 m_memfile->CopyTo((
char*)(m_shm->ptr()), m_memfile->GetSize());
101 int DqmMemFile::ClearSharedMem()
103 if (!m_writeMode)
return -1;
105 if (m_memfile != NULL)
delete m_memfile;
106 m_memfile =
new TMemFile(m_name.c_str(), m_buf, m_size *
sizeof(
int),
"RECREATE");
109 m_memfile->CopyTo((
char*)(m_shm->ptr()), m_memfile->GetSize());
115 TMemFile* DqmMemFile::LoadMemFile()
117 if (m_writeMode)
return NULL;
119 if (m_memfile != NULL) {
124 memcpy(m_buf, m_shm->ptr(), m_size *
sizeof(
int));
127 m_memfile =
new TMemFile(m_name.c_str(), m_buf, MEMFILESIZE);
134 TMemFile* memfile = LoadMemFile();
135 if (memfile == NULL)
return NULL;
145 StreamHistograms(gDirectory, &hdl, numobjs);
148 (msg->
header())->reserved[0] = 0;
149 (msg->
header())->reserved[1] = numobjs;
153 int DqmMemFile::StreamHistograms(TDirectory* curdir,
MsgHandler* msg,
int& numobjs)
155 TList* keylist = curdir->GetListOfKeys();
158 TIter nextkey(keylist);
162 while ((key = (TKey*)nextkey())) {
164 TObject* obj = curdir->FindObjectAny(key->GetName());
165 if (obj->IsA()->InheritsFrom(
"TH1")) {
166 TH1* h1 = (TH1*) obj;
168 msg->
add(h1, h1->GetName());
171 }
else if (obj->IsA()->InheritsFrom(TDirectory::Class())) {
173 TDirectory* tdir = (TDirectory*) obj;
175 TText subdir(0, 0, tdir->GetName());
176 msg->
add(&subdir,
"SUBDIR:" +
string(obj->GetName())) ;
180 StreamHistograms(tdir, msg, numobjs);
181 TText command(0, 0,
"COMMAND:EXIT");
182 msg->
add(&command,
"SUBDIR:EXIT");
191 bool DqmMemFile::SaveToFile(std::string outfile)
197 printf(
"dump to dqm file = %s\n", outfile.c_str());
199 TFile* dqmtfile =
new TFile(outfile.c_str(),
"RECREATE");
202 TIter next(m_memfile->GetListOfKeys());
204 while ((key = (TKey*)next())) {
205 TH1* hist = (TH1*)key->ReadObj();
Class to manage streamed object.
EvtHeader * header()
Get pointer to EvtHeader.
A class to encode/decode an EvtMessage.
virtual void add(const TObject *, const std::string &name)
Add an object to be streamed.
Abstract base class for different kinds of events.