#include "TH1F.h" #include "TProfile.h" #include "TMath.h" #include "TF1.h" #include "TLegend.h" #include "TCanvas.h" // #include "TROOT.h" //#include "TStyle.h" #include "TTree.h" #include "TFile.h" #include "TGraphErrors.h" #include "TStyle.h" #include #include #include #include #include #include // using namespace std; // for normal running: /* const int debug = 0; */ // for debug running: const int debug = 1; //DS test const int kNChan = 32; const int kMaxLineLength = kNChan * 6; // max 4 digits + 1 space per channel + 1 extra for margin int analyse_file(const int iChip, const char *infile, const char *outfile, const char *config) { gStyle->SetOptStat(0); gStyle->SetOptFit(0111); gStyle->SetStatX(0.5); FILE* fout = fopen(outfile, "w"); fprintf(fout, "Ch Min Max\n"); ifstream inADC; inADC.open(infile); cout << " reading file " << infile << endl; cout << " writing file " << outfile << endl; // counter stuff int ichan = 0; int minChan[32]; int maxChan[32]; for (ichan=0; ichan<32; ichan++) { minChan[ichan] = 1024; maxChan[ichan] = -1; } int nlines = 0; // over whole file // sample loop, inside block of interesting values, between zeros int nsamples = 0; char line[kMaxLineLength]; while ( inADC.good() ) { inADC.getline(line, kMaxLineLength); if (! inADC.good()) break; nlines++; // split line into the expected 32 pieces int ns = 0; int sample = 0; char * pch; pch = strtok (line," "); while (pch != NULL) { // printf ("ns %d pch %s\n",ns, pch); sample = atoi(pch); if (ns<32) { // hSample[ns]->Fill(sample); if (minChan[ns] > sample) minChan[ns] = sample; if (maxChan[ns] < sample) maxChan[ns] = sample; } pch = strtok (NULL, " "); ns++; } if (debug>2) { cout << "nlines " << nlines << " ns " << ns << endl; } } // inADC for (ichan=0; ichan<32; ichan++) { fprintf(fout, "%2d %4d %4d\n", ichan, minChan[ichan], maxChan[ichan] ); } fclose(fout); return 0; } int main (int argc, char *argv[]) { if (argc<4) { printf("not enough arguments: argc = %d\nSyntax should be:\n./bitcheck.exe chipstring config adcfilename\n",argc); printf("Example:\n./bitcheck.exe 171741 20mV_delay-all /home/tpc/robot/20180911/091954_sta2_sampa171471/091954_sta2_sampa171471_trorc00_link02_20mV_delay-all_adc.txt\n",argc); return -1; } int iChip = atoi(argv[1]); char* infile = argv[3]; // find dirname (last /) string str(infile); size_t found; found=str.find_last_of("/"); char* outfile = Form("%s/bitcheck_sampa%s_%s.log", str.substr(0,found).c_str(), argv[1], argv[2]); int iret = analyse_file(iChip, infile, outfile, argv[2]); return iret; }