GEMC  2.3
Geant4 Monte-Carlo Framework
fieldFactory.cc
Go to the documentation of this file.
1 // gemc headers
2 #include "fieldFactory.h"
3 #include "asciiField.h"
4 #include "utils.h"
5 
6 
7 fieldFactory *getFieldFactory(map<string, fieldFactoryInMap> *fieldsFactoryMap, string fieldsMethod)
8 {
9 
10  if(fieldsFactoryMap->find(fieldsMethod) == fieldsFactoryMap->end())
11  {
12  cout << endl << endl << " >>> WARNING: " << fieldsMethod << " NOT FOUND IN Field Factory Map." << endl;
13  return NULL;
14  }
15 
16  return (*fieldsFactoryMap)[fieldsMethod]();
17 }
18 
19 map<string, fieldFactoryInMap> registerFieldFactories()
20 {
21  map<string, fieldFactoryInMap> fieldFactoryMap;
22 
23  // ASCII factory
24  fieldFactoryMap["ASCII"] = &asciiField::createFieldFactory;
25 
26  return fieldFactoryMap;
27 }
28 
29 
30 map<string, gfield> loadAllFields(map<string, fieldFactoryInMap> fieldFactoryMap, goptions opts)
31 {
32  double verbosity = opts.optMap["FIELD_VERBOSITY"].arg ;
33  // get list of files in directories in:
34  //
35  // - JLAB_ROOT/noarch/data
36  // - GEMC_DATA_DIR if exists
37  // - FIELD_DIR gemc option if set
38  map<string, string> filesMap;
39 
40  if(getenv("JLAB_ROOT") != NULL) mergeMaps(filesMap, getFilesInDirectory((string) getenv("JLAB_ROOT") + "/noarch/data/" ));
41  if(getenv("GEMC_DATA_DIR") != NULL) mergeMaps(filesMap, getFilesInDirectory((string) getenv("GEMC_DATA_DIR") ));
42  if(opts.optMap["FIELD_DIR"].args != "env") mergeMaps(filesMap, getFilesInDirectory(opts.optMap["FIELD_DIR"].args));
43 
44 
45  // checking eligibility of each file
46  // if eligible, load field definitions
47  map<string, gfield> gfields;
48 
49  for(map<string, string>::iterator it = filesMap.begin(); it != filesMap.end(); it++)
50  {
51  // if factory exist, calling isEligible
52  fieldFactory *thisFactory = getFieldFactory(&fieldFactoryMap, it->second);
53 
54  if(thisFactory != NULL)
55  {
56  if(thisFactory->isEligible(it->first))
57  {
58  gfield gf = thisFactory->loadField(it->first, opts);
59  gf.fFactory = thisFactory;
60 
61  // if symmetry is set, it's probably a good field
62  if(gf.symmetry != "na")
63  {
64  gfields[gf.name] = gf;
65  if(verbosity > 0) cout << gfields[gf.name] << endl;
66  }
67  }
68  }
69  // not done with the factory, cannot delete factory pointer
70  // it's needed later for loading field maps
71  }
72 
73  return gfields;
74 }
75 
map< string, fieldFactoryInMap > registerFieldFactories()
Definition: fieldFactory.cc:19
map< string, gfield > loadAllFields(map< string, fieldFactoryInMap > fieldFactoryMap, goptions opts)
Definition: fieldFactory.cc:30
double verbosity
string symmetry
Field symmetry.
Definition: field.h:73
fieldFactory * getFieldFactory(map< string, fieldFactoryInMap > *fieldsFactoryMap, string fieldsMethod)
Definition: fieldFactory.cc:7
string name
Field name - used as key in the map<string, gfield>
Definition: field.h:72
virtual bool isEligible(string)=0
map< string, aopt > optMap
Options map.
Definition: options.h:75
static fieldFactory * createFieldFactory()
Definition: asciiField.h:24
virtual gfield loadField(string, goptions)=0
Definition: field.h:52
fieldFactory * fFactory
fieldFactory that created the field
Definition: field.h:93
void mergeMaps(map< string, string > &lhs, const map< string, string > &rhs)
Definition: utils.cc:75
map< string, string > getFilesInDirectory(string directory)
Definition: utils.cc:262