File indexing completed on 2025-08-03 08:22:01
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027 #ifndef __CINT__
0028
0029
0030 #include <TError.h>
0031 #include <TH1.h>
0032 #include <TH2.h>
0033 #include <TProfile.h>
0034 #include <TCanvas.h>
0035 #include <TSystem.h>
0036 #include <TROOT.h>
0037
0038 #include <RDBC/TSQLDriverManager.h>
0039 #include <RDBC/TSQLConnection.h>
0040 #include <RDBC/TSQLResultSet.h>
0041 #include <RDBC/TSQLResultSetMetaData.h>
0042 #include <RDBC/TSQLPreparedStatement.h>
0043
0044 #endif
0045
0046 const TString tableName = "object_test";
0047
0048
0049 TH1F* hpx=0;
0050 TH2F* hpxpy=0;
0051 TProfile* hprof=0;
0052
0053
0054 void DropStuff(TSQLConnection* con)
0055 {
0056
0057
0058 TSQLStatement* stmt = con->CreateStatement();
0059 stmt->ExecuteUpdate("drop table " + tableName);
0060 printf("Dropped table %s\n",tableName.Data());
0061 delete stmt;
0062 }
0063
0064
0065 Int_t RDBCconsumer( const Text_t* dsn,
0066 const Text_t* usr,
0067 const Text_t* pwd )
0068 {
0069
0070
0071
0072
0073
0074 TObject *to;
0075 TSQLConnection* con;
0076 TString str;
0077
0078
0079 TSQL::SetHandler("Catch(TSQLException*)");
0080
0081 str = "dsn="; str += dsn;
0082 str += "; uid="; str += usr;
0083
0084
0085 con = gSQLDriverManager->GetConnection(str);
0086
0087 if(!con) return -1;
0088
0089 printf("\t\t\t DONE.\n");
0090
0091 TCanvas *c1;
0092 TPad *pad1, *pad2, *pad3;
0093
0094 c1 = new TCanvas("c1","Reading objects from Database Example",200,10,700,780);
0095 pad1 = new TPad("pad1","This is pad1",0.02,0.52,0.98,0.98,21);
0096 pad2 = new TPad("pad2","This is pad2",0.02,0.02,0.48,0.48,21);
0097 pad3 = new TPad("pad3","This is pad3",0.52,0.02,0.98,0.48,21);
0098 pad1->Draw();
0099 pad2->Draw();
0100 pad3->Draw();
0101
0102 TSQLStatement* stmt = con->CreateStatement(kTYPE_FORWARD_ONLY,
0103 kCONCUR_READ_ONLY);
0104
0105 loop:
0106 TSQLResultSet* rs;
0107 rs = stmt->ExecuteQuery("select name, histos from " + tableName);
0108
0109 if (!rs) {
0110 for(int i=0; i<50; i++) {
0111 gSystem->Sleep(100);
0112 gSystem->ProcessEvents();
0113 }
0114 printf("\n\n\t\t** producer not connected yet **\n\n");
0115 goto loop;
0116 }
0117
0118
0119
0120 Double_t oldentries = 0;
0121 for (int j = 0; j < 100; j++)
0122 {
0123 if(hpx) delete hpx;
0124 if(hpxpy) delete hpxpy;
0125 if(hprof) delete hprof;
0126
0127 rs = stmt->ExecuteQuery("select name, histos from " + tableName);
0128 if (!rs) break;
0129
0130 while (rs->Next())
0131 {
0132 str = rs->GetString(1);
0133 cout << str << endl;
0134 to = rs->GetObject(2);
0135 if(str=="hpx") hpx = (TH1F *)to;
0136 else if(str=="hpxpy" ) hpxpy = (TH2F *)to;
0137 else if(str=="hprof") hprof = (TProfile *)to;
0138 }
0139 if (hpx->GetEntries() == oldentries) break;
0140 oldentries = hpx->GetEntries();
0141 pad1->cd();
0142 if (hpx) hpx->Draw();
0143 pad2->cd();
0144 if (hprof) hprof->Draw();
0145 pad3->cd();
0146 if (hpxpy) hpxpy->Draw("cont");
0147 c1->Modified();
0148 c1->Update();
0149
0150 gSystem->Sleep(100);
0151
0152 delete rs;
0153 }
0154
0155 delete stmt;
0156
0157
0158 con->Commit();
0159 con->Close();
0160 return 0;
0161 }
0162
0163
0164 void Catch(TSQLException* e)
0165 {
0166
0167
0168 TString str = e->GetMessage();
0169 printf("%s\n",str.Data());
0170 }