AraWebPlotter/AraPlotUtils.cxx
00001 00002 00003 00004 00005 00006 00007 00008 00009 #include "AraPlotUtils.h" 00010 #include "TStyle.h" 00011 #include "TROOT.h" 00012 #include "TCanvas.h" 00013 #include "TGraph.h" 00014 #include "TColor.h" 00015 #include "TAxis.h" 00016 #include "TH1.h" 00017 #include "TMultiGraph.h" 00018 #include "TPaveText.h" 00019 #include "TLatex.h" 00020 #include <fstream> 00021 #include <utime.h> 00022 #include <sys/stat.h> 00023 00024 TLatex *gLatex=0; 00025 00026 const char * AraPlotTime::getTimeString(AraPlotTime_t plotTime) 00027 { 00028 const char *myString; 00029 switch(plotTime) { 00030 case kFullTime: 00031 myString="All"; 00032 break; 00033 case kOneHour: 00034 myString="OneHour"; 00035 break; 00036 case kSixHours: 00037 myString="SixHours"; 00038 break; 00039 case kTwelveHours: 00040 myString="TwelveHours"; 00041 break; 00042 case kOneDay: 00043 myString="OneDay"; 00044 break; 00045 default: 00046 myString="Unknown"; 00047 break; 00048 } 00049 return myString; 00050 } 00051 00052 00053 const char * AraPlotTime::getTimeTitleString(AraPlotTime_t plotTime) 00054 { 00055 const char *myString; 00056 switch(plotTime) { 00057 case kFullTime: 00058 myString="All Time"; 00059 break; 00060 case kOneHour: 00061 myString="Last Hour"; 00062 break; 00063 case kSixHours: 00064 myString="Last Six Hours"; 00065 break; 00066 case kTwelveHours: 00067 myString="Last Twelve Hours"; 00068 break; 00069 case kOneDay: 00070 myString="Last Day"; 00071 break; 00072 default: 00073 myString="Unknown"; 00074 break; 00075 } 00076 return myString; 00077 } 00078 00079 00080 //AraPlotTime_t operator++ (const AraPlotTime_t& x, int) 00081 //{ 00082 // int ix=(int)x; 00083 // ++x; 00084 // return (AraPlotTime_t)x; 00085 // 00086 //} 00087 00088 00089 00090 00091 void AraPlotUtils::setDefaultStyle() { 00092 // gROOT->SetStyle("Plain"); 00093 // gStyle->SetCanvasBorderMode(0); 00094 // gStyle->SetFrameBorderMode(0); 00095 // gStyle->SetPadBorderMode(0); 00096 // gStyle->SetFrameFillStyle(4000); 00097 // gStyle->SetFillStyle(4000); 00098 // gStyle->SetDrawBorder(0); 00099 // gStyle->SetCanvasBorderSize(0); 00100 // gStyle->SetFrameBorderSize(0); 00101 // gStyle->SetPadBorderSize(0); 00102 gStyle->SetTitleBorderSize(0); 00103 00104 gStyle->SetStatColor(0); 00105 gStyle->SetCanvasColor(0); 00106 gStyle->SetPadColor(0); 00107 00108 // // Set the size of the default canvas 00109 gStyle->SetCanvasDefH(400); 00110 gStyle->SetCanvasDefW(500); 00111 // gStyle->SetCanvasDefX(10); 00112 // gStyle->SetCanvasDefY(10); 00113 00114 // Set Line Widths 00115 // gStyle->SetFrameLineWidth(1); 00116 gStyle->SetFuncWidth(1); 00117 // gStyle->SetHistLineWidth(1); 00118 gStyle->SetFuncColor(kRed); 00119 gStyle->SetFuncStyle(2); 00120 00121 // //Set Marker things for graphs 00122 gStyle->SetMarkerStyle(29); 00123 gStyle->SetMarkerColor(9); 00124 gStyle->SetMarkerSize(0.75); 00125 00126 // // Set margins -- I like to shift the plot a little up and to the 00127 // // right to make more room for axis labels 00128 gStyle->SetPadTopMargin(0.1); 00129 gStyle->SetPadBottomMargin(0.15); 00130 gStyle->SetPadLeftMargin(0.12); 00131 gStyle->SetPadRightMargin(0.05); 00132 00133 00134 // // Set tick marks and turn off grids 00135 // gStyle->SetNdivisions(505,"xyz"); 00136 00137 // // Set Data/Stat/... and other options 00138 // gStyle->SetOptDate(0); 00139 // //gStyle->SetDateX(0.1); 00140 // //gStyle->SetDateY(0.1); 00141 // gStyle->SetOptFile(0); 00142 gStyle->SetOptStat(1110); 00143 gStyle->SetStatFormat("6.3f"); 00144 gStyle->SetFitFormat("6.3f"); 00145 gStyle->SetOptFit(1); 00146 // gStyle->SetStatH(0.14); 00147 gStyle->SetStatStyle(0000); 00148 gStyle->SetStatW(0.2); 00149 gStyle->SetStatX(0.95); 00150 gStyle->SetStatY(0.9); 00151 gStyle->SetStatBorderSize(1); 00152 gStyle->SetStatColor(0); 00153 gStyle->SetOptTitle(1); 00154 00155 // // Adjust size and placement of axis labels 00156 // gStyle->SetLabelSize(0.04,"xyz"); 00157 // gStyle->SetLabelOffset(0.01,"x"); 00158 // gStyle->SetLabelOffset(0.01,"y"); 00159 // gStyle->SetLabelOffset(0.005,"z"); 00160 // gStyle->SetTitleSize(0.05,"xyz"); 00161 // gStyle->SetTitleOffset(0.5,"z"); 00162 gStyle->SetTitleOffset(1.3,"y"); 00163 00164 00165 // gStyle->SetPalette(1); 00166 const Int_t NRGBs = 5; 00167 const Int_t NCont = 255; 00168 00169 Double_t stops[NRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 }; 00170 Double_t red[NRGBs] = { 0.00, 0.00, 0.87, 1.00, 0.51 }; 00171 Double_t green[NRGBs] = { 0.00, 0.81, 1.00, 0.20, 0.00 }; 00172 Double_t blue[NRGBs] = { 0.51, 1.00, 0.12, 0.00, 0.00 }; 00173 TColor color; 00174 color.InitializeColors(); 00175 color.CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont); 00176 gStyle->SetNumberContours(NCont); 00177 00178 // gStyle->SetCanvasColor(0); 00179 gStyle->SetFrameFillColor(0); 00180 // // gStyle->SetFillColor(0); 00181 00182 00183 // // gStyle->SetPalette(51,0); 00184 gStyle->SetTitleH(0.06); 00185 gStyle->SetTitleW(0.6); 00186 gStyle->SetTitleBorderSize(0); 00187 gStyle->SetTitleStyle(0); 00188 // // gStyle->SetTitleFontSize(0.1); 00189 // gStyle->SetTextAlign(12); 00190 // // gStyle->SetTitleStyle(0); 00191 // // gStyle->SetStatX(0.9); 00192 // // gStyle->SetStatY(0.9); 00193 // // gStyle->SetStatH(0.2); 00194 // // gStyle->SetStatW(0.2); 00195 // // gStyle->SetStatFormat("6.3g"); 00196 // // gStyle->SetStatBorderSize(1); 00197 // // gStyle->SetOptStat(1110); 00198 // // gStyle->SetOptFit(1); 00199 // //gStyle->SetLabelSize(0.6); 00200 // //gStyle->SetLabelOffset(0.7); 00201 gROOT->ForceStyle(); 00202 00203 } 00204 00205 00206 int AraPlotUtils::getNiceColour(int index) 00207 { 00208 Int_t baseColours[12]={kRed,kBlue,kGreen,kMagenta,kCyan,kYellow,kPink,kAzure,kSpring,kOrange,kViolet,kTeal}; 00209 Int_t offsetNums[4]={+2,-2,+1,-1}; 00210 Int_t baseNum=index%12; 00211 Int_t offsetNum=(index/12)%4; 00212 return (baseColours[baseNum]+offsetNums[offsetNum]); 00213 } 00214 00215 int AraPlotUtils::getNiceMarker(int index) 00216 { 00217 int value=index%6; 00218 Int_t niceMarkers[6]={22,26,23,28,21,3}; 00219 return niceMarkers[value]; 00220 } 00221 00222 UInt_t AraPlotTime::getStartTime(UInt_t currentTime,AraPlotTime_t plotTime) 00223 { 00224 switch(plotTime) { 00225 case kFullTime: return 0; 00226 case kOneHour: return currentTime-3600; 00227 case kSixHours: return currentTime-(6*3600); 00228 case kTwelveHours: return currentTime-(12*3600); 00229 case kOneDay: return currentTime-(24*3600); 00230 default: return 0; //Who knows what they wanted 00231 } 00232 } 00233 00234 TMultiGraph* AraPlotUtils::plotMultigraph(TCanvas *can, TGraph *gr[], 00235 Int_t numGraphs, 00236 const char *plotTitle, const char *xTitle, const char *yTitle, 00237 int timeDisplay) 00238 { 00239 TMultiGraph *mg=0; 00240 int gotMg=0; 00241 for(int i=0;i<numGraphs;i++) { 00242 if(gr[i]) { 00243 00244 if(!mg) mg = new TMultiGraph(); 00245 gr[i]->SetLineColor(getNiceColour(i)); 00246 gr[i]->SetMarkerColor(getNiceColour(i)); 00247 gr[i]->SetMarkerStyle(getNiceMarker(i)); 00248 mg->Add(gr[i],"lp"); 00249 gotMg=1; 00250 } 00251 } 00252 00253 if(!gotMg) { 00254 if(mg) delete mg; //Shouldn't ever reach here 00255 return NULL; 00256 } 00257 //mg->SetTitle(plotTitle); 00258 00259 mg->Draw("ap"); 00260 if(mg->GetXaxis()) { 00261 mg->GetXaxis()->SetTimeDisplay(timeDisplay); 00262 if(xTitle) mg->GetXaxis()->SetTitle(xTitle); 00263 } 00264 if(mg->GetYaxis()) { 00265 if(yTitle)mg->GetYaxis()->SetTitle(yTitle); 00266 } 00267 // if(mg->GetHistogram()) 00268 // mg->GetHistogram()->SetTitle(plotTitle); 00269 if(!gLatex) gLatex = new TLatex(0,0.9,"dummy"); 00270 gLatex->DrawTextNDC(0.05,0.95,plotTitle); 00271 00272 return mg; 00273 00274 } 00275 00276 int AraPlotUtils::updateTouchFile(char *touchFile, UInt_t unixTime) 00277 { 00278 //Touch File 00279 struct utimbuf ut; 00280 ut.actime=unixTime; 00281 ut.modtime=unixTime; 00282 struct stat buf; 00283 int retVal2=stat(touchFile,&buf); 00284 if(retVal2==0) { 00285 if(buf.st_mtime<ut.modtime) { 00286 utime(touchFile,&ut); 00287 return 1; 00288 } 00289 } 00290 else { 00291 //Maybe file doesn't exist 00292 std::ofstream Touch(touchFile); 00293 Touch.close(); 00294 utime(touchFile,&ut); 00295 return 1; 00296 } 00297 return 0; 00298 }
Generated on Tue Jul 16 16:58:01 2013 for ARA ROOT v3.10 Software by
