#include "TH1F.h" #include "TProfile.h" #include "TMath.h" #include "TF1.h" #include "TLegend.h" #include "TCanvas.h" // #include "TROOT.h" #include "TString.h" #include "TTree.h" #include "TFile.h" #include "TChain.h" #include "TStyle.h" #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; int read(const char *listname="resultlist.txt", const char *foutname="result.root") { const int debug = 3; const int kNSIZE = 1000; // max line length const int kNChan = 32; // dimensions for arrays const int kNQR = 26; const int kNVRef = 6; const int kNACurr = 5; const int kNSync = 8; // interesting file contents char cQR[kNQR]; // QR code int iChip = 0; // Chip # int iSta = 0; // test station float fVRef[kNVRef] = {0}; // Voltages [V] float fVCurr[kNACurr] = {0}; // voltage for Currents readings (V) float fACurr[kNACurr] = {0}; // Currents [(m)A] float fGain20mV[kNChan] = {0}; float fGain30mV[kNChan] = {0}; float fRT20mV[kNChan] = {0}; float fRT30mV[kNChan] = {0}; float fPed20mV[kNChan] = {0}; float fPed30mV[kNChan] = {0}; float fRms20mV[kNChan] = {0}; float fRms30mV[kNChan] = {0}; float fPedAna20mV[kNChan] = {0}; float fPedAna30mV[kNChan] = {0}; float fRmsAna20mV[kNChan] = {0}; float fRmsAna30mV[kNChan] = {0}; float fX20mVeven = 0; float fX20mVodd = 0; float fX30mVeven = 0; float fX30mVodd = 0; int iSync[kNSync] = {0}; int iDFT = 0; // int iJtag = 0; // int iMem = 0; // float fRingOsc = 0; // int i2cErr = 0; // int iErrCode = 0; // Return code for robot int iRCode = 0; // Return code for robot char filename[200]; char datetime[100]; // declare output tree char infostr[100]; TFile *f = new TFile(foutname,"RECREATE"); TTree* tree = new TTree("tree", "spreadsheet info"); tree->Branch("filename",&filename,"filename/C"); tree->Branch("datetime",&datetime,"datetime/C"); tree->Branch("cQR",&cQR,"cQR/C"); tree->Branch("iChip",&iChip,"iChip/I"); tree->Branch("iSta",&iSta,"iSta/I"); sprintf(infostr,"fVRef[%d]/F", kNVRef); tree->Branch("fVRef", fVRef, infostr); sprintf(infostr,"fVCurr[%d]/F", kNACurr); tree->Branch("fVCurr", fVCurr, infostr); sprintf(infostr,"fACurr[%d]/F", kNACurr); tree->Branch("fACurr", fACurr, infostr); sprintf(infostr,"fGain20mV[%d]/F", kNChan); tree->Branch("fGain20mV", fGain20mV, infostr); sprintf(infostr,"fGain30mV[%d]/F", kNChan); tree->Branch("fGain30mV", fGain30mV, infostr); sprintf(infostr,"fRT20mV[%d]/F", kNChan); tree->Branch("fRT20mV", fRT20mV, infostr); sprintf(infostr,"fRT30mV[%d]/F", kNChan); tree->Branch("fRT30mV", fRT30mV, infostr); sprintf(infostr,"fPed20mV[%d]/F", kNChan); tree->Branch("fPed20mV", fPed20mV, infostr); sprintf(infostr,"fPed30mV[%d]/F", kNChan); tree->Branch("fPed30mV", fPed30mV, infostr); sprintf(infostr,"fRms20mV[%d]/F", kNChan); tree->Branch("fRms20mV", fRms20mV, infostr); sprintf(infostr,"fRms30mV[%d]/F", kNChan); tree->Branch("fRms30mV", fRms30mV, infostr); sprintf(infostr,"fPedAna20mV[%d]/F", kNChan); tree->Branch("fPedAna20mV", fPedAna20mV, infostr); sprintf(infostr,"fPedAna30mV[%d]/F", kNChan); tree->Branch("fPedAna30mV", fPedAna30mV, infostr); sprintf(infostr,"fRmsAna20mV[%d]/F", kNChan); tree->Branch("fRmsAna20mV", fRmsAna20mV, infostr); sprintf(infostr,"fRmsAna30mV[%d]/F", kNChan); tree->Branch("fRmsAna30mV", fRmsAna30mV, infostr); tree->Branch("fX20mVeven",&fX20mVeven,"fX20mVeven/F"); tree->Branch("fX20mVodd",&fX20mVodd,"fX20mVodd/F"); tree->Branch("fX30mVeven",&fX30mVeven,"fX30mVeven/F"); tree->Branch("fX30mVodd",&fX30mVodd,"fX30mVodd/F"); sprintf(infostr,"iSync[%d]/I", kNSync); tree->Branch("iSync", iSync, infostr); tree->Branch("iDFT",&iDFT,"iDFT/I"); tree->Branch("iJtag",&iJtag,"iJtag/I"); tree->Branch("iMem",&iMem,"iMem/I"); tree->Branch("fRingOsc",&fRingOsc,"fRingOsc/F"); tree->Branch("i2cErr",&i2cErr,"i2cErr/I"); tree->Branch("iErrCode",&iErrCode,"iErrCode/I"); tree->Branch("iRCode",&iRCode,"iRCode/I"); // start reading the files ifstream input; input.open(listname); int nfiles = 0; while (1) { // loop over all files // while (nfiles==0) { // test input >> filename; if (! input.good()) break; nfiles++; if (debug>0) cout << " filename " << filename << endl; struct stat buffer; int result = stat(filename, &buffer); if (result != 0) { cerr << filename << ": " << strerror(errno) << endl; continue; } const struct tm* time = localtime(&buffer.st_mtime); result = strftime(datetime, 100, "%c", time); cout << filename << " : last modified " << datetime << endl; // clear all variables int j = 0; sprintf(cQR, "-"); iChip = 0; iSta = 0; for (j=0; j0) cout << " chipStr " << chipstr << endl; iChip = chipstr.Atoi(); if (debug>0) cout << " iChip " << iChip << endl; ifstream in; in.open(filename); char line[kNSIZE]; float fp = 0; int nlines = 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<1) continue; // empty line TString tsFirst( ((TObjString *)(tx->At(0)))->String() ); if (nlines<20) printf(" header %s - found %d fields\n", tsFirst.Data(), nf); if ( strcmp(tsFirst.Data(), "QR") == 0 ) { if (debug>1) cout << "QR match" << endl; if (nf>1) { TString ts( ((TObjString *)(tx->At(1)))->String() ); sprintf( cQR, "%s", ts.Data()); } } else if ( strcmp(tsFirst.Data(), "Sta") == 0 ) { if (debug>1) cout << "Sta match" << endl; if (nf>1) { TString ts( ((TObjString *)(tx->At(1)))->String() ); iSta = ts.Atoi(); } } else if ( strcmp(tsFirst.Data(), "VRef") == 0 ) { if (debug>1) cout << "VRef match" << endl; if (nf > (kNVRef+1)) { nf = kNVRef+1;} for (Int_t i = 1; i < nf; i++) { TString ts( ((TObjString *)(tx->At(i)))->String() ); //printf ("i %d ts %s\n", i, ts.Data() ); fVRef[i-1] = ts.Atof(); } } else if ( strcmp(tsFirst.Data(), "VCurr") == 0 ) { if (debug>1) cout << "VCurr match" << endl; if (nf > (kNACurr+1)) { nf = kNACurr+1;} for (Int_t i = 1; i < nf; i++) { TString ts( ((TObjString *)(tx->At(i)))->String() ); //printf ("i %d ts %s\n", i, ts.Data() ); fVCurr[i-1] = ts.Atof(); } } else if ( strcmp(tsFirst.Data(), "ACurr") == 0 ) { if (debug>1) cout << "ACurr match" << endl; if (nf > (kNACurr+1)) { nf = kNACurr+1;} for (Int_t i = 1; i < nf; i++) { TString ts( ((TObjString *)(tx->At(i)))->String() ); //printf ("i %d ts %s\n", i, ts.Data() ); fACurr[i-1] = ts.Atof(); } } else if ( strcmp(tsFirst.Data(), "RT20mV") == 0 ) { if (debug>1) cout << " RT20mV match" << endl; if (nf > (kNChan+1)) { nf = kNChan+1;} for (Int_t i = 1; i < nf; i++) { TString ts( ((TObjString *)(tx->At(i)))->String() ); //printf ("i %d ts %s\n", i, ts.Data() ); fRT20mV[i-1] = ts.Atof(); } } else if ( strcmp(tsFirst.Data(), "RT30mV") == 0 ) { if (debug>1) cout << " RT30mV match" << endl; if (nf > (kNChan+1)) { nf = kNChan+1;} for (Int_t i = 1; i < nf; i++) { TString ts( ((TObjString *)(tx->At(i)))->String() ); //printf ("i %d ts %s\n", i, ts.Data() ); fRT30mV[i-1] = ts.Atof(); } } else if ( strcmp(tsFirst.Data(), "Ped20mV") == 0 ) { if (debug>1) cout << " Ped20mV match" << endl; if (nf > (kNChan+1)) { nf = kNChan+1;} for (Int_t i = 1; i < nf; i++) { TString ts( ((TObjString *)(tx->At(i)))->String() ); //printf ("i %d ts %s\n", i, ts.Data() ); fPed20mV[i-1] = ts.Atof(); } } else if ( strcmp(tsFirst.Data(), "Ped30mV") == 0 ) { if (debug>1) cout << " Ped30mV match" << endl; if (nf > (kNChan+1)) { nf = kNChan+1;} for (Int_t i = 1; i < nf; i++) { TString ts( ((TObjString *)(tx->At(i)))->String() ); //printf ("i %d ts %s\n", i, ts.Data() ); fPed30mV[i-1] = ts.Atof(); } } else if ( strcmp(tsFirst.Data(), "Rms20mV") == 0 ) { if (debug>1) cout << " Rms20mV match" << endl; if (nf > (kNChan+1)) { nf = kNChan+1;} for (Int_t i = 1; i < nf; i++) { TString ts( ((TObjString *)(tx->At(i)))->String() ); //printf ("i %d ts %s\n", i, ts.Data() ); fRms20mV[i-1] = ts.Atof(); } } else if ( strcmp(tsFirst.Data(), "Rms30mV") == 0 ) { if (debug>1) cout << " Rms30mV match" << endl; if (nf > (kNChan+1)) { nf = kNChan+1;} for (Int_t i = 1; i < nf; i++) { TString ts( ((TObjString *)(tx->At(i)))->String() ); //printf ("i %d ts %s\n", i, ts.Data() ); fRms30mV[i-1] = ts.Atof(); } } else if ( strcmp(tsFirst.Data(), "PedAna20mV") == 0 ) { if (debug>1) cout << " PedAna20mV match" << endl; if (nf > (kNChan+1)) { nf = kNChan+1;} for (Int_t i = 1; i < nf; i++) { TString ts( ((TObjString *)(tx->At(i)))->String() ); //printf ("i %d ts %s\n", i, ts.Data() ); fPedAna20mV[i-1] = ts.Atof(); } } else if ( strcmp(tsFirst.Data(), "PedAna30mV") == 0 ) { if (debug>1) cout << " PedAna30mV match" << endl; if (nf > (kNChan+1)) { nf = kNChan+1;} for (Int_t i = 1; i < nf; i++) { TString ts( ((TObjString *)(tx->At(i)))->String() ); //printf ("i %d ts %s\n", i, ts.Data() ); fPedAna30mV[i-1] = ts.Atof(); } } else if ( strcmp(tsFirst.Data(), "RmsAna20mV") == 0 ) { if (debug>1) cout << " RmsAna20mV match" << endl; if (nf > (kNChan+1)) { nf = kNChan+1;} for (Int_t i = 1; i < nf; i++) { TString ts( ((TObjString *)(tx->At(i)))->String() ); //printf ("i %d ts %s\n", i, ts.Data() ); fRmsAna20mV[i-1] = ts.Atof(); } } else if ( strcmp(tsFirst.Data(), "RmsAna30mV") == 0 ) { if (debug>1) cout << " RmsAna30mV match" << endl; if (nf > (kNChan+1)) { nf = kNChan+1;} for (Int_t i = 1; i < nf; i++) { TString ts( ((TObjString *)(tx->At(i)))->String() ); //printf ("i %d ts %s\n", i, ts.Data() ); fRmsAna30mV[i-1] = ts.Atof(); } } else if ( strcmp(tsFirst.Data(), "Gain20mVeven") == 0 ) { if (debug>1) cout << " Gain20mVeven match" << endl; if (nf > (kNChan/2 + 1)) { nf = kNChan/2 + 1;} for (Int_t i = 1; i < nf; i++) { TString ts( ((TObjString *)(tx->At(i)))->String() ); //printf ("i %d ts %s\n", i, ts.Data() ); fGain20mV[(i-1)*2] = ts.Atof(); } } else if ( strcmp(tsFirst.Data(), "Gain30mVeven") == 0 ) { if (debug>1) cout << " Gain30mVeven match" << endl; if (nf > (kNChan/2 + 1)) { nf = kNChan/2 + 1;} for (Int_t i = 1; i < nf; i++) { TString ts( ((TObjString *)(tx->At(i)))->String() ); //printf ("i %d ts %s\n", i, ts.Data() ); fGain30mV[(i-1)*2] = ts.Atof(); } } else if ( strcmp(tsFirst.Data(), "Gain20mVodd") == 0 ) { if (debug>1) cout << " Gain20mVodd match" << endl; if (nf > (kNChan/2 + 1)) { nf = kNChan/2 + 1;} for (Int_t i = 1; i < nf; i++) { TString ts( ((TObjString *)(tx->At(i)))->String() ); //printf ("i %d ts %s\n", i, ts.Data() ); fGain20mV[(i-1)*2 + 1] = ts.Atof(); } } else if ( strcmp(tsFirst.Data(), "Gain30mVodd") == 0 ) { if (debug>1) cout << " Gain30mVodd match" << endl; if (nf > (kNChan/2 + 1)) { nf = kNChan/2 + 1;} for (Int_t i = 1; i < nf; i++) { TString ts( ((TObjString *)(tx->At(i)))->String() ); //printf ("i %d ts %s\n", i, ts.Data() ); fGain30mV[(i-1)*2 + 1] = ts.Atof(); } } else if ( strcmp(tsFirst.Data(), "X20mVeven") == 0 ) { if (debug>1) cout << "X20mVeven match" << endl; if (nf>1) { TString ts( ((TObjString *)(tx->At(1)))->String() ); fX20mVeven = ts.Atof(); } } else if ( strcmp(tsFirst.Data(), "X30mVeven") == 0 ) { if (debug>1) cout << "X30mVeven match" << endl; if (nf>1) { TString ts( ((TObjString *)(tx->At(1)))->String() ); fX30mVeven = ts.Atof(); } } else if ( strcmp(tsFirst.Data(), "X20mVodd") == 0 ) { if (debug>1) cout << "X20mVodd match" << endl; if (nf>1) { TString ts( ((TObjString *)(tx->At(1)))->String() ); fX20mVodd = ts.Atof(); } } else if ( strcmp(tsFirst.Data(), "X30mVodd") == 0 ) { if (debug>1) cout << "X30mVodd match" << endl; if (nf>1) { TString ts( ((TObjString *)(tx->At(1)))->String() ); fX30mVodd = ts.Atof(); } } // digital else if ( strcmp(tsFirst.Data(), "DFT") == 0 ) { if (debug>1) cout << "DFT match" << endl; if (nf>1) { TString ts( ((TObjString *)(tx->At(1)))->String() ); iDFT = ts.Atoi(); } } else if ( strcmp(tsFirst.Data(), "Sync") == 0 ) { if (debug>1) cout << "Sync match" << endl; if (nf > (kNSync+1)) { nf = kNSync+1;} for (Int_t i = 1; i < nf; i++) { TString ts( ((TObjString *)(tx->At(i)))->String() ); //printf ("i %d ts %s\n", i, ts.Data() ); iSync[i-1] = ts.Atoi(); } } else if ( strcmp(tsFirst.Data(), "Jtag") == 0 ) { if (debug>1) cout << "Jtag match" << endl; if (nf>1) { TString ts( ((TObjString *)(tx->At(1)))->String() ); iJtag = ts.Atoi(); } } else if ( strcmp(tsFirst.Data(), "Mem") == 0 ) { if (debug>1) cout << "Mem match" << endl; if (nf>1) { TString ts( ((TObjString *)(tx->At(1)))->String() ); iMem = ts.Atoi(); } } else if ( strcmp(tsFirst.Data(), "RingOsc") == 0 ) { if (debug>1) cout << "RingOsc match" << endl; if (nf>1) { TString ts( ((TObjString *)(tx->At(1)))->String() ); fRingOsc = ts.Atof(); } } else if ( strcmp(tsFirst.Data(), "i2cErr") == 0 ) { if (debug>1) cout << "i2cErr match" << endl; if (nf>1) { TString ts( ((TObjString *)(tx->At(1)))->String() ); i2cErr = ts.Atoi(); } } else if ( strcmp(tsFirst.Data(), "ErrCode") == 0 ) { if (debug>1) cout << "ErrCode match" << endl; if (nf>1) { TString ts( ((TObjString *)(tx->At(1)))->String() ); sscanf(ts.Data(), "%x", &iErrCode); } } else if ( strcmp(tsFirst.Data(), "RCode") == 0 ) { if (debug>1) cout << "RCode match" << endl; if (nf>1) { TString ts( ((TObjString *)(tx->At(1)))->String() ); iRCode = ts.Atoi(); } } nlines++; } printf(" found %d lines\n", nlines); in.close(); tree->Fill(); nfiles++; } printf(" found %d files\n", nfiles); f->Write(); return 0; } int main (int argc, char *argv[]) { if (argc<3) { printf("not enough arguments: argc = %d\nSyntax should be:\n./read.exe infilelist outfile\n",argc); printf("Example:\n./read.exe resultlist.txt result.root\n"); return -1; } char* infile = argv[1]; char* outfile = argv[2]; int iret = read(infile, outfile); return iret; }