Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 08:21:00

0001 // use #include "" only for your local include and put
0002 // those in the first line(s) before any #include <>
0003 // otherwise you are asking for weird behavior
0004 // (more info - check the difference in include path search when using "" versus <>)
0005 
0006 #include "MyMon.h"
0007 
0008 #include <onlmon/OnlMon.h>  // for OnlMon
0009 #include <onlmon/OnlMonDB.h>
0010 #include <onlmon/OnlMonServer.h>
0011 
0012 #include <Event/msg_profile.h>
0013 
0014 #include <TH1.h>
0015 #include <TH2.h>
0016 #include <TRandom.h>
0017 
0018 #include <cmath>
0019 #include <cstdio>  // for printf
0020 #include <iostream>
0021 #include <sstream>
0022 #include <string>  // for allocator, string, char_traits
0023 
0024 enum
0025 {
0026   TRGMESSAGE = 1,
0027   FILLMESSAGE = 2
0028 };
0029 
0030 MyMon::MyMon(const std::string &name)
0031   : OnlMon(name)
0032 {
0033   // leave ctor fairly empty, its hard to debug if code crashes already
0034   // during a new MyMon()
0035   return;
0036 }
0037 
0038 MyMon::~MyMon()
0039 {
0040   // you can delete NULL pointers it results in a NOOP (No Operation)
0041   delete dbvars;
0042   return;
0043 }
0044 
0045 int MyMon::Init()
0046 {
0047   gRandom->SetSeed(rand());
0048   // use printf for stuff which should go the screen but not into the message
0049   // system (all couts are redirected)
0050   printf("doing the Init\n");
0051   myhist1 = new TH1F("mymon_hist1", "test 1d histo", 101, 0., 100.);
0052   myhist2 = new TH2F("mymon_hist2", "test 2d histo", 101, 0., 100., 101, 0., 100.);
0053   OnlMonServer *se = OnlMonServer::instance();
0054   // register histograms with server otherwise client won't get them
0055   se->registerHisto(this, myhist1);  // uses the TH1->GetName() as key
0056   se->registerHisto(this, myhist2);
0057   dbvars = new OnlMonDB(ThisName);  // use monitor name for db table name
0058   DBVarInit();
0059   Reset();
0060   return 0;
0061 }
0062 
0063 int MyMon::BeginRun(const int /* runno */)
0064 {
0065   // if you need to read calibrations on a run by run basis
0066   // this is the place to do it
0067   return 0;
0068 }
0069 
0070 int MyMon::process_event(Event * /* evt */)
0071 {
0072   evtcnt++;
0073   OnlMonServer *se = OnlMonServer::instance();
0074   // get temporary pointers to histograms
0075   // one can do in principle directly se->getHisto("myhist1")->Fill()
0076   // but the search in the histogram Map is somewhat expensive and slows
0077   // things down if you make more than one operation on a histogram
0078   myhist1->Fill(gRandom->Gaus(50,10));
0079   myhist2->Fill(gRandom->Gaus(50,10), gRandom->Gaus(50,10), 1.);
0080 
0081   if (idummy++ > 10)
0082   {
0083     if (dbvars)
0084     {
0085       dbvars->SetVar("mymoncount", (float) evtcnt, 0.1 * evtcnt, (float) evtcnt);
0086       dbvars->SetVar("mymondummy", sin((double) evtcnt), cos((double) evtcnt), (float) evtcnt);
0087       dbvars->SetVar("mymonnew", (float) evtcnt, 10000. / se->CurrentTicks(), (float) evtcnt);
0088       dbvars->DBcommit();
0089     }
0090     std::ostringstream msg;
0091     msg << "Filling Histos";
0092     se->send_message(this, MSG_SOURCE_UNSPECIFIED, MSG_SEV_INFORMATIONAL, msg.str(), FILLMESSAGE);
0093     idummy = 0;
0094   }
0095   return 0;
0096 }
0097 
0098 int MyMon::Reset()
0099 {
0100   // reset our internal counters
0101   evtcnt = 0;
0102   idummy = 0;
0103   return 0;
0104 }
0105 
0106 int MyMon::DBVarInit()
0107 {
0108   // variable names are not case sensitive
0109   std::string varname;
0110   varname = "mymoncount";
0111   dbvars->registerVar(varname);
0112   varname = "mymondummy";
0113   dbvars->registerVar(varname);
0114   varname = "mymonnew";
0115   dbvars->registerVar(varname);
0116   if (verbosity > 0)
0117   {
0118     dbvars->Print();
0119   }
0120   dbvars->DBInit();
0121   return 0;
0122 }