GEMC  1.8
Geant4 Monte-Carlo Framework
MOutputBaseClass.cc
Go to the documentation of this file.
1 // %%%%%%%%%%%%%
2 // gemc headers
3 // %%%%%%%%%%%%%
4 #include "MOutputBaseClass.h"
5 #include "usage.h"
6 
7 #include <fstream>
8 using namespace std;
9 
10 MOutputBaseClass *GetMOutputClass (map<string, MOutput_Factory> *MProcessOutput_Map, string outputType)
11 {
12 
13  if(MProcessOutput_Map->find(outputType) == MProcessOutput_Map->end())
14  {
15  cout << endl << endl << " >>> WARNING: Output type <" << outputType << "> NOT FOUND IN Output Map." << endl;
16  return NULL;
17  }
18 
19  return (*MProcessOutput_Map)[outputType]();
20 }
21 
23 {
24  // EVIO Buffer size set to 30M words
25  int evio_buffer = 30000000;
26 
27  gemcOpt = Opts;
28  string hd_msg = gemcOpt.args["LOG_MSG"].args + " Output File: >> ";
29 
30  string optf = gemcOpt.args["OUTPUT"].args;
31  outType.assign(optf, 0, optf.find(",")) ;
32  outFile.assign(optf, optf.find(",") + 1, optf.size()) ;
33 
34  if(outType != "no") cout << hd_msg << " Opening output file \"" << TrimSpaces(outFile) << "\"." << endl;
35  if(outType == "txt") txtoutput = new ofstream(TrimSpaces(outFile).c_str());
36  if(outType == "evio")
37  {
38  pchan = new evioFileChannel(TrimSpaces(outFile).c_str(), "w", evio_buffer);
39  pchan->open();
40  }
41 }
42 
44 {
45  string hd_msg = gemcOpt.args["LOG_MSG"].args + " Output File: >> ";
46 
47  if(outType != "no") cout << " Closing " << outFile << "." << endl;
48  if(outType == "txt") txtoutput->close();
49  if(outType == "evio")
50  {
51  pchan->close();
52  delete pchan;
53  }
54 }
MOutputs(gemc_opts)
STL namespace.
MOutputBaseClass * GetMOutputClass(map< string, MOutput_Factory > *MProcessOutput_Map, string outputType)
Instantiates MOutputBaseClass.
map< string, opts > args
Options map.
Definition: usage.h:68
string TrimSpaces(string in)
Removes leading and trailing spaces.