Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:22:58

0001 void test_AnyHistory(){
0002 
0003   // select SM number and channel number
0004   Int_t sm=9; // from 0 to 36
0005   Int_t chan_num=1036; // from 1 to 1700
0006 
0007   // select table and field
0008 
0009  // this is for BLUE or RED APD/PN or APD Mean 
0010    //  char table_name[20]="MON_LASER_RED_DAT";
0011    //   char table_name[20]="MON_LASER_BLUE_DAT";
0012 
0013   // char field_name[20]="APD_OVER_PN_MEAN";
0014    //    char field_name[20]="APD_MEAN";
0015 
0016  // this is for pedestals RMS
0017     char table_name[20]="MON_PEDESTALS_DAT";
0018      char field_name[20]="PED_RMS_G12";
0019   //  char field_name[20]="PED_RMS_G1";
0020   // char field_name[20]="PED_RMS_G6";
0021 
0022 
0023  Int_t sm_num=1041000000+10000*sm+sm;
0024 
0025 /*connect with oracle server */
0026 TSQLServer *db=TSQLServer::Connect("oracle://pccmsecdb:1521/ecalh4db","read01","XXXpasswordXXX");
0027 
0028  gStyle->SetOptStat(0);
0029  gStyle->SetOptFit();
0030  gStyle->SetPalette(1,0);
0031 
0032  char titolo[100];
0033   sprintf(titolo,"%s.%s for chan %d of SM %d",table_name,field_name,chan_num, sm_num );
0034 
0035 
0036  c1 = new TCanvas("c1","History plot from DB",200,10,600,400);
0037  c1->SetGrid();
0038  // c1->Divide(2,3);
0039 
0040 TDatime da(2005,01,01,00,00,00);
0041 gStyle->SetTimeOffset(da.Convert());
0042 
0043 
0044 /* first see how many rows we have */
0045  
0046  char sql_test[620];
0047  char query_skeleton1[33]="SELECT count(mon_run_iov.iov_id) "; 
0048  char query_skeleton2[420];
0049 
0050 char query_1[20]=" from channelview, ";
0051 char query_2[110]=" , mon_run_iov , run_iov, run_tag, run_dat WHERE run_iov.iov_id=mon_run_iov.RUN_IOV_ID and channelview.id2= ";
0052 char query_2b[27]=" and mon_run_iov.iov_id= ";
0053 char query_3[36]=".iov_id and channelview.logic_id= ";
0054 char query_4[169]=".logic_id and channelview.name=channelview.maps_to and  run_iov.tag_id=run_tag.tag_id and run_tag.LOCATION_ID=1 and run_dat.iov_id=run_iov.iov_id and run_dat.logic_id=";
0055 
0056   sprintf(query_skeleton2,"%s%s%s%d%s%s%s%s%s",query_1,table_name, query_2,chan_num, query_2b, 
0057       table_name,  query_3,table_name,  query_4);
0058 
0059   sprintf(sql_test,"%s%s%d",query_skeleton1, query_skeleton2,sm_num);
0060 
0061 
0062  TSQLResult *res=db->Query(sql_test);   
0063  int j=0;
0064  int nRows=0;
0065 
0066  do {
0067    j++;
0068    TSQLRow *row1=res->Next();
0069    TOracleRow * row2=(TOracleRow *)row1;  
0070    nRows=atoi( row2->GetField(0));
0071    delete row2;
0072    
0073  } while (j<1);
0074  cout <<"number of entries in the DB = "<< nRows<< endl; 
0075 
0076  /* now see the starting and end time of the plot */
0077 
0078  char query_skeleton0[90]="SELECT min(SUBRUN_START-to_date('01-JAN-2005 00:00:00','DD-MON-YYYY HH24:MI:SS'))"; 
0079 
0080   sprintf(sql_test,"%s%s%d",query_skeleton0, query_skeleton2,sm_num);
0081 
0082  TSQLResult *res=db->Query(sql_test);   
0083  int j=0;
0084  float tStart=0;
0085 
0086  do {
0087    j++;
0088    TSQLRow *row1=res->Next();
0089    TOracleRow * row2=(TOracleRow *)row1;  
0090    tStart=atof( row2->GetField(0));
0091    delete row2;
0092    
0093  } while (j<1);
0094  cout <<"tStart= "<< tStart << endl; 
0095 
0096  char query_skeleton3[90]="SELECT max(SUBRUN_START-to_date('01-JAN-2005 00:00:00','DD-MON-YYYY HH24:MI:SS'))"; 
0097 
0098   sprintf(sql_test,"%s%s%d",query_skeleton3, query_skeleton2,sm_num);
0099 
0100  TSQLResult *res=db->Query(sql_test);   
0101  int j=0;
0102  float tEnd=0;
0103 
0104  do {
0105    j++;
0106    TSQLRow *row1=res->Next();
0107    TOracleRow * row2=(TOracleRow *)row1;  
0108    tEnd=atof( row2->GetField(0));
0109    delete row2;
0110    
0111  } while (j<1);
0112  cout <<"tEnd= "<< tEnd << endl; 
0113 
0114  float day_to_sec=24.*60.*60.;
0115  tStart=(tStart-2)*day_to_sec;
0116  tEnd=(tEnd+2)*day_to_sec;
0117 temp_vs_time  = new TH2F("temp_vs_time",titolo, 100,tStart ,tEnd , 100, 0.,100. );
0118  temp_vs_time->GetXaxis()->SetTitle("Time");
0119  temp_vs_time->GetYaxis()->SetTitle(field_name);
0120 temp_vs_time->GetXaxis()->SetTimeDisplay(1);  // The X axis is a time axis 
0121 temp_vs_time->GetXaxis()->SetTimeFormat("%d-%m-%y");
0122  temp_vs_time->GetXaxis()->SetLabelSize(0.02);
0123  // 
0124 
0125  char query_skeleton4[200];
0126  char query_skeleton4a[49]="SELECT channelview.id2, CAST( ";
0127  char query_skeleton4b[110]=" AS NUMBER), (SUBRUN_START-to_date('01-JAN-2005 00:00:00','DD-MON-YYYY HH24:MI:SS')) , channelview.logic_id "; 
0128 
0129   sprintf(query_skeleton4,"%s%s.%s%s",query_skeleton4a,table_name,field_name,query_skeleton4b);
0130 
0131   sprintf(sql_test,"%s%s%d",query_skeleton4, query_skeleton2,sm_num);
0132 
0133 
0134 
0135  TSQLResult *res=db->Query(sql_test);   
0136  
0137  float temp=0;
0138  float time_meas=0;
0139  int chan=0;
0140  int j=0; 
0141  do {
0142    j++;
0143    TSQLRow *row1=res->Next();
0144    TOracleRow * row2=(TOracleRow *)row1;  
0145    
0146    for (int i=0; i<res->GetFieldCount();i++) {
0147          printf(" %*.*s ",row2->GetFieldLength(i),row2->GetFieldLength(i),row2->GetField(i)); 
0148      if(i==0) chan=atoi( row2->GetField(i));
0149      if(i==1) temp=atof( row2->GetField(i));
0150      if(i==2) time_meas=atof( row2->GetField(i))*day_to_sec;
0151    }
0152      cout <<  endl;
0153    
0154    Float_t tpippo= (Float_t)temp;
0155    Float_t tchanx= (Float_t) ((chan-1)/10) ;
0156    Float_t tchany= (Float_t) ((chan-1)%10) ;
0157    temp_vs_time->Fill(time_meas, tpippo,1.);
0158    
0159    
0160    //   cout << chan << " " << tchanx << " " << tchany << " " << tpippo << endl; 
0161    
0162    
0163    
0164    delete row2;
0165    
0166  } while (j<nRows);
0167  cout <<"loop done "<< endl; 
0168 
0169  
0170  // c1->cd(1);
0171  //hv_vmon->Draw();
0172  //c1->Update();
0173 
0174  //  c1->cd(1);
0175 
0176 
0177 temp_vs_time->SetMarkerStyle(20);
0178 temp_vs_time->SetMarkerSize(0.7);
0179  temp_vs_time->Draw();
0180  c1->Update(); 
0181  
0182 
0183  
0184  printf("end \n");
0185 
0186  delete res;
0187  delete db;
0188  
0189 }