GENIEGenerator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GMCJMonitor.cxx
Go to the documentation of this file.
1 //____________________________________________________________________________
2 /*
3  Copyright (c) 2003-2024, The GENIE Collaboration
4  For the full text of the license visit http://copyright.genie-mc.org
5 
6  Costas Andreopoulos <c.andreopoulos \at cern.ch>
7  University of Liverpool
8 */
9 //____________________________________________________________________________
10 
11 #include <sstream>
12 #include <fstream>
13 #include <cstdlib>
14 
15 #include <TSystem.h>
16 #include <TMath.h>
17 
23 
24 using std::ostringstream;
25 using std::endl;
26 using std::ios;
27 using std::ofstream;
28 
29 using namespace genie;
30 
31 //____________________________________________________________________________
32 GMCJMonitor::GMCJMonitor(Long_t runnu) :
33 fRunNu(runnu)
34 {
35  this->Init();
36 }
37 //____________________________________________________________________________
39 {
40 
41 }
42 //____________________________________________________________________________
44 {
45  fRefreshRate = TMath::Max(1,rate);
46 }
47 //____________________________________________________________________________
48 void GMCJMonitor::Update(int iev, const EventRecord * event)
49 {
50  if(iev%fRefreshRate) return; // continue only every fRefreshRate events
51 
52  fWatch.Stop();
53  fCpuTime += (fWatch.CpuTime());
54 
55  ofstream out(fStatusFile.c_str(), ios::out);
56 
57  ostringstream status;
58 
59  status << endl;
60  status << "Current Event Number: " << iev << endl;
61 
62  status << "Approximate total processing time: "
63  << fCpuTime << " s" << endl;
64  status << "Approximate processing time/event: "
65  << fCpuTime/(iev+1) << " s" << endl;
66 
67  if(!event) status << "NULL" << endl;
68  else status << *event << endl;
69 
70  out << status.str();
71  out.close();
72 
73  fWatch.Start();
74 }
75 //____________________________________________________________________________
77 {
78  // build the filename of the GENIE status file
79  ostringstream filename;
80  filename << "genie-mcjob-" << fRunNu << ".status";
81  fStatusFile = filename.str();
82 
83  // create a stopwatch
84  fWatch.Reset();
85  fWatch.Start();
86  fCpuTime = 0;
87 
88  // get rehreah rate of set default / protect from invalid refresh rates
89  if( gSystem->Getenv("GMCJMONREFRESH") ) {
90  fRefreshRate = atoi( gSystem->Getenv("GMCJMONREFRESH") );
91  } else fRefreshRate = 100;
92 
93  fRefreshRate = TMath::Max(1,fRefreshRate);
94 }
95 //____________________________________________________________________________
96 
97 void GMCJMonitor::CustomizeFilename(string filename)
98 {
99  fStatusFile = filename;
100 }
101 //____________________________________________________________________________
TStopwatch fWatch
Definition: GMCJMonitor.h:47
void Update(int iev, const EventRecord *event)
Definition: GMCJMonitor.cxx:48
Long_t fRunNu
run number
Definition: GMCJMonitor.h:45
void CustomizeFilename(string filename)
Definition: GMCJMonitor.cxx:97
void SetRefreshRate(int rate)
Definition: GMCJMonitor.cxx:43
string fStatusFile
name of output status file
Definition: GMCJMonitor.h:46
double fCpuTime
total cpu time so far
Definition: GMCJMonitor.h:48
Generated Event Record. It is a GHepRecord object that can accept / be visited by EventRecordVisitorI...
Definition: EventRecord.h:37
GMCJMonitor(Long_t runnu)
Definition: GMCJMonitor.cxx:32
int fRefreshRate
update output every so many events
Definition: GMCJMonitor.h:49