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