Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

DbiSimFlagAssociation.cxx

Go to the documentation of this file.
00001 // $Id: DbiSimFlagAssociation.cxx,v 1.1 2003/08/08 16:34:18 west Exp $
00003 // DbiSimFlagAssociation                                              //
00004 //                                                                    //
00005 // Package: Dbi (Database Interface).                                 //
00006 //                                                                    //
00007 // N. West 08/2003                                                    //
00008 //                                                                    //
00009 // Concept: Association of a particular SimFlag type with a list of   //
00010 //          SimFlag types.                                            //
00011 //                                                                    //
00012 // Purpose: To allow the DBI to choose an alternative SimFlag type    //
00013 //          when attempting to satisfy queries.  For example, allow   //
00014 //          MC data to use Data constants.                            //
00015 //                                                                    //
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 "DatabaseInterface/DbiSimFlagAssociation.h"
00028 #include "LeakChecker/Lea.h"
00029 #include "MessageService/MsgService.h"
00030 #include "Registry/Registry.h"
00031 #include "Util/UtilString.h"
00032 
00033 ClassImp(DbiSimFlagAssociation)
00034 
00035 
00036 //   Definition of static data members
00037 //   *********************************
00038 
00039 CVSID("$Id: DbiSimFlagAssociation.cxx,v 1.1 2003/08/08 16:34:18 west Exp $");
00040 
00041 const DbiSimFlagAssociation* DbiSimFlagAssociation::fgInstance = 0;
00042 
00043 // Definition of global functions (alphabetical order)
00044 // ***************************************************
00045 
00046 ostream& operator<<(ostream& s, const DbiSimFlagAssociation& simFlagAss) {
00047   simFlagAss.Print(s);
00048   return s;
00049 }
00050 
00051 // Definition of member functions (alphabetical order)
00052 // ***************************************************
00053 
00054 //.....................................................................
00055 
00056 DbiSimFlagAssociation::DbiSimFlagAssociation() {
00057 //
00058 //
00059 //  Purpose:  Default constructor
00060 //
00061 //  Contact:   N. West
00062 //
00063 
00064   LEA_CTOR    //Leak Checker
00065 
00066   MSG("Dbi", Msg::kVerbose) << "Creating DbiSimFlagAssociation" << endl;
00067 
00068   // Connect to global pointer;
00069   fgInstance = this;
00070 
00071 }
00072 
00073 
00074 //.....................................................................
00075 
00076 DbiSimFlagAssociation::~DbiSimFlagAssociation() {
00077 //
00078 //
00079 //  Purpose: Destructor
00080 //
00081 //  Contact:   N. West
00082 //
00083 
00084   LEA_DTOR    //Leak Checker
00085 
00086   MSG("Dbi", Msg::kVerbose) << "Destroying DbiSimFlagAssociation" << endl;
00087 
00088   // Disconnect from global pointer;
00089   if ( fgInstance == this ) fgInstance = 0;
00090 
00091 }
00092 //.....................................................................
00093 
00094 DbiSimFlagAssociation::SimList_t 
00095      DbiSimFlagAssociation::Get(const SimFlag::SimFlag_t value)const {
00096 //
00097 //
00098 //  Purpose:  Return associated list 
00099 //            or just list containing value if none.
00100 //
00101 
00102   SimMap_t::const_iterator itr = fAssociations.find(value);
00103   if ( itr != fAssociations.end() ) return itr->second;
00104   SimList_t l;
00105   l.push_back(value);
00106   return l;
00107 
00108 }
00109 
00110 //.....................................................................
00111 
00112 const DbiSimFlagAssociation& DbiSimFlagAssociation::Instance() {
00113 //
00114 //
00115 //  Purpose:  Get access to the one and only instance.
00116 //
00117 
00118 //  Program Notes:-
00119 //  =============
00120 
00121 //  If necessary, creates a DbiSimFlagAssociation, but once 
00122 //  DbiTableProxyRegistry has been created, it's owned version
00123 //  will supersede it and orginal will be lost (leak).
00124 //  In practice this should never happen; DbiTableProxyRegistry is
00125 //  the first significant object to be created.
00126 
00127   if ( ! fgInstance ) new DbiSimFlagAssociation;
00128   // The act of creation will set fgInstance.
00129   return *fgInstance;
00130 
00131 }
00132 //.....................................................................
00133 
00134 void DbiSimFlagAssociation::Print(ostream& s)const {
00135 //
00136 //
00137 //  Purpose:  Print self.
00138 
00139   s << "\n\nSimFlag Association Status:  ";
00140   if ( fAssociations.size() == 0 ) s <<"Not enabled" << endl;
00141   else {
00142     s << endl;
00143 
00144     SimMap_t::const_iterator mapItr    = fAssociations.begin();
00145     SimMap_t::const_iterator mapItrEnd = fAssociations.end();
00146     while ( mapItr != mapItrEnd ) {
00147 
00148       SimFlag::SimFlag_t value = mapItr->first;
00149       string name = SimFlag::AsString(value);
00150       ostringstream buff;
00151       buff << name << "(" << value << ")";
00152       name = buff.str();
00153       if ( name.size() < 20 ) name.append(20-name.size(),' ');
00154       s << name << "maps to: ";
00155 
00156       SimList_t l = mapItr->second;
00157       SimList_t::const_iterator listItr    = l.begin();
00158       SimList_t::const_iterator listItrEnd = l.end();
00159       while ( listItr != listItrEnd ) {
00160         SimFlag::SimFlag_t v = *listItr;
00161         string n = SimFlag::AsString(v);
00162         s << n << "(" << v << ")";
00163         ++listItr;
00164         if ( listItr != listItrEnd ) s << ", ";
00165       }
00166       s << endl;
00167       ++mapItr;
00168     }
00169 
00170   } 
00171 }
00172 
00173 //.....................................................................
00174 
00175 void DbiSimFlagAssociation::Set(Registry& reg) {
00176 //
00177 //
00178 //  Purpose:  Extract SimFlag association lists from Registry.
00179 //
00180 //  Arguments: 
00181 //    reg          in    Registry containing "SimFlagAssociation:..." keys.
00182 //                 out   Updated Registry with these keys removed.
00183 //
00184 //  Contact:   N. West
00185 //
00186 //  Specification:-
00187 //  =============
00188 //
00189 //  o Extract SimFlag association lists from Registry.
00190 
00191   Registry::RegistryKey keyItr(&reg);
00192  
00193   Bool_t  hasChanged = kFALSE;
00194 
00195   const char* key = keyItr();
00196   while ( key ) {
00197 
00198     const char* nextKey =  keyItr();
00199     if ( ! strncmp("SimFlagAssociation:",key,19) ) {
00200 
00201       // Found a SimFlagAssociation key, extract its value.
00202       string Name = key+19;
00203       SimFlag::SimFlag_t value = SimFlag::StringToEnum(Name.c_str());
00204       const char* listChars = 0;
00205       bool ok = reg.Get(key,listChars) && (value != SimFlag::kUnknown);
00206       // Collect the associated list
00207       SimList_t lv;
00208       if ( ok ) {
00209         vector<string> ls;
00210         UtilString::StringTok(ls,listChars,",");
00211         vector<string>::iterator itr    = ls.begin();
00212         vector<string>::iterator itrEnd = ls.end();
00213         for (; itr != itrEnd; ++itr ) {
00214           SimFlag::SimFlag_t v = SimFlag::StringToEnum(itr->c_str());
00215           if ( v == SimFlag::kUnknown) ok = false;
00216           lv.push_back(v);
00217         }
00218       }
00219 
00220       if ( ok ) {
00221         this->Set(value,lv);
00222         hasChanged = true;
00223       }
00224       else  MSG("Dbi",Msg::kWarning) 
00225           << "Illegal SimFlagAssociation registry item: " << key
00226           << " = " << listChars << endl;
00227 
00228       reg.RemoveKey(key);
00229     }
00230     key = nextKey;
00231   }
00232 
00233   if ( hasChanged ) this->Show();
00234 }
00235 
00236 //.....................................................................
00237 
00238 void DbiSimFlagAssociation::Show() {
00239 //
00240 //
00241 //  Purpose:  
00242 
00243   MSG("Dbi",Msg::kInfo) << *this << endl;
00244 
00245 
00246 }
00247 
00248 /*    Template for New Member Function
00249 
00250 //.....................................................................
00251 
00252 DbiSimFlagAssociation:: {
00253 //
00254 //
00255 //  Purpose:  
00256 //
00257 //  Arguments: 
00258 //    xxxxxxxxx    in    yyyyyy
00259 //
00260 //  Return:    
00261 //
00262 //  Contact:   N. West
00263 //
00264 //  Specification:-
00265 //  =============
00266 //
00267 //  o 
00268 
00269 //  Program Notes:-
00270 //  =============
00271 
00272 //  None.
00273 
00274 
00275 }
00276 
00277 */
00278 

Generated on Mon Feb 15 11:06:34 2010 for loon by  doxygen 1.3.9.1