Belle II Software
release-05-01-25
hsendfile.cc
1
#include <daq/dataflow/EvtSocket.h>
2
#include <framework/pcore/EvtMessage.h>
3
#include <framework/pcore/MsgHandler.h>
4
5
#include "TObject.h"
6
#include "TText.h"
7
#include "TH1.h"
8
#include "TKey.h"
9
#include "TFile.h"
10
#include "TIterator.h"
11
#include "TDirectory.h"
12
#include "TList.h"
13
14
#include <stdio.h>
15
#include <string>
16
17
using namespace
Belle2
;
18
using namespace
std;
19
20
void
StreamHistogramsInDir(TDirectory* curdir,
MsgHandler
* hdl,
int
& numobjs)
21
{
22
TList* keylist = curdir->GetListOfKeys();
23
24
TIter nextkey(keylist);
25
TKey* key = 0;
26
int
nkeys = 0;
27
int
nobjs = 0;
28
while
((key = (TKey*)nextkey())) {
29
nkeys++;
30
TObject* obj = key->ReadObj();
31
if
(obj->IsA()->InheritsFrom(
"TH1"
)) {
32
TH1* h1 = (TH1*) obj;
33
hdl->
add
(h1, h1->GetName());
34
nobjs++;
35
numobjs++;
36
}
else
if
(obj->IsA()->InheritsFrom(TDirectory::Class())) {
37
TDirectory* tdir = (TDirectory*) obj;
38
printf(
"subdir: %s\n"
, tdir->GetName());
39
TText subdir(0, 0, tdir->GetName());
40
hdl->
add
(&subdir,
"SUBDIR:"
+
string
(obj->GetName())) ;
41
nobjs++;
42
numobjs++;
43
tdir->cd();
44
StreamHistogramsInDir(tdir, hdl, numobjs);
45
TText command(0, 0,
"COMMAND:EXIT"
);
46
hdl->
add
(&command,
"SUBDIR:EXIT"
);
47
nobjs++;
48
numobjs++;
49
curdir->cd();
50
}
51
}
52
}
53
54
int
main
(
int
argc,
char
** argv)
55
{
56
if
(argc < 4) {
57
printf(
"Usage : hsendfile file host port\n"
);
58
exit(-1);
59
}
60
string
file = string(argv[1]);
61
string
host = string(argv[2]);
62
int
port = atoi(argv[3]);
63
64
EvtSocketSend
* sock =
new
EvtSocketSend
(host.c_str(), port);
65
66
MsgHandler
hdl(0);
67
int
numobjs = 0;
68
69
TFile* f =
new
TFile(file.c_str());
70
71
StreamHistogramsInDir(f, &hdl, numobjs);
72
73
EvtMessage
* msg = hdl.
encode_msg
(MSG_EVENT);
74
(msg->
header
())->reserved[0] = 0;
75
(msg->
header
())->reserved[1] = numobjs;
76
77
sock->send(msg);
78
delete
(msg);
79
delete
(sock);
80
81
f->Close();
82
delete
f;
83
84
return
0;
85
}
Belle2::EvtSocketSend
Definition:
EvtSocket.h:26
Belle2::EvtMessage
Class to manage streamed object.
Definition:
EvtMessage.h:60
Belle2::MsgHandler::encode_msg
virtual EvtMessage * encode_msg(ERecordType rectype)
Stream object list into an EvtMessage.
Definition:
MsgHandler.cc:68
main
int main(int argc, char **argv)
Run all tests.
Definition:
test_main.cc:77
Belle2
Abstract base class for different kinds of events.
Definition:
MillepedeAlgorithm.h:19
Belle2::EvtMessage::header
EvtHeader * header()
Get pointer to EvtHeader.
Definition:
EvtMessage.cc:162
Belle2::MsgHandler::add
virtual void add(const TObject *, const std::string &name)
Add an object to be streamed.
Definition:
MsgHandler.cc:47
Belle2::MsgHandler
A class to encode/decode an EvtMessage.
Definition:
MsgHandler.h:104
daq
dqm
tools
hsendfile.cc
Generated on Fri Nov 5 2021 03:49:03 for Belle II Software by
1.8.17