StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
history.C
1 static int startday=082;
2 static int endday=365;
3 
4 static const int NRUN=10000;
5 static int nrun=0;
6 static int ngoodrun=0;
7 
8 static const int NCRATE=14;
9 static const char* CRATE[NCRATE]={"L1","BC1","MXQ","MIX","BCW","BCE","FEQ",
10  "BBC","BBQ","FMS","QT1","QT2","QT3","QT4"};
11 static const int color[NCRATE]= {kGreen,kBlue,kRed,kBlue,kBlue,kBlue,kRed,
12  kBlue,kRed,kBlue,kRed,kRed,kRed,kRed};
13 
14 static const int NVAL=3;
15 static int run[NRUN];
16 static Float_t frun[NRUN];
17 static Long64_t idx[NRUN];
18 static double val[NCRATE][NVAL][NRUN]; //2nd index 0=mean,1=rms,2=max
19 static TGraph* g[NCRATE][NVAL]; //last index 0=mip,1=mean,2=tac,3=tacdiff
20 
21 //#include <stdio.h>
22 //#include <dirent.h>
23 //#include <algorithm>
24 
25 void read(int irun, int runnum){
26  char file[100];
27  int yearday=runnum/1000;
28  sprintf(file,"www/%d/rcc.%d.txt",yearday,runnum);
29  FILE* f=fopen(file,"r");
30  if(!f) { printf("Failed to open %s\n",file); return; }
31  //printf("Reading %s\n",file);
32  run[irun]=runnum;
33  int nzero=0;
34  for(int i=0; i<NCRATE; i++){
35  float rmean,rrms,rmax;
36  fscanf(f,"%f %f %f",&rmean,&rrms,&rmax);
37  val[i][0][irun]=rmean;
38  val[i][1][irun]=rrms;
39  val[i][2][irun]=rmax;
40  g[i][0]->SetPoint(ngoodrun,double(irun),val[i][0][irun]);
41  g[i][1]->SetPoint(ngoodrun,double(irun),val[i][1][irun]);
42  g[i][2]->SetPoint(ngoodrun,double(irun),val[i][2][irun]);
43  }
44  ngoodrun++;
45  fclose(f);
46 }
47 
48 void readall(int day){
49  int i=0;
50  char tmp[100];
51  float r;
52  int year=day/1000;
53  int yearday=day%1000;
54  //printf("%d %d %d\n",day,year,yearday);
55  if(yearday!=0) {startday=yearday; endday=yearday;}
56  for(int d=startday; d<=endday; d++){
57  int yday=year*1000+d;
58  char dirname[100]; sprintf(dirname,"www/%5d/",yday);
59  TSystemDirectory dir(dirname,dirname);
60  TList *files = dir.GetListOfFiles();
61  if(files){
62  TSystemFile *file;
63  TString fname;
64  TIter next(files);
65  while ((file=(TSystemFile*)next())) {
66  fname = file->GetName();
67  if (!file->IsDirectory() && fname.BeginsWith("rcc") && fname.EndsWith(".txt")) {
68  sscanf(fname.Data(),"%4s%8f%4s",tmp,&r,tmp);
69  frun[i]=(Long64_t)r;
70  i++;
71  //printf("%s %8.0f\n",fname.Data(),r);
72  }
73  }
74  }
75  }
76  nrun=i;
77  TMath::Sort((long)i,frun,idx,0);
78  for(int j=0; j<nrun; j++){
79  read(j,(int)frun[idx[j]]);
80  }
81 }
82 
83 void plot(int val=1, float xmin=0.0, float xmax=0.0, float ymin=0.0, float ymax=500.0){
84  if(xmax==0) xmax=nrun;
85  TH2F *frame = new TH2F("frame","",1,xmin,xmax,1,ymin,ymax); frame->Draw();
86  for(int i=0; i<NCRATE; i++){
87  g[i][val]->Draw("L");
88  }
89 }
90 
91 void history(int day=15170, int zoom=0,
92  float xmin=0.0, float xmax=0.0,
93  float ymin=0.0, float ymax=65536.0,
94  float ymin2=0.0, float ymax2=65536.0/3.0,
95  float ymin3=0.0, float ymax3=65536.0*3.0
96  ){
97  if(zoom>0) {
98  ymax=4000;
99  ymax2=600;
100  ymax3=20000;
101  }
102  for(int i=0; i<NCRATE; i++){
103  for(int v=0; v<NVAL; v++){
104  g[i][v]=new TGraph(1);
105  g[i][v]->SetMarkerStyle(20);
106  g[i][v]->SetMarkerSize(1);
107  g[i][v]->SetLineColor(color[i]);
108  }
109  }
110  readall(day);
111  gStyle->SetOptStat(0);
112  TText *t;
113  c1 = new TCanvas("c1","History",50,0,700,720);
114  c1->Divide(1,3);
115  c1->cd(1); plot(0,xmin,xmax,ymin,ymax);
116  t=new TText(0.15,0.92,"Mean(RCC-TCU)[xing]"); t->SetNDC(); t->SetTextSize(0.1); t->Draw();
117  t=new TText(0.75,0.8,"DSM Crates"); t->SetNDC(); t->SetTextSize(0.07); t->SetTextColor(kBlue); t->Draw();
118  t=new TText(0.75,0.7,"QT Crates"); t->SetNDC(); t->SetTextSize(0.07); t->SetTextColor(kRed); t->Draw();
119  c1->cd(2); plot(1,xmin,xmax,ymin2,ymax2);
120  t=new TText(0.15,0.92,"RMS(RCC-TCU)[xing]"); t->SetNDC(); t->SetTextSize(0.1); t->Draw();
121  c1->cd(3); plot(2,xmin,xmax,ymin3,ymax3);
122  t=new TText(0.15,0.92,"MAX(RCC-TCU)[xing]"); t->SetNDC(); t->SetTextSize(0.1); t->Draw();
123  t=new TText(0.77,0.01,"RunIdx"); t->SetNDC(); t->SetTextSize(0.1); t->Draw();
124  TLine *l = new TLine(0.0, 65536.0,nrun, 65536.0); l->Draw();
125  if(zoom==0){
126  t=new TText(0.15,0.45,"Memory Overwrite above"); t->SetNDC(); t->SetTextSize(0.05); t->Draw();
127  }
128  c1->Update();
129  char file[100];
130  if(day%1000!=0) {
131  if(zoom>0) {sprintf(file,"%d/historyz.%5d.png",day,day);}
132  else {sprintf(file,"%d/history.%5d.png",day,day);}
133  }else{
134  if(zoom>0) {sprintf(file,"historyz.png",day);}
135  else {sprintf(file,"history.png",day);}
136  }
137  c1->SaveAs(file);
138  printf("Create %s\n",file);
139 }
140