Analysis Software
Documentation for
sPHENIX
simulation software
Home page
Related Pages
Modules
Namespaces
Classes
Files
Examples
External Links
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
MyMon.cc
Go to the documentation of this file.
Or view
the newest version in sPHENIX GitHub for file MyMon.cc
1
// use #include "" only for your local include and put
2
// those in the first line(s) before any #include <>
3
// otherwise you are asking for weird behavior
4
// (more info - check the difference in include path search when using "" versus <>)
5
6
#include "
MyMon.h
"
7
8
#include <onlmon/OnlMon.h>
// for OnlMon
9
#include <onlmon/OnlMonDB.h>
10
#include <onlmon/OnlMonServer.h>
11
12
#include <Event/msg_profile.h>
13
14
#include <TH1.h>
15
#include <TH2.h>
16
#include <TRandom.h>
17
18
#include <cmath>
19
#include <cstdio>
// for printf
20
#include <iostream>
21
#include <sstream>
22
#include <string>
// for allocator, string, char_traits
23
24
enum
25
{
26
TRGMESSAGE
= 1,
27
FILLMESSAGE
= 2
28
};
29
30
MyMon::MyMon
(
const
std::string
&
name
)
31
:
OnlMon
(name)
32
{
33
// leave ctor fairly empty, its hard to debug if code crashes already
34
// during a new MyMon()
35
return
;
36
}
37
38
MyMon::~MyMon
()
39
{
40
// you can delete NULL pointers it results in a NOOP (No Operation)
41
delete
dbvars
;
42
return
;
43
}
44
45
int
MyMon::Init
()
46
{
47
gRandom->SetSeed(rand());
48
// use printf for stuff which should go the screen but not into the message
49
// system (all couts are redirected)
50
printf
(
"doing the Init\n"
);
51
myhist1
=
new
TH1F(
"mymon_hist1"
,
"test 1d histo"
, 101, 0., 100.);
52
myhist2
=
new
TH2F(
"mymon_hist2"
,
"test 2d histo"
, 101, 0., 100., 101, 0., 100.);
53
OnlMonServer
*se =
OnlMonServer::instance
();
54
// register histograms with server otherwise client won't get them
55
se->
registerHisto
(
this
,
myhist1
);
// uses the TH1->GetName() as key
56
se->
registerHisto
(
this
,
myhist2
);
57
dbvars
=
new
OnlMonDB
(
ThisName
);
// use monitor name for db table name
58
DBVarInit
();
59
Reset
();
60
return
0;
61
}
62
63
int
MyMon::BeginRun
(
const
int
/* runno */
)
64
{
65
// if you need to read calibrations on a run by run basis
66
// this is the place to do it
67
return
0;
68
}
69
70
int
MyMon::process_event
(
Event
*
/* evt */
)
71
{
72
evtcnt
++;
73
OnlMonServer
*se =
OnlMonServer::instance
();
74
// get temporary pointers to histograms
75
// one can do in principle directly se->getHisto("myhist1")->Fill()
76
// but the search in the histogram Map is somewhat expensive and slows
77
// things down if you make more than one operation on a histogram
78
myhist1
->Fill(gRandom->Gaus(50,10));
79
myhist2
->Fill(gRandom->Gaus(50,10), gRandom->Gaus(50,10), 1.);
80
81
if
(
idummy
++ > 10)
82
{
83
if
(
dbvars
)
84
{
85
dbvars
->
SetVar
(
"mymoncount"
, (
float
)
evtcnt
, 0.1 * evtcnt, (
float
) evtcnt);
86
dbvars
->
SetVar
(
"mymondummy"
, sin((
double
) evtcnt), cos((
double
) evtcnt), (
float
) evtcnt);
87
dbvars
->
SetVar
(
"mymonnew"
, (
float
) evtcnt, 10000. / se->
CurrentTicks
(), (float) evtcnt);
88
dbvars
->
DBcommit
();
89
}
90
std::ostringstream
msg
;
91
msg <<
"Filling Histos"
;
92
se->
send_message
(
this
,
MSG_SOURCE_UNSPECIFIED
,
MSG_SEV_INFORMATIONAL
, msg.str(),
FILLMESSAGE
);
93
idummy
= 0;
94
}
95
return
0;
96
}
97
98
int
MyMon::Reset
()
99
{
100
// reset our internal counters
101
evtcnt
= 0;
102
idummy
= 0;
103
return
0;
104
}
105
106
int
MyMon::DBVarInit
()
107
{
108
// variable names are not case sensitive
109
std::string
varname;
110
varname =
"mymoncount"
;
111
dbvars
->
registerVar
(varname);
112
varname =
"mymondummy"
;
113
dbvars
->
registerVar
(varname);
114
varname =
"mymonnew"
;
115
dbvars
->
registerVar
(varname);
116
if
(
verbosity
> 0)
117
{
118
dbvars
->
Print
();
119
}
120
dbvars
->
DBInit
();
121
return
0;
122
}
OnlMon
blob
main
subsystems
example
MyMon.cc
Built by
Jin Huang
. updated:
Sat Feb 17 2024 22:18:28
using
1.8.2 with
sPHENIX GitHub integration