/// Class to hold TPC and MM status for /// a range of times, and calculate /// live times. Uses ITPCMMStatus to /// read the values at a particular time. /// /// Blair Jamieson (C) 2010 #include "ITPCStatus.hxx" /// Initialize TPC MM status object using unix time ITPCStatus::ITPCStatus( long autimemin, long autimemax, bool verbose, bool makeplots){ fStart = autimemin; fEnd = autimemax; fVerbose = verbose; fMakePlots = makeplots; Init(); } /// Initialize TPC MM status object using year, month(0-11), /// day(1-31),... ITPCStatus::ITPCStatus( int ayearmin, int amonthmin, int adaymin, int ahourmin, int aminmin, int asecmin, int ayearmax, int amonthmax, int adaymax, int ahourmax, int aminmax, int asecmax, bool verbose, bool makeplots ){ tm mt; fVerbose = verbose; fMakePlots = makeplots; // 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; mt.tm_isdst = -1; fStart = (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; mt.tm_isdst = -1; fEnd = (long)mktime(&mt); Init(); } /// Update the livetime objects void ITPCStatus::AddUpdate( ITPCMMStatus &mmstatus, long atime, long astart_time, long aend_time ){ // guard against adding a time that is much after requested // time interval if ( aend_time > fEnd ) aend_time = fEnd+1; if ( astart_time < fStart ) astart_time = fStart-1; fStatus -> AddStatus( astart_time, aend_time, mmstatus.Status() ); for ( int itpc = 0 ; itpc < 3 ; itpc++ ){ ( fTPCStatus[itpc] ) -> AddStatus( astart_time, aend_time, mmstatus.TPCStatus( itpc ) ); for ( int irp = 0 ; irp < 2; irp++ ){ for ( int imm = 0 ; imm < 12 ; imm++ ){ ( fMMStatus [itpc] [irp] [imm] ) -> AddStatus( astart_time, aend_time, mmstatus.MMStatus( itpc, irp, imm ) ); } } } return; } /// Update the livetime objects with a number as status -> for bad gas condition void ITPCStatus::AddUpdate( long istatus, long atime, long astart_time, long aend_time ){ // guard against adding a time that is much after requested // time interval if ( aend_time > fEnd ) aend_time = fEnd+1; if ( astart_time < fStart ) astart_time = fStart-1; // fStatus -> AddStatus( astart_time, // aend_time, // istatus ); //as the istatus we have is already a flag, i.e. 2^x //we can get the x to compute the flags for each TPC int x = log(istatus)/log(2); long totalstatus =0; for ( int itpc = 0 ; itpc < 3 ; itpc++ ){ long status = (1<<(itpc+1)*8 + x); //(x+1)th status flag ( fTPCStatus[itpc] ) -> AddStatus( astart_time, aend_time, status ); for ( int irp = 0 ; irp < 2; irp++ ){ for ( int imm = 0 ; imm < 12 ; imm++ ){ ( fMMStatus [itpc] [irp] [imm] ) -> AddStatus( astart_time, aend_time, status ); } } totalstatus += status; } fStatus -> AddStatus( astart_time, aend_time, totalstatus ); return; } /// Update the livetime objects /// with a number as status (odb - dcc or fem masked conditions) + mmstatus (for rest of TPCs) void ITPCStatus::AddUpdate( long istatus, ITPCMMStatus &mmstatus, long atime, long astart_time, long aend_time ){ //for the odb info flag //first separate in TPC flags bool idTPC1=false; bool idTPC2=false; bool idTPC3=false; long auxstatus=istatus; if(auxstatus>=2147483648){ idTPC3 = true; auxstatus -=2147483648 ; } if(auxstatus>=8388608){ idTPC2 = true; auxstatus -= 8388608; } if(auxstatus==32768) idTPC1=true; long totalstatus =0; //now add statuses if(idTPC1){ ( fTPCStatus[0] ) -> AddStatus( astart_time, aend_time, 32768 ); for ( int irp = 0 ; irp < 2; irp++ ){ for ( int imm = 0 ; imm < 12 ; imm++ ){ ( fMMStatus [0] [irp] [imm] ) -> AddStatus( astart_time, aend_time, 32768 ); } } totalstatus += 32768; }else{//set undefined flag for TPCs without ODB problems in a period with ODB problems ( fTPCStatus[0] ) -> AddStatus( astart_time, aend_time, mmstatus.TPCStatus(0) ); for ( int irp = 0 ; irp < 2; irp++ ){ for ( int imm = 0 ; imm < 12 ; imm++ ){ ( fMMStatus [0] [irp] [imm] ) -> AddStatus( astart_time, aend_time, mmstatus.MMStatus( 0, irp, imm ) ); } } totalstatus += mmstatus.TPCStatus(0); } if(idTPC2){ ( fTPCStatus[1] ) -> AddStatus( astart_time, aend_time, 8388608 ); for ( int irp = 0 ; irp < 2; irp++ ){ for ( int imm = 0 ; imm < 12 ; imm++ ){ ( fMMStatus [1] [irp] [imm] ) -> AddStatus( astart_time, aend_time, 8388608 ); } } totalstatus += 8388608; }else{//set undefined flag for TPCs without ODB problems in a period with ODB problems ( fTPCStatus[1] ) -> AddStatus( astart_time, aend_time, mmstatus.TPCStatus(1) ); for ( int irp = 0 ; irp < 2; irp++ ){ for ( int imm = 0 ; imm < 12 ; imm++ ){ ( fMMStatus [1] [irp] [imm] ) -> AddStatus( astart_time, aend_time, mmstatus.MMStatus( 1, irp, imm ) ); } } totalstatus += mmstatus.TPCStatus(1); } if(idTPC3){ ( fTPCStatus[2] ) -> AddStatus( astart_time, aend_time, 2147483648 ); for ( int irp = 0 ; irp < 2; irp++ ){ for ( int imm = 0 ; imm < 12 ; imm++ ){ ( fMMStatus [2] [irp] [imm] ) -> AddStatus( astart_time, aend_time, 2147483648 ); } } totalstatus += 2147483648; }else{//set undefined flag for TPCs without ODB problems in a period with ODB problems ( fTPCStatus[2] ) -> AddStatus( astart_time, aend_time, mmstatus.TPCStatus(2) ); for ( int irp = 0 ; irp < 2; irp++ ){ for ( int imm = 0 ; imm < 12 ; imm++ ){ ( fMMStatus [2] [irp] [imm] ) -> AddStatus( astart_time, aend_time, mmstatus.MMStatus( 2, irp, imm ) ); } } totalstatus += mmstatus.TPCStatus(2); } //total status adding statuses for each TPC fStatus -> AddStatus( astart_time, aend_time, totalstatus ); return; } /// Save graph values void ITPCStatus::SaveGraphValues( ITPCGas &agas, ITPCMMStatus& mmstatus, bool lastflag ){ // fIbuMon.Add( agas.GetTime(), agas.IbuMon(), lastflag ); fVdIn.Add( agas.GetTime(), agas.VdIn(), lastflag ); fTemp.Add( agas.GetTime(), agas.TO2(), lastflag ); fPatm.Add( agas.GetTime(), agas.Patm()*1000.0, lastflag ); fDensityGS.Add( agas.GetTime(), agas.Patm()*1000.0 / ( 273.15+agas.TO2() ), lastflag ); for (int itpc=0; itpc<3; itpc++){ fCath_V[itpc].Add( mmstatus.GetTime(), mmstatus.Cathode_V(itpc ), lastflag ); fTTpc[itpc].Add( agas.GetTime(), agas.TTPC(itpc), lastflag ); fDensity[itpc].Add( agas.GetTime(), agas.Patm()*1000.0 / ( 273.15+agas.TTPC(itpc) ), lastflag ); for (int irp=0; irp<2; irp++ ){ for (int imm=0; imm<12; imm++){ fLV_I[itpc][irp][imm].Add( mmstatus.GetTime(), mmstatus.LV_I(itpc,irp,imm ), lastflag ); fFEM_V[itpc][irp][imm].Add( mmstatus.GetTime(), mmstatus.FEM_V(itpc,irp,imm ), lastflag ); fMM_HV[itpc][irp][imm].Add( mmstatus.GetTime(), mmstatus.MM_HV(itpc,irp,imm ), lastflag ); fDCC_V[itpc][irp][imm].Add( mmstatus.GetTime(), mmstatus.DCC_V(itpc,irp,imm ), lastflag ); } } } return; } /// Initialize livetime and status objects void ITPCStatus::Init(){ /// Setup Livetime objects char aname[256]; sprintf(aname,"AllTPCs"); fStatus = new ILiveTime( aname ); bool doAll = true; if (doAll==true){ for ( int itpc = 0 ; itpc < 3 ; itpc++ ){ sprintf(aname,"TPC%1d",itpc+1); fTPCStatus[itpc] = new ILiveTime( aname ); for ( int irp = 0 ; irp < 2; irp++ ){ for ( int imm = 0 ; imm < 12 ; imm++ ){ sprintf( aname,"TPC%1dRP%1dMM%02d", itpc+1, irp, imm ); fMMStatus[itpc][irp][imm] = new ILiveTime( aname ); } } } } // Build initial MMStatus at start-time ITPCMMStatus mmstatus( fStart, fStart, fEnd ); ITPCGas agas( fStart, fEnd ); ITPCODBInfo odb(fStart, fEnd); long atime= mmstatus.GetTime(); long astart_time; long aend_time; mmstatus.GetTimeInterval( astart_time, aend_time ); // Fill livetime / status information and read next set of status // until we reach end time. // also count queries int nquery = 0; bool badgas; bool odbstatus; do { if( fVerbose==true && nquery%50 == 0 ){ std::cout<<"DB Query "< BadGas t="< WriteLog( aauthor, acomment, aname); } } ( fTPCStatus[itpc] ) -> WriteLog( aauthor, acomment, aname ); } fStatus->WriteLog( aauthor, acomment, aname); return; } /// Collect all of the TGraphs, and save them to file. void ITPCStatus::SavePlotsToFile(){ char aname[256]; sprintf(aname,"ttpcstatus_%ld_to_%ld.root",fStart,fEnd); TFile fout(aname,"recreate"); TDirectory * dtpc[3]; TDirectory * dirp[3][2]; TDirectory * dstatus[3][2]; TDirectory * dlive[3][2]; TDirectory * dvalues[3][2]; fout.cd(); TGraph * tg; // save general gas plots in head sprintf(aname,"Isobutane Monitor (%)"); fIbuMon.Print(aname,false); sprintf(aname,"ibumon"); fIbuMon.MakePlot(aname,false); fIbuMon.fGraph->Write(); sprintf(aname,"Vdrift Input Gas (cm/mus)"); fVdIn.Print(aname,false); sprintf(aname,"vdin"); fVdIn.MakePlot(aname,false); fVdIn.fGraph->Write(); sprintf(aname,"Gas Shack Temperature (degC)"); fTemp.Print(aname,false); sprintf(aname,"Temperature"); fTemp.MakePlot(aname,false); fTemp.fGraph->Write(); sprintf(aname,"Atmospheric Pressure (mbar)"); fPatm.Print(aname,false); sprintf(aname,"Patm"); fPatm.MakePlot(aname,false); fPatm.fGraph->Write(); sprintf(aname,"Gas Density (mbar/K)"); fDensityGS.Print(aname,false); sprintf(aname,"gasdensity"); fDensityGS.MakePlot(aname,false); fDensityGS.fGraph->Write(); for ( int itpc = 0 ; itpc < 3 ; itpc++ ){ sprintf(aname,"TPC%1d",itpc+1); dtpc[itpc] = fout.mkdir(aname,aname); dtpc[itpc]->cd(); sprintf(aname,"Cathode V (V) for TPC%1d",itpc+1); fCath_V[itpc].Print(aname,false); sprintf(aname,"cathodevtpc%d",itpc+1); fCath_V[itpc].MakePlot(aname,false); tg = fCath_V[itpc].fGraph; tg->Write(); sprintf(aname,"TPC%1d Temperature (degC)",itpc+1); fTTpc[itpc].Print(aname,false); sprintf(aname,"TPC%1dTemperature",itpc+1); fTTpc[itpc].MakePlot(aname,false); fTTpc[itpc].fGraph->Write(); sprintf(aname,"TPC%1d Gas Density (mbar/K)",itpc+1); fDensity[itpc].Print(aname,false); sprintf(aname,"tpc%1ddensity",itpc+1); fDensity[itpc].MakePlot(aname,false); fDensity[itpc].fGraph->Write(); for ( int irp = 0 ; irp < 2; irp++ ){ sprintf(aname,"RP%1d",irp); dirp[itpc][irp] = dtpc[itpc]->mkdir(aname,aname); dirp[itpc][irp]->cd(); dstatus[itpc][irp] = dirp[itpc][irp]->mkdir("Status","Status"); dlive[itpc][irp] = dirp[itpc][irp]->mkdir("LiveFraction","Live Fractions"); dvalues[itpc][irp] = dirp[itpc][irp]->mkdir("Values","Plots on which Status is calculated"); for ( int imm = 0 ; imm < 12 ; imm++ ){ dstatus[itpc][irp]->cd(); tg = ( fMMStatus [itpc] [irp] [imm] ) -> GraphStatVsTime(); tg->Write(); dlive[itpc][irp]->cd(); tg = ( fMMStatus [itpc] [irp] [imm] ) -> GraphLiveFraction(); tg->Write(); dvalues[itpc][irp]->cd(); sprintf(aname,"LV I (A) TPC%1d RP%1d MM%02d",itpc+1,irp,imm); fLV_I[itpc][irp][imm].Print(aname,false); sprintf(aname,"lowvoltage_tpc%1d_rp%1d_mm%02d",itpc+1,irp,imm); fLV_I[itpc][irp][imm].MakePlot(aname,false); tg = fLV_I[itpc][irp][imm].fGraph; tg->Write(); sprintf(aname,"FEM V (mV) TPC%1d RP%1d MM%02d",itpc+1,irp,imm); fFEM_V[itpc][irp][imm].Print(aname,false); sprintf(aname,"femvoltage_tpc%1d_rp%1d_mm%02d",itpc+1,irp,imm); fFEM_V[itpc][irp][imm].MakePlot(aname,false); tg = fFEM_V[itpc][irp][imm].fGraph; tg->Write(); sprintf(aname,"MM HV (V) TPC%1d RP%1d MM%02d",itpc+1,irp,imm); fMM_HV[itpc][irp][imm].Print(aname,false); sprintf(aname,"mmhv_tpc%1d_rp%1d_mm%02d",itpc+1,irp,imm); fMM_HV[itpc][irp][imm].MakePlot(aname,false); tg = fMM_HV[itpc][irp][imm].fGraph; tg->Write(); sprintf(aname,"DCC V (V) TPC%1d RP%1d MM%02d",itpc+1,irp,imm); fDCC_V[itpc][irp][imm].Print(aname,false); sprintf(aname,"dccv_tpc%1d_rp%1d_mm%02d",itpc+1,irp,imm); fDCC_V[itpc][irp][imm].MakePlot(aname,false); tg = fDCC_V[itpc][irp][imm].fGraph; tg->Write(); } } dtpc[itpc]->cd(); tg = ( fTPCStatus[itpc] ) -> GraphStatVsTime(); tg->Write(); tg = ( fTPCStatus[itpc] ) -> GraphLiveFraction(); tg->Write(); } fout.cd(); tg = fStatus->GraphStatVsTime(); tg->Write(); tg = fStatus->GraphLiveFraction(); tg->Write(); fout.Write(); fout.Close(); return; }