Belle II Software development
HistoRelay2 Class Reference

Public Member Functions

 HistoRelay2 (std::string &filename, std::string &dest, int port)
 
 HistoRelay2 (const HistoRelay2 &)=delete
 Copy constructor (disabled).
 
HistoRelay2 & operator= (const HistoRelay2 &)=delete
 Operator = (disabled).
 
int collect ()
 

Static Private Member Functions

static EvtMessage * StreamFile (std::string &filename)
 
static int StreamHistograms (TDirectory *curdir, MsgHandler *msg, int &numobjs)
 

Private Attributes

std::string m_filename
 
EvtSocketSend * m_sock
 
std::string m_dest
 
int m_port
 

Detailed Description

Definition at line 21 of file HistoRelay2.h.

Constructor & Destructor Documentation

◆ HistoRelay2()

HistoRelay2 ( std::string & filename,
std::string & dest,
int port )

Definition at line 19 of file HistoRelay2.cc.

19 : m_filename(filename), m_dest(dest)
20{
21 m_port = port;
22 m_sock = new EvtSocketSend(m_dest, m_port);
23}

◆ ~HistoRelay2()

Definition at line 25 of file HistoRelay2.cc.

26{
27 delete m_sock;
28}

Member Function Documentation

◆ collect()

int collect ( )

Definition at line 30 of file HistoRelay2.cc.

31{
32 // printf ( "HistoRelay2 : collect!!\n" );
33 EvtMessage* msg = StreamFile(m_filename);
34
35 if (!msg) return 1; // error indicator
36
37 auto ret = m_sock->send(msg);
38
39 delete (msg);
40
41 if (ret < 0) {
42 // Socket error, e.g server died
43 delete m_sock;
44 // try reconnect
45 printf("HistoRelay2: socket seems dead -> reconnect\n");
46 m_sock = new EvtSocketSend(m_dest, m_port);
47 }
48
49 return 0;
50}

◆ StreamFile()

EvtMessage * StreamFile ( std::string & filename)
staticprivate

Definition at line 53 of file HistoRelay2.cc.

54{
55 TFile* file = new TFile((std::string("/dev/shm/") + filename).c_str(), "read");
56 if (file == NULL || file->IsZombie()) return NULL;
57 file->cd();
58 MsgHandler hdl(0);
59 int numobjs = 0;
60 StreamHistograms(gDirectory, &hdl, numobjs);
61 file->Close();
62 delete file;
63 // printf ( "DqmMemFile::StreamMemFile : streamed %d histograms in EvtMessage\n", numobjs );
64 EvtMessage* msg = hdl.encode_msg(MSG_EVENT);
65 (msg->header())->reserved[0] = 0;
66 (msg->header())->reserved[1] = numobjs;
67 return msg;
68}
EvtHeader * header()
Get pointer to EvtHeader.

◆ StreamHistograms()

int StreamHistograms ( TDirectory * curdir,
MsgHandler * msg,
int & numobjs )
staticprivate

Definition at line 70 of file HistoRelay2.cc.

71{
72 TList* keylist = curdir->GetListOfKeys();
73
74 TIter nextkey(keylist);
75 TKey* key = 0;
76 while ((key = static_cast<TKey*>(nextkey()))) {
77 TObject* obj = curdir->FindObjectAny(key->GetName());
78 if (obj->IsA()->InheritsFrom("TH1")) {
79 TH1* h1 = static_cast<TH1*>(obj);
80 // printf ( "Key = %s, entry = %f\n", key->GetName(), h1->GetEntries() );
81 msg->add(h1, h1->GetName());
82 numobjs++;
83 } else if (obj->IsA()->InheritsFrom(TDirectory::Class())) {
84 // printf ( "New directory found %s, Go into subdir\n", obj->GetName() );
85 TDirectory* tdir = static_cast<TDirectory*>(obj);
86 // m_msg->add(tdir, tdir->GetName());
87 TText subdir(0, 0, tdir->GetName());
88 msg->add(&subdir, "SUBDIR:" + string(obj->GetName())) ;
89 numobjs++;
90 tdir->cd();
91 StreamHistograms(tdir, msg, numobjs);
92 TText command(0, 0, "COMMAND:EXIT");
93 msg->add(&command, "SUBDIR:EXIT");
94 numobjs++;
95 curdir->cd();
96 }
97 }
98 return 0;
99}
virtual void add(const TObject *, const std::string &name)
Add an object to be streamed.
Definition MsgHandler.cc:46

Member Data Documentation

◆ m_dest

std::string m_dest
private

Definition at line 35 of file HistoRelay2.h.

◆ m_filename

std::string m_filename
private

Definition at line 33 of file HistoRelay2.h.

◆ m_port

int m_port
private

Definition at line 36 of file HistoRelay2.h.

◆ m_sock

EvtSocketSend* m_sock
private

Definition at line 34 of file HistoRelay2.h.


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