#include "TFile.h" #include "stdio.h" #include "string.h" #include #include #define LINES_TO_READ 36900 void FastRootMaker2Modules(){ // TNtuple* t1 = new TNtuple("t1","test","Timestamp:V_T0:V_T1:V_T2:V_T3:V_T4:V_T5:V_T6:V_T7:Colon:V_S0:V_S1:V_S2:V_S3:V_S4:V_s5:V_S6:V_S7"); // t1->ReadFile("MPOD_Monitor_Day1.txt"); // TFile *f = new TFile("Day1.root","RECREATE"); // t1->Write(); int h=0,endofchannelflag=0; char timestamp[8]; char CharVoltage_Sense[8],CharVoltage_Terminal[8],CharVoltage_Keithley[11],charTimestampTerm[18],charTimestampSense[18],charTimestampKeith[18],charTotalTime[9],charSNMPTime[8],charKeithTime[8],charTimestampTimeFile[18]; double Voltage_Sense,Voltage_Terminal,Voltage_Keithley=0,KeithTime,SNMPTime,TotalTime,TimestampTerm,TimestampSense,TimestampKeith,TimestampTimeFile; char dummy; char header[77]; int MismatchFlagT=0,MismatchFlagS=0,MismatchFlagK=0; int line=0; FILE *term0 = fopen("./temp_Term0MT","r"); FILE *term1 = fopen("./temp_Term1MT","r"); FILE *keith = fopen("./temp_KeithMT","r"); FILE *timeFile = fopen("./temp_TimeMT","r"); TFile *fout = new TFile("./1Module2Measurements.root","RECREATE"); TTree *tree = new TTree("Tree","MPOD Stability Data"); tree->Branch("EventNumber",&line,"EventNumber/I"); tree->Branch("V_T0",&Voltage_Terminal,"V_T0/D"); tree->Branch("V_T1",&Voltage_Sense,"V_T1/D"); tree->Branch("V_K",&Voltage_Keithley,"V_K/D"); tree->Branch("KeithTime",&KeithTime,"KeithTime/D"); tree->Branch("SNMPTime",&SNMPTime,"SNMPTime/D"); tree->Branch("TotalTime",&TotalTime,"TotalTime/D"); tree->Branch("Timestamp",&TimestampTimeFile,"Timestamp/D"); // t[h]->Fill(Voltage_Terminal,Voltage_Sense,Voltage_Keithley,line,KeithTime,SNMPTime,TotalTime,TimestampTimeFile); while (line=2 && atoi(&dummy)!=6) cerr << "Mismatch2t!" << line << " " << h << dummy << endl; fread(&dummy,1,1,term0); //Check second digit is right if (atoi(&dummy)!=((h+8)%10)) MismatchFlagT=1; fread(CharVoltage_Terminal,1,8,term0); Voltage_Terminal = strtod(CharVoltage_Terminal,NULL); if (MismatchFlagT==1) Voltage_Terminal=Voltage_Terminal-1.0000000; MismatchFlagT=0; //Read Sense fread(&dummy,1,1,term1); //Check first digit is right if (h<2 && atoi(&dummy)!=5) cerr << "Mismatch1s!" << line << " " << h << endl; if (h>=2 && atoi(&dummy)!=6) cerr << "Mismatch1s!"<< line << " " << h << endl; fread(&dummy,1,1,term1); //Check second digit is right if (atoi(&dummy)!=((h+9)%10)) MismatchFlagS=1; fread(CharVoltage_Sense,1,8,term1); Voltage_Sense = strtod(CharVoltage_Sense,NULL); if (MismatchFlagS==1) Voltage_Sense=Voltage_Sense-1.0000000; MismatchFlagS=0; //Read Keithley if(line%86400==1&&line>1) endofchannelflag=0; if(endofchannelflag==0){ fread(&dummy,1,1,keith); if (dummy=='E') { fread(&dummy,1,1,keith); if(dummy=='n') { for(int y=0;y<8;y++) {fread(&dummy,1,1,keith);} } if (dummy!='a') cerr << "Failed to read end of channel properly" << endl; endofchannelflag=1; Voltage_Keithley=-10; } } if(endofchannelflag==0){ fread(&dummy,1,1,keith); //Check first digit is right if (h<2 && atoi(&dummy)!=5 && dummy!='9') cerr << "Mismatch1k!" << dummy << endl; if (h>=2 && atoi(&dummy)!=6 && dummy!='9') cerr << "Mismatch1k!" << endl; fread(&dummy,1,1,keith); if (dummy=='+') {for (int y=0;y<2;y++) {fread(&dummy,1,1,keith);}} if (dummy!='.') cerr << "Period not in right place" << dummy << line << endl; fread(&dummy,1,1,keith); //Check second digit is right if (atoi(&dummy)!=((h+9)%10)) MismatchFlagK=1; if (dummy=='6') MismatchFlagK=0; //cout << dummy << endl; fread(&CharVoltage_Keithley,1,11,keith); //Read the number Voltage_Keithley=strtod(CharVoltage_Keithley,NULL); Voltage_Keithley=Voltage_Keithley*pow(10,-8); if (MismatchFlagK==1) Voltage_Keithley = Voltage_Keithley-1.0000000; MismatchFlagK=0; // fread(&dummy,1,1,keith); //Ignore the + // fread(&dummy,1,1,keith); //Check first number in exponent // if (atoi(&dummy)!=0) cerr << "Exponent1 Wrong!" << endl; // fread(&dummy,1,1,keith); //Check second number in exponent //if (dummy!='1') cerr << "Exponent2 Wrong!" << dummy << line << endl; fread(&dummy,1,1,keith); //Get the space and /n //while (dummy!='\n'){ //fread(&dummy,1,1,keith); //} //Read Timestamp for (int j=0;j<12;j++){ fread(&dummy,1,1,timeFile); //cout << dummy; } fread(&charTimestampTimeFile,1,14,timeFile); TimestampTimeFile = strtod(charTimestampTimeFile,NULL); //Read KeithTime for (int j=0;j<6;j++) { fread(&dummy,1,1,timeFile); } fread(&dummy,1,1,timeFile); if (dummy=='-') fread(&dummy,1,1,timeFile); fread(&charKeithTime,1,8,timeFile); KeithTime = strtod(charKeithTime,NULL); //Read SNMPTime for (int j=0;j<5;j++) { fread(&dummy,1,1,timeFile); } fread(&charSNMPTime,1,8,timeFile); fread(&dummy,1,1,timeFile); if (dummy=='-') fread(&dummy,1,1,timeFile); SNMPTime = strtod(charSNMPTime,NULL); //Read TotalTime for (int j=0;j<6;j++) { fread(&dummy,1,1,timeFile); //cout << dummy; } //cout << endl; fread(&charTotalTime,1,9,timeFile); TotalTime = strtod(charTotalTime,NULL); if (TotalTime>10) cout << "High Time " << line << "Time" << TotalTime << charTotalTime << endl; } tree->Fill(); //} line++; } tree->Write(); fout->Close(); fclose(term0); fclose(term1); fclose(keith); fclose(timeFile); }