00001 // $Id: DbiConfigSet.cxx,v 1.15 2006/08/08 10:51:32 west Exp $ 00002 00003 #include "DatabaseInterface/Dbi.h" 00004 #include "DatabaseInterface/DbiConfigSet.h" 00005 #include "DatabaseInterface/DbiOutRowStream.h" 00006 #include "DatabaseInterface/DbiResultSet.h" 00007 #include "MessageService/MsgService.h" 00008 00009 #include <iostream> 00010 00011 ClassImp(DbiConfigSet) 00012 00013 00014 // Definition of static data members 00015 // ********************************* 00016 00017 CVSID("$Id: DbiConfigSet.cxx,v 1.15 2006/08/08 10:51:32 west Exp $\n \ 00018 CVSID_DBIRESULTPTR "); 00019 00020 // Instantiate associated Result Pointer and Writer classes. 00021 // ******************************************************** 00022 00023 #include "DatabaseInterface/DbiResultPtr.tpl" 00024 template class DbiResultPtr<DbiConfigSet>; 00025 00026 #include "DatabaseInterface/DbiWriter.tpl" 00027 template class DbiWriter<DbiConfigSet>; 00028 00029 // Definition of all member functions (static or otherwise) 00030 // ******************************************************* 00031 // 00032 // - ordered: ctors, dtor, operators then in alphabetical order. 00033 00034 //..................................................................... 00035 00036 DbiConfigSet::~DbiConfigSet() { 00037 // 00038 // 00039 // Purpose: Destructor 00040 00041 LEA_DTOR; 00042 00043 for ( vector<Param*>::iterator itr = fParams.begin(); 00044 itr != fParams.end(); 00045 ++itr ) delete (*itr); 00046 00047 } 00048 00049 //..................................................................... 00050 00051 ostream& operator<<(ostream& s, const DbiConfigSet& cfSet) { 00052 // 00053 // 00054 // Purpose: Output configuration set to message stream. 00055 // 00056 // Arguments: 00057 // s in Message stream 00058 // cfSet in Configuration set to be output 00059 // 00060 // Return: Message stream 00061 // 00062 // Contact: N. West 00063 // 00064 // Specification:- 00065 // ============= 00066 // 00067 // o Output configuration set to message stream. 00068 00069 // Program Notes:- 00070 // ============= 00071 00072 // None. 00073 00074 s << "DbiConfigSet: Number of parameters: " 00075 << cfSet.GetNumParams() << endl; 00076 00077 for ( UInt_t iParam = 0; iParam < cfSet.GetNumParams(); ++iParam) { 00078 s << " " << cfSet.GetParamName(iParam) << ": " 00079 << cfSet.GetParamValue(iParam) << " (" 00080 << cfSet.GetParamType(iParam).AsString() << ")" << endl; 00081 } 00082 00083 return s; 00084 00085 } 00086 00087 00088 00089 //..................................................................... 00090 00091 void DbiConfigSet::Fill(DbiResultSet& rs, 00092 const DbiValidityRec* vrec) { 00093 // 00094 // 00095 // Purpose: Fill oject from Result Set 00096 // 00097 // Arguments: 00098 // rs in Result Set used to fill object 00099 // vrec in Associated validity record (or 0 if filling 00100 // DbiValidityRec) 00101 // 00102 // Return: 00103 // 00104 // Contact: N. West 00105 // 00106 // Specification:- 00107 // ============= 00108 // 00109 // o Fill object from current (and only) row of Result Set. 00110 00111 // Program Notes:- 00112 // ============= 00113 00114 // None. 00115 00116 00117 // Don't count leading SeqNo, its already been skipped. 00118 UInt_t numParams = rs.NumCols()-1; 00119 // Skip the ROW_COUNTER if present 00120 if ( rs.HasRowCounter() ) --numParams; 00121 00122 for (UInt_t iParam = 0; iParam < numParams; ++iParam ) { 00123 Param* par = new Param; 00124 par->Name = rs.CurColName(); 00125 par->Value = rs.CurColValue(); 00126 par->Type = rs.CurColFieldType(); 00127 00128 fParams.push_back(par); 00129 rs.IncrementCurCol(); 00130 } 00131 00132 fAggregateNo = vrec->GetAggregateNo (); 00133 00134 } 00135 //..................................................................... 00136 00137 string DbiConfigSet::GetParamName(UInt_t parNo) const { 00138 // 00139 // 00140 // Purpose: Get the name of selected parameter. 00141 // 00142 // Arguments: 00143 // parNo in parNo (in range 0..GetNumParams()) 00144 // 00145 // Return: The name of selected parameter 00146 // or "" if parNo out of range. 00147 // 00148 // Contact: N. West 00149 // 00150 // Specification:- 00151 // ============= 00152 // 00153 // o Get the name of selected parameter or "" if parNo out of range. 00154 00155 // Program Notes:- 00156 // ============= 00157 00158 // None. 00159 00160 return ( parNo <= GetNumParams() ) ? 00161 fParams[parNo]->Name : ""; 00162 00163 } 00164 //..................................................................... 00165 00166 DbiFieldType DbiConfigSet::GetParamType(UInt_t parNo) const { 00167 // 00168 // 00169 // Purpose: Get the type of selected parameter. 00170 // 00171 // Arguments: 00172 // parNo in parNo (in range 0..GetNumParams()) 00173 // 00174 // Return: The type of selected parameter 00175 // or Dbi::kUnknown if parNo out of range. 00176 // 00177 // Contact: N. West 00178 // 00179 // Specification:- 00180 // ============= 00181 // 00182 // o Get the type of selected parameter or Dbi::kUnknown if 00183 // parNo out of range. 00184 00185 // Program Notes:- 00186 // ============= 00187 00188 // None. 00189 00190 return ( parNo <= GetNumParams() ) ? 00191 fParams[parNo]->Type : DbiFieldType(Dbi::kUnknown); 00192 00193 } 00194 //..................................................................... 00195 00196 string DbiConfigSet::GetParamValue(UInt_t parNo) const { 00197 // 00198 // 00199 // Purpose: Get the value of selected parameter. 00200 // 00201 // Arguments: 00202 // parNo in parNo (in range 0..GetNumParams()) 00203 // 00204 // Return: The value of selected parameter 00205 // or "" if parNo out of range. 00206 // 00207 // Contact: N. West 00208 // 00209 // Specification:- 00210 // ============= 00211 // 00212 // o Get the value of selected parameter or "" if parNo out of range. 00213 00214 // Program Notes:- 00215 // ============= 00216 00217 // None. 00218 00219 return ( parNo <= GetNumParams() ) ? 00220 fParams[parNo]->Value : ""; 00221 00222 } 00223 00224 //..................................................................... 00225 00226 void DbiConfigSet::PushBack(const string& name, 00227 const string& value, 00228 const DbiFieldType& type) { 00229 // 00230 // 00231 // Purpose: Add another entry to the end of the existing row. 00232 00233 fParams.push_back(new Param(name,value,type)); 00234 } 00235 00236 //..................................................................... 00237 00238 void DbiConfigSet::Store(DbiOutRowStream& ors, 00239 const DbiValidityRec* /* vrec */) const { 00240 // 00241 // 00242 // Purpose: Stream object to output row stream 00243 // 00244 // Arguments: 00245 // ors in Output row stream. 00246 // vrec in =0. If filling other table rows it points 00247 // to the associated validity record. 00248 // 00249 // Return: 00250 // 00251 // Contact: N. West 00252 // 00253 // Specification:- 00254 // ============= 00255 // 00256 // o Stream object to output row stream. 00257 00258 // Program Notes:- 00259 // ============= 00260 00261 // This method sneaks round the back of the DbiRowStream interface 00262 // and directly uses the private Store method as the data is already 00263 // in string form. Its all in a good cause because this allows 00264 // DbiConfigSet to output data from any type of table. 00265 00266 for ( vector<Param*>::const_iterator itr = fParams.begin(); 00267 itr != fParams.end(); 00268 ++itr ) ors.Store((*itr)->Value.c_str()); 00269 00270 } 00271
1.3.9.1