#include "Riostream.h" #include "TObjString.h" #include "TString.h" void readWLCGAcct() { // Read WLCG data from an csv file and create a root file with an histogram and an ntuple. // see a variant of this macro in basic2.C // Author: Shawn McKee from basic.C example from Rene Brun and Mydemo_works.C from Axel // Sep 13, 2010 --- All inputs for 2009 converted in spreadsheet // to HS06: HS06(cvt)=3.9*kSI2K // read file WLCGAcctTier2.csv should be in same directory as this code // this file has a first row header followed by lines of data like: SiteName,CPU_hours_Jan09,CPU_hours_Feb09... TString FileName = gSystem->UnixPathName(gInterpreter->GetCurrentMacroName()); printf(" This macro: %s\n",FileName.Data()); FileName.ReplaceAll("readWLCGAcct.C","WLCGAcctTier2.csv"); FileName.ReplaceAll("/./","/"); // Define a stream to read in the file with ifstream in; // Maximum size const Int_t MAXHEAD = 100; const Int_t MAXSITES = 200; const Int_t NXRANGE = 50; printf(" Filename to open %s\n",FileName.Data()); in.open(Form("%s",FileName.Data()), ifstream::in); if (!in.good()) { printf(" Unable to open %s\n",FileName.Data()); exit; } // Create a new output file to put new ROOT tree into TFile *f = new TFile("WLCGAcct.root","recreate"); TTree *t = new TTree("WLCGAcct","A simple tree containing WLCG accounting info for Tier-2s"); Char_t tier2[30]; Int_t cpuhrs[MAXHEAD]; Int_t cpuh[MAXHEAD][MAXSITES]; TString headers[MAXHEAD]; // Create a set of pointers to 1d integer histograms TH1I* h[MAXHEAD]; // Create a "Tier-2" histogram (Tier-2 vs time) TH1I* sh[MAXSITES]; // Create an "hlist" to track 1d histograms TObjArray Hlist(0); TObjArray SHlist(0); Int_t ntier2s = 0; TString tier2s[MAXSITES]; // Count number of lines Int_t nlines = 0; TString line, tmp; Int_t nheader = 0; Int_t indexUSATLAS[5]; Int_t iUSA=0; Int_t indexUSCMS[7]; Int_t iUSC=0; Int_t lmonth=0; // Define "token" delimiters char delimiters[] = ",\n"; while (!line.ReadLine(in).eof()) { nlines++; // Insert dummy value for "blank" columns line.ReplaceAll(",,",",0,"); // Create a TobJArrray pointer to track the tokenized components of this line TObjArray* strings = line.Tokenize(delimiters); // printf("%i:(%i tokens) = %s\n",nlines,strings->GetEntriesFast(),line.Data()); // If we found 1 or more tokens on the line, process it if (strings->GetEntriesFast()) { TIter istring(strings); TObjString* os=0; Int_t itok=0; // Treat the first line differently since it contains the column headers if ( nlines == 1 ) { nheader = strings->GetEntriesFast(); if ( nheader > MAXHEAD ) { printf(" Found %d headers...only allow for %d...stopping\n",nheader,MAXHEAD); exit; } while ((os=(TObjString*)istring())) { headers[itok]=os->GetString().Data(); headers[itok].Strip(); // if (headers[itok].CompareTo("Blank",TString::kExact) == 0) { // printf(" Found -BLANK- column...continuing\n"); // continue; // } // Make sure column headers don't contain spaces or '-' headers[itok].ReplaceAll(" ","_"); headers[itok].ReplaceAll("-",""); headers[itok].ReplaceAll("Total_",""); printf("%d: token #%d = '%s'\n",nlines,itok, headers[itok].Data()); // Create tree branches if ( itok == 0 ) { // Site (first token is site name "Tier-2") t->Branch(headers[itok].Data(),tier2,"tier2/C"); } else { tmp=headers[itok].Data(); // line 87 tmp.Append("/I"); t->Branch(headers[itok].Data(),&cpuhrs[itok],tmp.Data()); // Prepare 1d histogram for this column tmp=headers[itok].Data(); if ( tmp.BeginsWith("Total",TString::kExact) && tmp.Length() == 5 ) { TString trng; trng=headers[1].Data(); trng+="-"; // Save "last" month index lmonth=itok-1; trng+=headers[lmonth].Data(); tmp.ReplaceAll("Total",trng.Data()); tmp.Prepend("Total WLCG Tier-2 CPU-hours(normalized, ALL VOs) from "); // Mixed units for this plot...convert to HS06 via HS06 = 3.9 kSI2K tmp.Append(" Top 50 Sites"); } else { tmp.Prepend("Total WLCG CPU-hours(normalized, ALL VOs) for "); tmp.Append(" - Top 50 Sites"); } printf(" Creating histogram(%d) titled |%s|\n",itok,tmp.Data()); h[itok] = new TH1I(headers[itok].Data(),tmp.Data(),3,0,3); // Add new histogram to Hlist Hlist.Add(h[itok]); // Which units for this plot? Up to Dec 2009 we used kSI2K-hours and after we use HS06-hours // Conversion 3.9 kSI2K = 1 HEPSPEC06 //https://twiki.cern.ch/twiki/bin/view/FIOgroup/ProcRefHepSpec2006Spec if ( tmp.Contains("09") ) { if ( tmp.Contains("from") ) { h[itok]->GetYaxis()->SetTitle("Normalized HS06(cvt)-hours"); } else { h[itok]->GetYaxis()->SetTitle("Normalized HS06(cvt)-hours"); } } else { h[itok]->GetYaxis()->SetTitle("Normalized HS06-hours"); } h[itok]->SetStats(0); h[itok]->SetFillColor(38); h[itok]->SetBit(TH1::kCanRebin); } itok++; } } else { while ((os=(TObjString*)istring())) { // printf("%d: token #%d = '%s'\n",nlines,itok++, os->GetString().Data()); if (itok == 0 ) { sscanf(os->GetString().Data(),"%15s",tier2); tier2s[ntier2s]=tier2; tmp=tier2; // Now create "Tier-2" histogram (performance vs time) sh[ntier2s] = new TH1I(os->GetString().Data(),tmp.Data(),3,0,3); // Add new histogram to Hlist SHlist.Add(sh[ntier2s]); sh[ntier2s]->GetYaxis()->SetTitle("Normalized HS06-hours"); sh[ntier2s]->SetStats(0); sh[ntier2s]->SetFillColor(38); sh[ntier2s]->SetBit(TH1::kCanRebin); } else { if (os->GetString().IsNull()) { printf(" Found empty data...continuing\n"); continue; } else { cpuhrs[itok]=os->GetString().Atoi(); cpuh[itok][ntier2s]=cpuhrs[itok]; } } itok++; } t->Fill(); ntier2s++; if ( ntier2s > MAXSITES ) { printf(" Exceeded maximum number of sites: %d > %d (MAXSITES)\n",ntier2s,MAXSITES); exit; } } } // Remove "strings" since we are done with it. delete strings; } // Write out tree f->cd(); // Create canvas of right size TCanvas *c1 = new TCanvas("c1", "c1",119,26,1269,590); c1->SetBorderSize(2); c1->SetRightMargin(0.016); c1->SetBottomMargin(0.34); c1->SetFrameFillColor(0); // Fill histograms now that we have the list of sites for (Int_t ihist=1; ihistFill(tier2s[it2].Data(),cpuh[ihist][it2]); } // Default histogram blue h[ihist]->SetFillColor(4); h[ihist]->GetYaxis()->SetTitleSize(0.055); h[ihist]->GetYaxis()->SetTitleOffset(0.92); h[ihist]->GetXaxis()->SetLabelSize(0.055); h[ihist]->GetXaxis()->SetLabelFont(22); h[ihist]->GetYaxis()->SetTitleFont(22); // h[ihist]->LabelsDeflate(); // Define range... h[ihist]->GetXaxis()->SetRange(0,NXRANGE); h[ihist]->LabelsOption("v>","X"); h[ihist]->Draw(); h[ihist]->DrawCopy(); // Set USATLAS sites "green" (SetFillColor(3)) for (Int_t i=0; iGetNbinsX(); i++) { tmp=h[ihist]->GetXaxis()->GetBinLabel(i); // Check for US ATLAS sites and mark them "green" if (tmp.BeginsWith("US-")) { h[ihist]->SetFillColor(3); h[ihist]->GetXaxis()->SetRange(i,i); h[ihist]->DrawCopy("same"); } } // Set USCMS sites "red" (SetFillColor(2)) for (Int_t i=0; iGetNbinsX(); i++) { tmp=h[ihist]->GetXaxis()->GetBinLabel(i); // Check for US CMS sites and mark them "red" if (tmp.BeginsWith("T2_US")) { h[ihist]->SetFillColor(2); h[ihist]->GetXaxis()->SetRange(i,i); h[ihist]->DrawCopy("same"); } } // Add Legend in... TPad *c1_1 = new TPad("c1_1", "legend",0.728,0.626,0.979,0.884); c1_1->Draw(); c1_1->cd(); c1_1->Range(0,0,1,1); c1_1->SetFillColor(41); c1_1->SetFrameFillColor(0); pt = new TPaveText(0.041,0.73,0.918,0.910,"br"); pt->SetFillColor(19); text = pt->AddText("WLCG TIer-2 Affiliation"); pt->Draw(); TPave *pave = new TPave(0.0915,0.51,0.15,0.65,4,"br"); pave->SetFillColor(3); pave->Draw(); pave = new TPave(0.0915,0.30,0.15,0.44,4,"br"); pave->SetFillColor(2); pave->Draw(); pave = new TPave(0.0915,0.09,0.15,0.23,4,"br"); pave->SetFillColor(4); pave->Draw(); pt = new TPaveText(0.1829205,0.4909653,0.8443066,0.6495903,"br"); pt->SetFillColor(19); text = pt->AddText("USATLAS Tier-2"); pt->Draw(); pt = new TPaveText(0.1829205,0.2909598,0.8443066,0.4495848,"br"); pt->SetFillColor(19); text = pt->AddText("USCMS Tier-2"); pt->Draw(); pt = new TPaveText(0.1829205,0.07716075,0.8443066,0.2357858,"br"); pt->SetFillColor(19); text = pt->AddText("WCLG (non-US) Tier-2"); pt->Draw(); c1->cd(); // Print it c1->Print(Form("%s.png",headers[ihist].Data())); } // Write list of histograms Hlist->Write(); // Now site histograms // Loop over the sites (Tier2s) for (Int_t it2=0; it2Fill(headers[ihist].Data(),cpuh[ihist][it2]); } // Default histogram blue sh[it2]->SetFillColor(4); sh[it2]->GetYaxis()->SetTitleSize(0.055); sh[it2]->GetYaxis()->SetTitleOffset(0.92); sh[it2]->GetXaxis()->SetLabelSize(0.055); sh[it2]->GetXaxis()->SetLabelFont(22); sh[it2]->GetYaxis()->SetTitleFont(22); sh[it2]->LabelsDeflate(); // Define range... h[ihist]->GetXaxis()->SetRange(0,NXRANGE); sh[it2]->LabelsOption("v","X"); sh[it2]->SetMinimum(0.0); sh[it2]->Draw(); sh[it2]->DrawCopy(); c1->cd(); // Print it c1->Print(Form("%s.png",tier2s[it2].Data())); } // Write list of histograms SHlist->Write(); // Write tree t->Write(); // Close CSV file... in.close(); printf("File ended OK\n"); printf("readWLCGAcct: %s contains %d lines\n",FileName.Data(),nlines); // Close ROOT file f->Close(); }