00001 #include <iostream>
00002 #include <fstream>
00003 #include <iomanip>
00004 #include <string>
00005 #include <cstring>
00006 #include <vector>
00007
00008 #include "TFile.h"
00009 #include "TTree.h"
00010 #include "TFolder.h"
00011 #include "TProfile.h"
00012 #include "TObjArray.h"
00013 #include "TSpline.h"
00014 #include "TPostScript.h"
00015 #include "TLatex.h"
00016 #include "TCanvas.h"
00017 #include "TStyle.h"
00018
00019 #include "include/MdcAlignPar.h"
00020 #include "include/MdcCosGeom.h"
00021 #include "include/fun.h"
00022 #include "include/ResiAlign.h"
00023
00024 using namespace std;
00025
00026 int main(int argc, char* argv[]){
00027 char* jobname;
00028 if(argc>1){
00029 jobname = argv[1];
00030 }else{
00031 cout << "bad argument" << endl;
00032 return -1;
00033 }
00034
00035 string path = "";
00036 string strJob = jobname;
00037 cout << "strJob: " << strJob << endl;
00038 string::size_type ilast = strJob.find_last_of("/");
00039 if(string::npos != ilast){
00040 path = strJob.substr(0, ilast);
00041 }
00042
00043 int alignMeth;
00044 string alignFile;
00045 string confname;
00046 string str;
00047 string strtmp;
00048 ifstream fjob(jobname);
00049 if( ! fjob.is_open() ){
00050 cout << "ERROR: can not read jobOption: " << jobname << endl;
00051 return 0;
00052 } else{
00053 cout << "Open jobOption: " << jobname << endl;
00054 while( getline(fjob, str) ){
00055 if(str.find("//", 0) != string::npos){
00056 continue;
00057 } else if( str.find("MdcGeomSvc.alignFilePath", 0) != string::npos ){
00058 string::size_type i1 = str.find_first_of("\"");
00059 string::size_type i2 = str.find_last_of("\"");
00060 alignFile = str.substr(i1+1, i2-i1-1);
00061 } else if(str.find("MdcAlignAlg.ConfigFile", 0) != string::npos){
00062 string::size_type i1 = str.find_first_of("\"");
00063 string::size_type i2 = str.find_last_of("\"");
00064 confname = str.substr(i1+1, i2-i1-1);
00065 } else if(str.find("MdcAlignAlg.MdcAlignMeth", 0) != string::npos){
00066 string::size_type i1 = str.find_first_of("=");
00067 string::size_type i2 = str.find_last_of(";");
00068 strtmp = str.substr(i1+1, i2-i1-1);
00069 sscanf(strtmp.c_str(), "%d", &alignMeth);
00070 }
00071 }
00072 }
00073
00074 MdcCosGeom* pGeom = 0;
00075 pGeom = new MdcCosGeom("/home/bes/wulh/document/wireconf.txt", "/home/bes/wulh/calibConst/MdcAlignPar_ini.txt" );
00076 pGeom -> initialize(0.0);
00077
00078 TObjArray* hlist = new TObjArray(0);
00079 AlignBase* pAlign;
00080 if(0 == alignMeth) pAlign = new ResiAlign();
00081 else {cout << "Error AlignType" << endl; return 0;}
00082 pAlign->init(hlist, pGeom);
00083
00084 vector<string> fhistname = getHistList();
00085 if(0==fhistname.size()){
00086 cout << "hist file path: " << path << endl;
00087 fhistname = getHistList(path);
00088 }
00089 for(unsigned nf=0; nf<fhistname.size(); nf++){
00090 TFile* fin = new TFile(fhistname[nf].c_str());
00091 if(!fin->IsOpen()){
00092 continue;
00093 } else{
00094 cout << "merge hist file " << nf << ": " << fhistname[nf] << endl;
00095 pAlign->mergeHist(fin);
00096 fin->Close();
00097 }
00098 }
00099
00100
00101 MdcAlignPar* alignPar = new MdcAlignPar();
00102 alignPar->initAlignPar();
00103 alignPar->rdAlignPar(alignFile);
00104
00105
00106 pAlign->align(alignPar);
00107
00108 TFile fhist("histall.root", "recreate");
00109 fhist.cd();
00110 hlist->Write();
00111 fhist.Close();
00112
00113
00114 alignPar->wrtAlignPar();
00115
00116 return 0;
00117 }
00118