00001 void Example_tagDB(const Char_t * selection = NULL)
00002 {
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00018
00019
00020
00021 gBenchmark = new TBenchmark();
00022 gBenchmark->Start("total");
00023
00024 TSQLServer *db = TSQLServer::
00025 Connect("mysql://duvall.star.bnl.gov/fcMDC3", "", "");
00026
00027 TSQLResult *res;
00028 TSQLRow *row;
00029 TStringLong query= "SELECT CONCAT(path,'/',fName)
00030 FROM fileCatalog
00031 WHERE fName LIKE '%tags.root'
00032 AND readable='Y'
00033 AND dataset LIKE '%";
00034 if (selection!=NULL)
00035 query+=selection;
00036 query+="%'";
00037
00038 res = db->Query(query.Data());
00039 Int_t nFiles = res->GetRowCount();
00040
00041 cout<<"Selected "<<nFiles<<" files from the tagDB"<<endl;
00042 if (nFiles==0) return;
00043
00044
00045 gROOT->ProcessLine(".O4");
00046
00047 TChain chain("Tag");
00048 TString fileName;
00049 UInt_t nF=0;
00050 while ((row = res->Next())) {
00051 fileName=row->GetField(0);
00052 fileName.ReplaceAll("/home/starreco/reco","/star/rcf/GC/tags");
00053
00054 nF++;
00055 if (nF%100==0)
00056 cout<<"Chained "<<nF<<" files, Total events = "
00057 <<chain->GetEntries()<<endl;
00058
00059
00060 chain.Add(fileName.Data());
00061 }
00062 cout<<"chained "<<chain->GetEntries()<<" events from the tagDB"<<endl;
00063
00064
00065 db->Close();
00066
00067 TObjArray *files = chain.GetListOfFiles();
00068 cout<<"chained "<<files->GetEntriesFast()<<" files from the tagDB"<<endl;
00069
00070
00071
00072 TObjArray *branches = chain.GetListOfBranches();
00073 TObjArray *leaves = chain.GetListOfLeaves();
00074 Int_t nleaves = leaves->GetEntriesFast();
00075
00076 TString file;
00077 Int_t l;
00078 TLeaf *leaf;
00079 TBranch *branch;
00080
00081
00082 for (l=0;l<nleaves;l++) {
00083 leaf = (TLeaf*)leaves->UncheckedAt(l);
00084 branch = leaf->GetBranch();
00085 cout<< "StructureName: "<<branch->GetName()
00086 << ", tagName: "<<leaf->GetName()<<endl;
00087 }
00088
00089
00090 chain->Draw("NLa");
00091 gPad->Update();
00092
00093
00094 gBenchmark->Start("loop");
00095
00096 for (Int_t k=0;k<chain->GetEntries();k++) {
00097
00098
00099 chain->GetEntry(k);
00100
00101
00102 if (k == *(chain.GetTreeOffset()+chain.GetTreeNumber())) {
00103 file = (files->UncheckedAt(chain.GetTreeNumber()))->GetTitle();
00104 cout<<"chain event "<< k
00105 <<", start of file "<< chain.GetTreeNumber()+1 <<endl;
00106
00107
00108
00109 leaf = chain.GetLeaf("NLa");
00110 cout<<leaf->GetName()<<" = "<<leaf->GetValue()<<endl;
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121 }
00122 }
00123
00124
00125 gBenchmark->Stop("loop");
00126 gBenchmark->Print("loop");
00127 gBenchmark->Stop("total");
00128 gBenchmark->Print("total");
00129 }