GEMC  2.3
Geant4 Monte-Carlo Framework
outputFactory.cc
Go to the documentation of this file.
1 // gemc headers
2 #include "outputFactory.h"
3 #include "options.h"
4 #include "string_utilities.h"
5 #include "evio_output.h"
6 #include "txt_output.h"
7 
8 // C++ headers
9 #include <fstream>
10 using namespace std;
11 
12 #define EVIO_BUFFER 30000000
13 
14 outputFactory *getOutputFactory(map<string, outputFactoryInMap> *outputFactoryMap, string outputType)
15 {
16 
17  if(outputFactoryMap->find(outputType) == outputFactoryMap->end())
18  {
19  cout << endl << endl << " >>> WARNING: Output type <" << outputType << "> NOT FOUND IN Output Map." << endl;
20  return NULL;
21  }
22 
23  return (*outputFactoryMap)[outputType]();
24 }
25 
27 {
28  // EVIO Buffer size set to 30M words
29  int evio_buffer = EVIO_BUFFER;
30 
31  gemcOpt = Opts;
32  string hd_msg = gemcOpt.optMap["LOG_MSG"].args + " Output File: >> ";
33 
34  string optf = gemcOpt.optMap["OUTPUT"].args;
35  outType.assign(optf, 0, optf.find(",")) ;
36  outFile.assign(optf, optf.find(",") + 1, optf.size()) ;
37 
38  if(outType != "no") cout << hd_msg << " Opening output file \"" << TrimSpaces(outFile) << "\"." << endl;
39  if(outType == "txt") txtoutput = new ofstream(TrimSpaces(outFile).c_str());
40  if(outType == "evio")
41  {
42  pchan = new evioFileChannel(TrimSpaces(outFile).c_str(), "w", evio_buffer);
43  pchan->open();
44  }
45 }
46 
48 {
49  string hd_msg = gemcOpt.optMap["LOG_MSG"].args + " Output File: >> ";
50 
51  if(outType != "no") cout << " Closing " << outFile << "." << endl;
52  if(outType == "txt") txtoutput->close();
53  if(outType == "evio")
54  {
55  pchan->close();
56  delete pchan;
57  }
58 }
59 
60 
61 map<string, outputFactoryInMap> registerOutputFactories()
62 {
63  map<string, outputFactoryInMap> outputMap;
64 
65  outputMap["txt"] = &txt_output::createOutput;
66  outputMap["evio"] = &evio_output::createOutput;
67 
68  return outputMap;
69 }
70 
72 {
73  if(what == "pid") return PID;
74  return 0;
75 }
76 
78 {
79  if(what == "px") return momentum.x();
80  if(what == "py") return momentum.y();
81  if(what == "pz") return momentum.z();
82  if(what == "vx") return vertex.x();
83  if(what == "vy") return vertex.y();
84  if(what == "vz") return vertex.z();
85 
86  return 0;
87 }
#define EVIO_BUFFER
double getVariableFromStringD(string)
int getVariableFromStringI(string)
STL namespace.
static outputFactory * createOutput()
Definition: txt_output.h:20
map< string, aopt > optMap
Options map.
Definition: options.h:75
outputFactory * getOutputFactory(map< string, outputFactoryInMap > *outputFactoryMap, string outputType)
string TrimSpaces(string in)
Removes leading and trailing spaces.
map< string, outputFactoryInMap > registerOutputFactories()
outputContainer(goptions)
static outputFactory * createOutput()
Definition: evio_output.h:20