00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "NtupleReader/MyTextFileReader.h"
00014
00015
00016
00017
00018
00019
00020 using namespace std;
00021
00022
00023
00024
00025
00026
00027
00028
00029 void MyTextFileReader::init(TString textfilename) {
00030
00031 m_textfilename = textfilename;
00032 return;
00033 }
00034
00035
00036
00037
00038
00039
00040
00041 void MyTextFileReader::destruct(void) {
00042
00043 return;
00044
00045 }
00046
00047
00048
00049
00050
00051
00052
00053
00054 TString
00055 MyTextFileReader::get_textfilename(void) {
00056
00057 return m_textfilename;
00058
00059 }
00060
00061
00062
00063
00064
00065
00066
00067 template <class MyType> MyType
00068 MyTextFileReader::retrieve_from_file(TString key_string, TString filename){
00069
00070
00071
00072 MyType value;
00073 TString aBuffer;
00074 TString dummy;
00075
00076 TString m_filename = filename;
00077
00078
00079
00080 if(m_filename=="")
00081 m_filename = m_textfilename;
00082
00083 ifstream myFile(m_filename);
00084
00085
00086
00087 if (myFile.fail()){
00088 std::cerr << std::endl
00089 << "Error: Could not open " << m_filename
00090 << std::endl;
00091 exit(1);
00092 }
00093
00094
00095
00096 while ( !myFile.eof() ){
00097
00098 aBuffer.ReadToken( myFile );
00099
00100 if ( aBuffer==key_string){
00101 myFile >> dummy;
00102 myFile >> value;
00103 }
00104
00105 if (myFile.eof()) {
00106 break;
00107 }
00108
00109 }
00110
00111
00112 return value;
00113 }
00114
00115
00116
00117
00118
00119
00120
00121 TString
00122 MyTextFileReader::get_string(TString key_string){
00123
00124
00125
00126
00127 TString string;
00128 string = retrieve_from_file<TString>(key_string);
00129
00130 return string;
00131
00132 }
00133
00134 Bool_t
00135 MyTextFileReader::get_bool(TString key_string){
00136
00137
00138
00139
00140 Bool_t flag;
00141 flag = retrieve_from_file<Bool_t>(key_string);
00142
00143 return flag;
00144
00145 }
00146
00147 int
00148 MyTextFileReader::get_int(TString key_string){
00149
00150
00151
00152
00153 int flag;
00154 flag = retrieve_from_file<int>(key_string);
00155
00156 return flag;
00157
00158 }
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169 void
00170 MyTextFileReader::fill_cutvalue_map(TString cutstring, TString filename){
00171 m_cutvalue_map.clear();
00172
00173
00174 TString sdummy;
00175 TString eqdummy;
00176 Double_t vdummy;
00177
00178 int nvalues = -1;
00179 TString aBuffer;
00180
00181 TString m_filename = filename;
00182
00183
00184
00185 if(m_filename=="")
00186 m_filename = m_textfilename;
00187
00188 ifstream myFile(m_filename);
00189
00190
00191
00192 if (myFile.fail()){
00193 std::cerr << std::endl
00194 << "Error: Could not open " << m_filename
00195 << std::endl;
00196 exit(1);
00197 }
00198
00199
00200
00201
00202 while ( !myFile.eof() ){
00203
00204 if ( nvalues < 0 ){
00205
00206 aBuffer.ReadToken( myFile );
00207 if ( aBuffer.Index(cutstring+":") != kNPOS ){
00208 nvalues = 0;
00209 }
00210 }
00211 else{
00212
00213 myFile >> sdummy;
00214 if(sdummy=="#end_of_"+cutstring) break;
00215
00216 if(sdummy.Contains("#") || sdummy==""){
00217 continue;
00218 }
00219
00220 myFile >> eqdummy;
00221 myFile >> vdummy;
00222
00223
00224
00225 m_cutvalue_map.insert(ValuePair(sdummy,vdummy));
00226
00227 nvalues++;
00228
00229 }
00230
00231 if (myFile.eof()) {
00232 break;
00233 }
00234
00235 }
00236
00237
00238
00239
00240
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 Double_t
00267 MyTextFileReader::get_cutvalue(TString variable){
00268
00269
00270
00271
00272 Double_t value;
00273
00274 maptype::const_iterator iter = m_cutvalue_map.find(variable);
00275 if( iter != m_cutvalue_map.end() ){
00276 value = (*iter).second;
00277 }
00278 else{
00279 std::cerr << std::endl
00280 << "Error: Could not find variable: "
00281 << variable
00282 << std::endl;
00283 exit(1);
00284 }
00285
00286 return value;
00287
00288 }
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308