#include "ITPCGasSmooth.hxx" ITPCGasSmooth::ITPCGasSmooth( long autmin, long autmax, int dtaverage ){ fTimeMin = autmin; fTimeMax = autmax; fDtAvg = dtaverage; Init(); } ITPCGasSmooth::ITPCGasSmooth( int ayearmin, int amonthmin, int adaymin, int ahourmin, int aminmin, int asecmin, int ayearmax, int amonthmax, int adaymax, int ahourmax, int aminmax, int asecmax, int dtaverage ){ fDtAvg = dtaverage; tm mt; // use time structure from time.h // to build unix time from year,month, etc. mt.tm_year = ayearmin - 1900; mt.tm_mon = amonthmin-1; mt.tm_mday = adaymin; mt.tm_hour = ahourmin; mt.tm_min = aminmin; mt.tm_sec = asecmin; fTimeMin = (long)mktime(&mt); mt.tm_year = ayearmax - 1900; mt.tm_mon = amonthmax-1; mt.tm_mday = adaymax; mt.tm_hour = ahourmax; mt.tm_min = aminmax; mt.tm_sec = asecmax; fTimeMax = (long)mktime(&mt); Init(); } /// Add to average and rms objects void ITPCGasSmooth::AddUpdate( ITPCGas &agas, bool lastflag ){ // add a new entry? long atime = agas.GetTime(); if ( atime < fTimeMax+long(fDtAvg/2) && atime > fTimeMin-long(fDtAvg) ){ fTimes.push_back( atime+long(fDtAvg/2) ); fTAvg.push_back( IAvgRMSPlot() ); fPAvg.push_back( IAvgRMSPlot() ); fDensAvg.push_back( IAvgRMSPlot() ); fH2OAvg.push_back( IAvgRMSPlot() ); fO2Avg.push_back( IAvgRMSPlot() ); fIbuMonAvg.push_back( IAvgRMSPlot() ); fCO2Avg.push_back( IAvgRMSPlot() ); fCF4Avg.push_back( IAvgRMSPlot() ); fVdInAvg.push_back( IAvgRMSPlot() ); fVdOutAvg.push_back( IAvgRMSPlot() ); fGainInAvg.push_back( IAvgRMSPlot() ); fGainOutAvg.push_back( IAvgRMSPlot() ); fArFracAvg.push_back( IAvgRMSPlot() ); fCF4FracAvg.push_back( IAvgRMSPlot() ); fIbuFracAvg.push_back( IAvgRMSPlot() ); } // loop over entries, and add to averages unsigned int istart=fCurIdx; for ( unsigned int i=istart; i< fTimes.size(); i++ ){ bool lastavg=lastflag; long aendtime = fTimes[i]+long(fDtAvg/2); if ( atime > aendtime ){ lastavg = true; fCurIdx++; } fPAvg [i].Add( atime, agas.Patm()*1000.0, lastavg ); fTAvg [i].Add( atime, agas.TO2(), lastavg ); fDensAvg [i].Add( atime, agas.Patm()*1000.0 / (273.15+agas.TO2()) , lastavg ); fH2OAvg [i].Add( atime, agas.H2O(), lastavg ); fO2Avg [i].Add( atime, agas.O2(), lastavg ); fIbuMonAvg [i].Add( atime, agas.IbuMon(), lastavg ); fCO2Avg [i].Add( atime, agas.CO2An(), lastavg ); fCF4Avg [i].Add( atime, agas.CF4An(), lastavg ); fVdInAvg [i].Add( atime, agas.VdIn(), lastavg ); fVdOutAvg [i].Add( atime, agas.VdOut(), lastavg ); fGainInAvg [i].Add( atime, agas.GainIn(), lastavg ); fGainOutAvg[i].Add( atime, agas.GainOut(), lastavg ); float asum = agas.ArFlow() + agas.CF4Flow() + agas.IbuFlow(); fArFracAvg [i].Add( atime, agas.ArFlow()/asum, lastavg ); fCF4FracAvg[i].Add( atime, agas.CF4Flow()/asum, lastavg ); fIbuFracAvg[i].Add( atime, agas.IbuFlow()/asum, lastavg ); } return; } /// Initialize gas density object void ITPCGasSmooth::Init(){ fCurIdx=0; //long atime = fTimeMin-long(fDtAvg+fDtAvg/2); ITPCGas aGas( fTimeMin-long(2*fDtAvg), fTimeMax+long(2*fDtAvg) ); long astart_time; long aend_time; aGas.GetTimeInterval( astart_time, aend_time ); int nquery = 0; do { if (nquery%100 == 0 ){ std::cout<<"DB Query"<Write(); fT .fGraph->Write(); fDens .fGraph->Write(); fH2O .fGraph->Write(); fO2 .fGraph->Write(); fIbuMon .fGraph->Write(); fCO2 .fGraph->Write(); fCF4 .fGraph->Write(); fVdIn .fGraph->Write(); fVdOut .fGraph->Write(); fGainIn .fGraph->Write(); fGainOut.fGraph->Write(); fArFrac .fGraph->Write(); fCF4Frac.fGraph->Write(); fIbuFrac.fGraph->Write(); fP .fHist->Write(); fT .fHist->Write(); fDens .fHist->Write(); fH2O .fHist->Write(); fO2 .fHist->Write(); fIbuMon .fHist->Write(); fCO2 .fHist->Write(); fCF4 .fHist->Write(); fVdIn .fHist->Write(); fVdOut .fHist->Write(); fGainIn .fHist->Write(); fGainOut.fHist->Write(); fArFrac .fHist->Write(); fCF4Frac.fHist->Write(); fIbuFrac.fHist->Write(); fout.Close(); return; }