EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FairDbSimFlagAssociation.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file FairDbSimFlagAssociation.cxx
1 
2 #include <iostream>
3 #include <sstream>
4 using std::ostringstream;
5 #include <iostream>
6 using namespace std;
7 #include <string>
8 using std::string;
9 #include <vector>
10 using std::vector;
11 
12 
14 #include "FairRegistry.h"
15 #include "FairDbString.h"
16 
18 
20 
21 
22 ostream& operator<<(ostream& s, const FairDbSimFlagAssociation& simFlagAss)
23 {
24  simFlagAss.Print(s);
25  return s;
26 }
27 
28 
30  : fAssociations()
31 {
32 
33  // Connect to global pointer;
34  fgInstance = this;
35 
36 }
37 
38 
39 
41 {
42  // Disconnect from global pointer;
43  if ( fgInstance == this ) { fgInstance = 0; }
44 
45 }
46 //.....................................................................
47 
50 {
51 
52  SimMap_t::const_iterator itr = fAssociations.find(value);
53  if ( itr != fAssociations.end() ) { return itr->second; }
54  SimList_t l;
55  l.push_back(value);
56  return l;
57 
58 }
59 
60 
62 {
63 
64  if ( ! fgInstance ) { new FairDbSimFlagAssociation; }
65  // The act of creation will set fgInstance.
66  return *fgInstance;
67 
68 }
69 
71 {
72 
73  s << "\n\nSimFlag Association Status: ";
74  if ( fAssociations.size() == 0 ) { s <<"Not enabled" << endl; }
75  else {
76  s << endl;
77 
78  SimMap_t::const_iterator mapItr = fAssociations.begin();
79  SimMap_t::const_iterator mapItrEnd = fAssociations.end();
80  while ( mapItr != mapItrEnd ) {
81 
82  SimFlag::SimFlag_t value = mapItr->first;
83  string name = SimFlag::AsString(value);
84  ostringstream buff;
85  buff << name << "(" << value << ")";
86  name = buff.str();
87  if ( name.size() < 20 ) { name.append(20-name.size(),' '); }
88  s << name << "maps to: ";
89 
90  SimList_t l = mapItr->second;
91  SimList_t::const_iterator listItr = l.begin();
92  SimList_t::const_iterator listItrEnd = l.end();
93  while ( listItr != listItrEnd ) {
94  SimFlag::SimFlag_t v = *listItr;
95  string n = SimFlag::AsString(v);
96  s << n << "(" << v << ")";
97  ++listItr;
98  if ( listItr != listItrEnd ) { s << ", "; }
99  }
100  s << endl;
101  ++mapItr;
102  }
103 
104  }
105 }
106 
107 
109 {
110 
111  FairRegistry::FairRegistryKey keyItr(&reg);
112 
113  Bool_t hasChanged = kFALSE;
114 
115  const char* key = keyItr();
116  while ( key ) {
117 
118  const char* nextKey = keyItr();
119  if ( ! strncmp("SimFlagAssociation:",key,19) ) {
120 
121  // Found a SimFlagAssociation key, extract its value.
122  string Name = key+19;
124  const char* listChars = 0;
125  bool ok = reg.Get(key,listChars) && (value != SimFlag::kUnknown);
126  // Collect the associated list
127  SimList_t lv;
128  if ( ok ) {
129  vector<string> ls;
130  FairUtilString::StringTok(ls,listChars,",");
131  vector<string>::iterator itr = ls.begin();
132  vector<string>::iterator itrEnd = ls.end();
133  for (; itr != itrEnd; ++itr ) {
135  if ( v == SimFlag::kUnknown) { ok = false; }
136  lv.push_back(v);
137  }
138  }
139 
140  if ( ok ) {
141  this->Set(value,lv);
142  hasChanged = true;
143  } else cout << "Illegal SimFlagAssociation registry item: " << key
144  << " = " << listChars << endl;
145 
146  reg.RemoveKey(key);
147  }
148  key = nextKey;
149  }
150 
151  if ( hasChanged ) { this->Show(); }
152 }
153 
154 //.....................................................................
155 
157 {
158 
159 }
160