1 | // ESAF : Euso Simulation and Analysis Framework |
---|
2 | // $Id: SimuModuleFactory.cc 2956 2011-06-28 18:54:32Z mabl $ |
---|
3 | // A. Thea created Mar, 13 2004 |
---|
4 | |
---|
5 | #include <fstream> |
---|
6 | #include "utils.hh" |
---|
7 | #include "SimuModuleFactory.hh" |
---|
8 | #include "TestSimuModule.hh" |
---|
9 | |
---|
10 | ClassImp(SimuModuleFactory) |
---|
11 | |
---|
12 | // constructor |
---|
13 | SimuModuleFactory::SimuModuleFactory(const string& sName) { |
---|
14 | |
---|
15 | fCurrent = 0; |
---|
16 | |
---|
17 | ifstream in( sName.c_str() ); |
---|
18 | if (!in) { |
---|
19 | throw runtime_error("Cannot find ModuleFileName in EusoSimuFramework"); |
---|
20 | } |
---|
21 | |
---|
22 | string dummy; |
---|
23 | |
---|
24 | // parse file |
---|
25 | while ( getline(in,dummy) ) { |
---|
26 | // erase comments |
---|
27 | size_t pos = dummy.find('#'); |
---|
28 | if ( pos != string::npos ) |
---|
29 | dummy.erase( pos ); |
---|
30 | |
---|
31 | // swallow spaces |
---|
32 | dummy = ltrim( dummy ); |
---|
33 | |
---|
34 | // skip blank lines |
---|
35 | if ( dummy.empty() ) continue; |
---|
36 | |
---|
37 | // each line must be a key=value pair |
---|
38 | // key can be : Module, Sequence |
---|
39 | // Module: normal module |
---|
40 | // Sequence: list of connected modules (not implemented yet) |
---|
41 | |
---|
42 | // get identifier |
---|
43 | string identifier = dummy.substr( 0, dummy.find('=') ); |
---|
44 | identifier = rtrim( identifier ); |
---|
45 | if ( identifier.find_first_of("\t ") != string::npos) { |
---|
46 | throw runtime_error("Syntax error in file "+sName+" line "+dummy); |
---|
47 | } |
---|
48 | |
---|
49 | // get module name |
---|
50 | string name = dummy.substr( dummy.find('=')+1, string::npos); |
---|
51 | name = trim( name ); |
---|
52 | |
---|
53 | // build modules |
---|
54 | if ( identifier == "Module" ) { |
---|
55 | MakeModule( name ); |
---|
56 | } |
---|
57 | else if ( identifier == "Sequence" ) { |
---|
58 | MakeSequence( name ); |
---|
59 | } |
---|
60 | else { |
---|
61 | throw runtime_error("Syntax error in file"+sName+" line "+dummy); |
---|
62 | } |
---|
63 | |
---|
64 | } |
---|
65 | } |
---|
66 | |
---|
67 | // destructor |
---|
68 | SimuModuleFactory::~SimuModuleFactory() { |
---|
69 | } |
---|
70 | |
---|
71 | // returns a module until the list is over |
---|
72 | SimuModule* SimuModuleFactory::GetModule() { |
---|
73 | if ( fCurrent < fModules.size() ) |
---|
74 | return fModules[fCurrent++]; |
---|
75 | else |
---|
76 | return (SimuModule*)0; |
---|
77 | } |
---|
78 | |
---|
79 | // physically build objects and store into a vector |
---|
80 | void SimuModuleFactory::MakeModule( const string& name) { |
---|
81 | if ( name == "Test1" ) |
---|
82 | fModules.push_back( new TestSimuModule( name ) ); |
---|
83 | else if ( name == "Test2" ) |
---|
84 | fModules.push_back( new TestSimuModule( name ) ); |
---|
85 | else if ( name == "Test3" ) |
---|
86 | fModules.push_back( new TestSimuModule( name ) ); |
---|
87 | else |
---|
88 | throw runtime_error("Unknown Module:"+name); |
---|
89 | } |
---|
90 | |
---|
91 | void SimuModuleFactory::MakeSequence( const string& name) { |
---|
92 | } |
---|