/// Class to hold TFB status for /// a range of times, and calculate /// live times. Uses IECALStatus to /// read the values at a particular time. /// /// Blair Jamieson (C) 2010 /// Roberto Sacco (C) 2011 #include "IECALStatus.hxx" #define nrmm 12 /// Initialize ECAL TFB status object using unix time IECALStatus::IECALStatus( long autimemin, long autimemax, bool verbose, bool makeplots){ fStart = autimemin; fEnd = autimemax; fVerbose = verbose; // fMakePlots = makeplots; fMakePlots = true; // nrmm = 2; ntfb[0] = 28; ntfb[1] = 28; ntfb[2] = 15; ntfb[3] = 44; ntfb[4] = 44; ntfb[5] = 26; ntfb[6] = 26; ntfb[7] = 15; ntfb[8] = 26; ntfb[9] = 26; ntfb[10] = 44; ntfb[11] = 44; Init(); } /// Initialize ECAL TFB status object using year, month(0-11), /// day(1-31),... IECALStatus::IECALStatus( 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; fMakePlots = true; // 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); // nrmm = 2; ntfb[0] = 28; ntfb[1] = 28; ntfb[2] = 15; ntfb[3] = 44; ntfb[4] = 44; ntfb[5] = 26; ntfb[6] = 26; ntfb[7] = 15; ntfb[8] = 26; ntfb[9] = 26; ntfb[10] = 44; ntfb[11] = 44; Init(); } /// Update the livetime objects void IECALStatus::AddUpdate( IECALTFBStatus &tfbstatus, 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, tfbstatus.Status() ); for ( int irmm = 0 ; irmm < nrmm ; irmm++ ){ ( fECALStatus[irmm] ) -> AddStatus( astart_time, aend_time, tfbstatus.ECALStatus( irmm ) ); for ( int itfb = 0 ; itfb < ntfb[irmm]; itfb++ ){ ( fTFBStatus [irmm] [itfb] ) -> AddStatus( astart_time, aend_time, tfbstatus.TFBStatus( irmm, itfb ) ); } } //end for irmm =0 return; } /// Update the livetime objects void IECALStatus::AddUpdate( int 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 ); for ( int irmm = 0 ; irmm < nrmm ; irmm++ ){ ( fECALStatus[irmm] ) -> AddStatus( astart_time, aend_time, istatus ); for ( int itfb = 0 ;itfb AddStatus( astart_time, aend_time, istatus ); } //end for itfb(0) = 0 } //end for irmm(0)=0 return; } /// Save graph values void IECALStatus::SaveGraphValues( IECALTFBStatus& tfbstatus, bool lastflag ){ // for (int irmm=0; irmm WriteLog( aauthor, acomment, aname); } ( fECALStatus[irmm] ) -> WriteLog( aauthor, acomment, aname ); } fStatus->WriteLog( aauthor, acomment, aname); return; } /// Collect all of the TGraphs, and save them to file. void IECALStatus::SavePlotsToFile(){ char aname[256]; sprintf(aname,"tecalstatus_%ld_to_%ld.root",fStart,fEnd); TFile fout(aname,"recreate"); TDirectory * drmm[12]; TDirectory * dtfb[12][44]; TDirectory * dstatus[12][44]; TDirectory * dlive[12][44]; TDirectory * dvalues[12][44]; fout.cd(); TGraph * tg; for ( int irmm = 0 ; irmm < nrmm ; irmm++ ){ sprintf(aname,"RMM%1d",irmm); drmm[irmm] = fout.mkdir(aname,aname); drmm[irmm]->cd(); for ( int itfb = 0 ; itfb < ntfb[irmm]; itfb++ ){ sprintf(aname,"TFB%1d",itfb); dtfb[irmm][itfb] = drmm[irmm]->mkdir(aname,aname); dtfb[irmm][itfb]->cd(); dstatus[irmm][itfb] = dtfb[irmm][itfb]->mkdir("Status","Status"); dlive[irmm][itfb] = dtfb[irmm][itfb]->mkdir("LiveFraction","Live Fractions"); dvalues[irmm][itfb] = dtfb[irmm][itfb]->mkdir("Values","Plots on which Status is calculated"); // for ( int imm = 0 ; imm < 12 ; imm++ ){ dstatus[irmm][itfb]->cd(); tg = ( fTFBStatus [irmm] [itfb] ) -> GraphStatVsTime(); tg->Write(); dlive[irmm][itfb]->cd(); tg = ( fTFBStatus [irmm] [itfb] ) -> GraphLiveFraction(); tg->Write(); dvalues[irmm][itfb]->cd(); sprintf(aname,"External Temp (C) RMM%1d TFB%1d",irmm,itfb); fTempexternal[irmm][itfb].Print(aname,false); sprintf(aname,"tempexternal_rmm%1d_tfb%1d",irmm,itfb); fTempexternal[irmm][itfb].MakePlot(aname,false); tg = fTempexternal[irmm][itfb].fGraph; tg->Write(); /* make things simple for now... dvalues[irmm][itfb]->cd(); sprintf(aname,"LV I (A) RMM%1d TFB%1d",irmm,itfb); fLV_I[irmm][itfb].Print(aname,false); sprintf(aname,"lowvoltage_rmm%1d_tfb%1d",irmm,itfb); fLV_I[irmm][itfb][imm].MakePlot(aname,false); tg = fLV_I[irmm][itfb].fGraph; tg->Write(); sprintf(aname,"FEM V (mV) RMM%1d TFB%1d",irmm,itfb); fFEM_V[irmm][itfb].Print(aname,false); sprintf(aname,"femvoltage_rmm%1d_tfb%1d",irmm,itfb); fFEM_V[irmm][itfb].MakePlot(aname,false); tg = fFEM_V[irmm][itfb].fGraph; tg->Write(); sprintf(aname,"MM HV (V) RMM%1d TFB%1d",irmm,itfb); fMM_HV[irmm][itfb].Print(aname,false); sprintf(aname,"mmhv_rmm%1d_tfb%1d",irmm,itfb); fMM_HV[irmm][itfb].MakePlot(aname,false); tg = fMM_HV[irmm][itfb].fGraph; tg->Write(); sprintf(aname,"DCC V (V) RMM%1d TFB%1d",irmm,itfb); fDCC_V[irmm][itfb].Print(aname,false); sprintf(aname,"dccv_rmm%1d_tfb%1d",irmm,itfb); fDCC_V[irmm][itfb].MakePlot(aname,false); tg = fDCC_V[irmm][itfb].fGraph; tg->Write(); */ // } } drmm[irmm]->cd(); tg = ( fECALStatus[irmm] ) -> GraphStatVsTime(); tg->Write(); tg = ( fECALStatus[irmm] ) -> GraphLiveFraction(); tg->Write(); } fout.cd(); tg = fStatus->GraphStatVsTime(); tg->Write(); tg = fStatus->GraphLiveFraction(); tg->Write(); fout.Write(); fout.Close(); return; }