TDbiSimFlagAssociation.cxx
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <iostream>
00019 #include <sstream>
00020 using std::ostringstream;
00021
00022 #include <string>
00023 using std::string;
00024 #include <vector>
00025 using std::vector;
00026
00027 #include "TDbiSimFlagAssociation.hxx"
00028 #include <TSK_DBI_Log.hxx>
00029 #include <MsgFormat.h>
00030 using std::endl;
00031 #include "TDbiRegistry.hxx"
00032 #include "UtilString.hxx"
00033
00034 ClassImp(TDbiSimFlagAssociation)
00035
00036
00037
00038
00039
00040
00041 const TDbiSimFlagAssociation* TDbiSimFlagAssociation::fgInstance = 0;
00042
00043
00044
00045
00046 ostream& operator<<(ostream& s, const TDbiSimFlagAssociation& simFlagAss) {
00047 simFlagAss.Print(s);
00048 return s;
00049 }
00050
00051
00052
00053
00054
00055
00056 TDbiSimFlagAssociation::TDbiSimFlagAssociation() {
00057
00058
00059
00060
00061
00062
00063
00064
00065 SK_DBI_Trace( "Creating TDbiSimFlagAssociation" << " ");
00066
00067
00068 fgInstance = this;
00069
00070 }
00071
00072
00073
00074
00075 TDbiSimFlagAssociation::~TDbiSimFlagAssociation() {
00076
00077
00078
00079
00080
00081
00082
00083
00084 SK_DBI_Trace( "Destroying TDbiSimFlagAssociation" << " ");
00085
00086
00087 if ( fgInstance == this ) fgInstance = 0;
00088
00089 }
00090
00091
00092 TDbiSimFlagAssociation::SimList_t
00093 TDbiSimFlagAssociation::Get(const DbiSimFlag::SimFlag_t value)const {
00094
00095
00096
00097
00098
00099
00100 SimMap_t::const_iterator itr = fAssociations.find(value);
00101 if ( itr != fAssociations.end() ) return itr->second;
00102 SimList_t l;
00103 l.push_back(value);
00104 return l;
00105
00106 }
00107
00108
00109
00110 const TDbiSimFlagAssociation& TDbiSimFlagAssociation::Instance() {
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125 if ( ! fgInstance ) new TDbiSimFlagAssociation;
00126
00127 return *fgInstance;
00128
00129 }
00130
00131
00132 void TDbiSimFlagAssociation::Print(ostream& s)const {
00133
00134
00135
00136
00137 s << "\n\nSimFlag Association Status: ";
00138 if ( fAssociations.size() == 0 ) s <<"Not enabled" << endl;
00139 else {
00140 s << endl;
00141
00142 SimMap_t::const_iterator mapItr = fAssociations.begin();
00143 SimMap_t::const_iterator mapItrEnd = fAssociations.end();
00144 while ( mapItr != mapItrEnd ) {
00145
00146 DbiSimFlag::SimFlag_t value = mapItr->first;
00147 string name = DbiSimFlag::AsString(value);
00148 ostringstream buff;
00149 buff << name << "(" << value << ")";
00150 name = buff.str();
00151 if ( name.size() < 20 ) name.append(20-name.size(),' ');
00152 s << name << "maps to: ";
00153
00154 SimList_t l = mapItr->second;
00155 SimList_t::const_iterator listItr = l.begin();
00156 SimList_t::const_iterator listItrEnd = l.end();
00157 while ( listItr != listItrEnd ) {
00158 DbiSimFlag::SimFlag_t v = *listItr;
00159 string n = DbiSimFlag::AsString(v);
00160 s << n << "(" << v << ")";
00161 ++listItr;
00162 if ( listItr != listItrEnd ) s << ", ";
00163 }
00164 s << endl;
00165 ++mapItr;
00166 }
00167
00168 }
00169 }
00170
00171
00172
00173 void TDbiSimFlagAssociation::Set(TDbiRegistry& reg) {
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189 TDbiRegistry::TDbiRegistryKey keyItr(®);
00190
00191 Bool_t hasChanged = kFALSE;
00192
00193 const char* key = keyItr();
00194 while ( key ) {
00195
00196 const char* nextKey = keyItr();
00197 if ( ! strncmp("SimFlagAssociation:",key,19) ) {
00198
00199
00200 string Name = key+19;
00201 DbiSimFlag::SimFlag_t value = DbiSimFlag::StringToEnum(Name.c_str());
00202 const char* listChars = 0;
00203 bool ok = reg.Get(key,listChars) && (value != DbiSimFlag::kUnknown);
00204
00205 SimList_t lv;
00206 if ( ok ) {
00207 vector<string> ls;
00208 UtilString::StringTok(ls,listChars,",");
00209 vector<string>::iterator itr = ls.begin();
00210 vector<string>::iterator itrEnd = ls.end();
00211 for (; itr != itrEnd; ++itr ) {
00212 DbiSimFlag::SimFlag_t v = DbiSimFlag::StringToEnum(itr->c_str());
00213 if ( v == DbiSimFlag::kUnknown) ok = false;
00214 lv.push_back(v);
00215 }
00216 }
00217
00218 if ( ok ) {
00219 this->Set(value,lv);
00220 hasChanged = true;
00221 }
00222 else SK_DBI_Warn( "Illegal SimFlagAssociation registry item: " << key
00223 << " = " << listChars << " ");
00224
00225 reg.RemoveKey(key);
00226 }
00227 key = nextKey;
00228 }
00229
00230 if ( hasChanged ) this->Show();
00231 }
00232
00233
00234
00235 void TDbiSimFlagAssociation::Show() {
00236
00237
00238
00239
00240 SK_DBI_Info( *this << " ");
00241
00242
00243 }
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276