GMCJMonitor.cxx
Go to the documentation of this file.
1 //____________________________________________________________________________
2 /*
3  Copyright (c) 2003-2019, The GENIE Collaboration
4  For the full text of the license visit http://copyright.genie-mc.org
5  or see $GENIE/LICENSE
6 
7  Author: Costas Andreopoulos <costas.andreopoulos \at stfc.ac.uk>
8  University of Liverpool & STFC Rutherford Appleton Lab
9 
10  For the class documentation see the corresponding header file.
11 
12  Important revisions after version 2.0.0 :
13  @ Jun 23, 2008 - CA
14  fCpuTime wasn't initialized.
15  @ Jan 30, 2013 - CA
16  Added SetRefreshRate(int rate)
17 
18 */
19 //____________________________________________________________________________
20 
21 #include <sstream>
22 #include <fstream>
23 #include <cstdlib>
24 
25 #include <TSystem.h>
26 #include <TMath.h>
27 
33 
34 using std::ostringstream;
35 using std::endl;
36 using std::ios;
37 using std::ofstream;
38 
39 using namespace genie;
40 
41 //____________________________________________________________________________
42 GMCJMonitor::GMCJMonitor(Long_t runnu) :
43 fRunNu(runnu)
44 {
45  this->Init();
46 }
47 //____________________________________________________________________________
49 {
50 
51 }
52 //____________________________________________________________________________
54 {
55  fRefreshRate = TMath::Max(1,rate);
56 }
57 //____________________________________________________________________________
58 void GMCJMonitor::Update(int iev, const EventRecord * event)
59 {
60  if(iev%fRefreshRate) return; // continue only every fRefreshRate events
61 
62  fWatch.Stop();
63  fCpuTime += (fWatch.CpuTime());
64 
65  ofstream out(fStatusFile.c_str(), ios::out);
66 
67  ostringstream status;
68 
69  status << endl;
70  status << "Current Event Number: " << iev << endl;
71 
72  status << "Approximate total processing time: "
73  << fCpuTime << " s" << endl;
74  status << "Approximate processing time/event: "
75  << fCpuTime/(iev+1) << " s" << endl;
76 
77  if(!event) status << "NULL" << endl;
78  else status << *event << endl;
79 
80  out << status.str();
81  out.close();
82 
83  fWatch.Start();
84 }
85 //____________________________________________________________________________
87 {
88  // build the filename of the GENIE status file
89  ostringstream filename;
90  filename << "genie-mcjob-" << fRunNu << ".status";
91  fStatusFile = filename.str();
92 
93  // create a stopwatch
94  fWatch.Reset();
95  fWatch.Start();
96  fCpuTime = 0;
97 
98  // get rehreah rate of set default / protect from invalid refresh rates
99  if( gSystem->Getenv("GMCJMONREFRESH") ) {
100  fRefreshRate = atoi( gSystem->Getenv("GMCJMONREFRESH") );
101  } else fRefreshRate = 100;
102 
103  fRefreshRate = TMath::Max(1,fRefreshRate);
104 }
105 //____________________________________________________________________________
106 
108 {
110 }
111 //____________________________________________________________________________
int iev
Definition: runWimpSim.h:118
TStopwatch fWatch
Definition: GMCJMonitor.h:46
int status
Definition: fabricate.py:1613
THE MAIN GENIE PROJECT NAMESPACE
Definition: GeneratorBase.h:8
void Update(int iev, const EventRecord *event)
Definition: GMCJMonitor.cxx:58
Long_t fRunNu
run number
Definition: GMCJMonitor.h:44
void CustomizeFilename(string filename)
string filename
Definition: shutoffs.py:106
void SetRefreshRate(int rate)
Definition: GMCJMonitor.cxx:53
string fStatusFile
name of output status file
Definition: GMCJMonitor.h:45
double fCpuTime
total cpu time so far
Definition: GMCJMonitor.h:47
Generated Event Record. It is a GHepRecord object that can accept / be visited by EventRecordVisitorI...
Definition: EventRecord.h:38
GMCJMonitor(Long_t runnu)
Definition: GMCJMonitor.cxx:42
int fRefreshRate
update output every so many events
Definition: GMCJMonitor.h:48