#include "TH1F.h" #include "TProfile.h" #include "TMath.h" #include "TF1.h" #include "TLegend.h" #include "TCanvas.h" // #include "TTree.h" #include "TFile.h" #include "TChain.h" #include "TStyle.h" #include #include #include #include #include #include void read(const char *filename="protocol_padded.csv", const char *foutname="protocol.root") { const int kNSIZE = 1000; // // const int kNFIELD = 82; // 0..81 const int kNFIELD = 17; // 0..16; skip ped fields const int kNChan = 32; ifstream in; in.open(filename); // interesting file contents // *_padded files char version[50]; // field 0 char location[50]; // field 1 int iChip = 0; // 2 float fAC = 0; // 3 float fDC = 0; // 4 int iV770 = 0; // 5 int iV450 = 0; // 6 int iV620 = 0; // 7 int iRef = 0; // 8 int iSync = 0; // 9 int iJtag = 0; // 10 int iMem = 0; // 11 int iClk = 0; // 12 int iPlot = 0; // 13 char comment[50]; // field 14 int iDFT = 0; // 15 int iPed = 0; // 16 float fPed[kNChan]; // 17..48; 49 is a blank field float fPed2[kNChan]; // 50..81 // counters Int_t nlines = 0; Int_t nchips = 0; char infostr[100]; TFile *f = new TFile(foutname,"RECREATE"); TTree* tree = new TTree("tree", "spreadsheet info"); tree->Branch("version",&version,"version/C"); tree->Branch("location",&location,"location/C"); tree->Branch("comment",&comment,"comment/C"); tree->Branch("iChip",&iChip,"iChip/I"); tree->Branch("fAC",&fAC,"fAC/F"); tree->Branch("fDC",&fDC,"fDC/F"); tree->Branch("iV770",&iV770,"iV770/I"); tree->Branch("iV450",&iV450,"iV450/I"); tree->Branch("iV620",&iV620,"iV620/I"); tree->Branch("iRef",&iRef,"iRef/I"); tree->Branch("iSync",&iSync,"iSync/I"); tree->Branch("iJtag",&iJtag,"iJtag/I"); tree->Branch("iMem",&iMem,"iMem/I"); tree->Branch("iClk",&iClk,"iClk/I"); tree->Branch("iPlot",&iPlot,"iPlot/I"); tree->Branch("iDFT",&iDFT,"iDFT/I"); tree->Branch("iPed",&iPed,"iPed/I"); sprintf(infostr,"fPed[%d]/F", kNChan); tree->Branch("fPed", fPed, infostr); sprintf(infostr,"fPed2[%d]/F", kNChan); tree->Branch("fPed2", fPed2, infostr); char line[kNSIZE]; float fp = 0; // while (nlines<20) { // test while (1) { // all in.getline(line, kNSIZE); if (!in.good()) break; if (nlines<20) cout << " line " << nlines << " : " << line << endl; TString x(line); TObjArray *tx = x.Tokenize(","); int nf = tx->GetEntries(); if (nf>kNFIELD) nf=kNFIELD; for (Int_t i = 0; i < nf; i++) { TString ts( ((TObjString *)(tx->At(i)))->String() ); //printf ("i %d ts %s\n", i, ts.Data() ); if (i==0) sprintf(version, "%s", ts.Data() ); else if (i==1) sprintf(location, "%s", ts.Data() ); else if (i==2) iChip = ts.Atoi(); else if (i==3) fAC = ts.Atof(); else if (i==4) fDC = ts.Atof(); else if (i==5) iV770 = ts.Atoi(); else if (i==6) iV450 = ts.Atoi(); else if (i==7) iV620 = ts.Atoi(); else if (i==8) iRef = ts.Atoi(); else if (i==9) iSync = ts.Atoi(); else if (i==10) iJtag = ts.Atoi(); else if (i==11) iMem = ts.Atoi(); else if (i==12) iClk = ts.Atoi(); else if (i==13) iPlot = ts.Atoi(); else if (i==14) sprintf(comment, "%s", ts.Data() ); else if (i==15) iDFT = ts.Atoi(); else if (i==16) iPed = ts.Atoi(); else { // ped arrays fp = ts.Atof(); if (i>=17 && i<=48) fPed[i-17] = fp; else if (i>=50 && i<=81) fPed2[i-50] = fp; } } //if (nlines<20) printf(" found %d fields\n", nf); tree->Fill(); nlines++; } printf(" found %d lines\n",nlines); in.close(); f->Write(); }