Configuration.cc

Go to the documentation of this file.
00001 
00002 // this class header file
00003 #include "../include/Configuration.h"
00004 
00005 #include <iostream>
00006 #include <fstream>
00007 #include <sstream>
00008 
00009 //**********************
00010 
00011 //starting functions
00012 Configuration::Configuration()
00013 {
00014   // the default randomseed will be generated from the time
00015   srand(time(0)%900000000);
00016   rseed=rand();
00017   
00018   // default: 1000 events
00019   nevents=1000;
00020   
00021   // default Outputfilename
00022   OutputFileName="output.root";
00023   
00024   // default: no Algorithm specified
00025   dijet = false;
00026   z = false;
00027   wplusjet = false;
00028   tau = false;
00029   top = false;
00030   ue = false;
00031   etmiss = false;
00032   elasScat = false;
00033   user = false;
00034   
00035   // default Jet parameter
00036   coneRadius = 0.4;
00037   overlapThreshold = 0.75;
00038   jet_ptmin = 15.0;
00039   lepton_ptmin = 15.0;
00040   DeltaR_lepton_track = 0.4;
00041   max_eta = 2.5;
00042   min_pt = 0.5;
00043   
00044   FSR=true;
00045   ISR=true;
00046   MI=true;
00047   
00048   IsOK=true;
00049 }
00050 
00051 Configuration::Configuration( std::string configfile )
00052 {
00053   Configuration();
00054   IsOK=read(configfile);
00055 }
00056 
00057 Configuration::~Configuration()
00058 {
00059   while(!ConfigFileNames.empty())
00060     ConfigFileNames.pop_back();
00061 }
00062 
00063 
00064 int  Configuration::read(std::string configfile){
00065   std::string line;
00066   std::ifstream myfile (configfile.c_str());
00067   std::cout << "readConfigFile: Read in Configuration from file " << configfile << std::endl;
00068   if (myfile.is_open())
00069     {
00070       // read line by line of the file
00071       while (! myfile.eof() )
00072         {
00073           std::string parameter;
00074           std::string str1;
00075           int mylong=-9999;
00076           double myfloat=-9999.9;
00077           bool mybool=false;
00078           
00079           // write read lines into string line
00080           getline (myfile,line);
00081           
00082           // now split the line into the subwords
00083           std::istringstream instring(line);
00084           std::istringstream instring2(line);
00085           std::istringstream instring3(line);
00086           
00087           // and fill string or float
00088           instring >> parameter >> str1 ;
00089           instring2 >> parameter >> myfloat ;
00090           instring3 >> parameter >> mybool ;
00091           mylong=long(myfloat);
00092           
00093           // check for Comments. If the line starts with # than skip the line
00094           std::string::size_type pos = parameter.find("#");
00095           if(pos != std::string::npos) continue;
00096           // check for Comments. If the line starts with * than skip the line
00097           std::string::size_type pos2 = parameter.find("*");
00098           if(pos2 != std::string::npos) continue;
00099           // check for Comments. If the line starts with '/' than skip the line
00100           std::string::size_type pos3 = parameter.find("/");
00101           if(pos3 != std::string::npos) continue;
00102           
00103           // skip if the string is empty
00104           if(parameter.empty()) continue;
00105           
00106           
00107           // read pysub entries
00108           if ((parameter == "rseed") && (mylong!=-9999)) {
00109             rseed=mylong;
00110             std::cout << "readConfigFile: Parameter " << parameter << "=" << rseed << std::endl;
00111           }
00112           else if ((parameter == "nevents") && (mylong!=-9999)){
00113             nevents=(unsigned int)mylong;
00114             std::cout << "readConfigFile: Parameter " << parameter << "=" << nevents << std::endl;
00115           }
00116           else if ((parameter == "OutputFileName") && (!str1.empty())){
00117             OutputFileName=str1;
00118             std::cout << "readConfigFile: Parameter " << parameter << "=" << OutputFileName << std::endl;
00119           }
00120           else if ((parameter == "ConfigFileNames") && (!str1.empty())){
00121             ConfigFileNames.push_back(str1);
00122             std::cout << "readConfigFile: Parameter " << parameter << "=" << ConfigFileNames.back() << std::endl;
00123           }
00124           else if ((parameter == "InputFileNames") && (!str1.empty())){
00125             InputFileNames.push_back(str1);
00126             std::cout << "readConfigFile: Parameter " << parameter << "=" << InputFileNames.back() << std::endl;
00127           }
00128           else if ((parameter == "dijet_analysis") && (!str1.empty())){
00129             if( (str1 == "on") ||  (str1 == "true") ||  (str1 == "True")) dijet=true;
00130             std::cout << "readConfigFile: Parameter " << parameter << "=" << dijet << std::endl;
00131           }
00132           else if ((parameter == "z_analysis")  && (!str1.empty())){
00133             if( (str1 == "on") ||  (str1 == "true") ||  (str1 == "True")) z=true;
00134             std::cout << "readConfigFile: Parameter " << parameter << "=" << z << std::endl;
00135           }
00136           else if ((parameter == "wplusjet_analysis")  && (!str1.empty())){
00137             if( (str1 == "on")  ||  (str1 == "true") ||  (str1 == "True") ) wplusjet=true;
00138             std::cout << "readConfigFile: Parameter " << parameter << "=" << wplusjet << std::endl;
00139           }
00140           else if ((parameter == "tau_analysis")  && (!str1.empty())){
00141             if( (str1 == "on")  ||  (str1 == "true") ||  (str1 == "True") ) tau=true;
00142             std::cout << "readConfigFile: Parameter " << parameter << "=" << tau << std::endl;
00143           }
00144           else if ((parameter == "top_analysis")  && (!str1.empty())){
00145             if( (str1 == "on")  ||  (str1 == "true") ||  (str1 == "True") ) top=true;
00146             std::cout << "readConfigFile: Parameter " << parameter << "=" << top << std::endl;
00147           }
00148           else if ((parameter == "ue_analysis")  && (!str1.empty())){
00149             if( (str1 == "on")  ||  (str1 == "true") ||  (str1 == "True") ) ue=true;
00150             std::cout << "readConfigFile: Parameter " << parameter << "=" << ue << std::endl;
00151           }
00152           else if ((parameter == "etmiss_analysis")  && (!str1.empty())){
00153             if( (str1 == "on")  ||  (str1 == "true") ||  (str1 == "True") ) etmiss=true;
00154             std::cout << "readConfigFile: Parameter " << parameter << "=" << etmiss << std::endl;
00155           }
00156           else if ((parameter == "elasScat_analysis")  && (!str1.empty())){
00157             if( (str1 == "on")  ||  (str1 == "true") ||  (str1 == "True") ) elasScat=true;
00158             std::cout << "readConfigFile: Parameter " << parameter << "=" << elasScat << std::endl;
00159           }
00160           else if ((parameter == "user_analysis")  && (!str1.empty())){
00161             if( (str1 == "on")  ||  (str1 == "true") ||  (str1 == "True") ) user=true;
00162             std::cout << "readConfigFile: Parameter " << parameter << "=" << user << std::endl;
00163           }
00164           else if ((parameter == "jet_coneRadius") && (myfloat!=-9999.9)){
00165             coneRadius=myfloat;
00166             std::cout << "readConfigFile: Parameter " << parameter << "=" << coneRadius << std::endl;
00167           }
00168           else if ((parameter == "jet_overlapThreshold") && (myfloat!=-9999.9)){
00169             overlapThreshold=myfloat;
00170             std::cout << "readConfigFile: Parameter " << parameter << "=" << overlapThreshold << std::endl;
00171           }
00172           else if ((parameter == "jet_ptmin") && (myfloat!=-9999.9)){
00173             jet_ptmin=myfloat;
00174             std::cout << "readConfigFile: Parameter " << parameter << "=" << jet_ptmin << std::endl;
00175           }
00176           else if ((parameter == "DeltaR_lepton_track") && (myfloat!=-9999.9)){
00177             DeltaR_lepton_track=myfloat;
00178             std::cout << "readConfigFile: Parameter " << parameter << "=" << DeltaR_lepton_track << std::endl;
00179           }
00180           else if ((parameter == "lepton_ptmin") && (myfloat!=-9999.9)){
00181             lepton_ptmin=myfloat;
00182             std::cout << "readConfigFile: Parameter " << parameter << "=" << lepton_ptmin << std::endl;
00183           }
00184           else if ((parameter == "max_eta") && (myfloat!=-9999.9)){
00185             max_eta=myfloat;
00186             std::cout << "readConfigFile: Parameter " << parameter << "=" << max_eta << std::endl;
00187           }
00188           else if ((parameter == "min_pt") && (myfloat!=-9999.9)){
00189             min_pt=myfloat;
00190             std::cout << "readConfigFile: Parameter " << parameter << "=" << min_pt << std::endl;
00191           }
00192           else if ((parameter == "FSR")  && (!str1.empty())){
00193             if( (str1 == "on")  ||  (str1 == "true") ||  (str1 == "True") ) FSR=true;
00194             else FSR=false;
00195             std::cout << "readConfigFile: Parameter " << parameter << "=" << FSR << std::endl;
00196           }
00197           else if ((parameter == "ISR")  && (!str1.empty())){
00198             if( (str1 == "on")  ||  (str1 == "true") ||  (str1 == "True") ) ISR=true;
00199             else ISR=false;
00200             std::cout << "readConfigFile: Parameter " << parameter << "=" << ISR << std::endl;
00201           }
00202           else if ((parameter == "MI")  && (!str1.empty())){
00203             if( (str1 == "on")  ||  (str1 == "true") ||  (str1 == "True") ) MI=true;
00204             else MI=false;
00205             std::cout << "readConfigFile: Parameter " << parameter << "=" << MI << std::endl;
00206           }
00207           else{
00208             std::cout << "readConfigFile: Parameter " << parameter << " not recognized!" << std::endl;
00209             return 1;
00210           }
00211         }
00212       myfile.close();
00213     }
00214   else 
00215     {
00216       std::cerr << "readConfigFile: Unable to open file" << std::endl;
00217       return 1;
00218     }
00219   return 0;
00220 }

Generated on Mon Jan 4 15:22:34 2010 for HepMCAnalysis by  doxygen 1.4.7