/// Class to hold MM HV Spark Properties inside TPC /// at a particular time /// Blair Jamieson (C) 2009, 2010 #include #include #include "ITPCMMSpark.hxx" ///-------------------------------------------------------------------- /// build new TTPC MM HV Spark reading with intended time range of use specified ITPCMMSpark::ITPCMMSpark( long autimemin, long autimemax ){ fTime = autimemin; fStartTime = autimemin; fEndTime = autimemax; fTimeStamp = 0x0; Init(); } ///-------------------------------------------------------------------- /// build new TTPC MM HV Spark reading with intended time range of use specified ITPCMMSpark::ITPCMMSpark( int ayearmin, int amonthmin, int adaymin, int ahourmin, int aminmin, int asecmin, int ayearmax, int amonthmax, int adaymax, int ahourmax, int aminmax, int asecmax ){ fTimeStamp=0x0; SetTimeNoRead(ayearmax, amonthmax, adaymax, ahourmax, aminmax, asecmax); fEndTime = fTime; SetTimeNoRead(ayearmin, amonthmin, adaymin, ahourmin, aminmin, asecmin); fStartTime = fTime; Init(); } /// Initialize MM HV spark properties object void ITPCMMSpark::Init(){ // set up the field names SetupFieldNames(); fSparks_vec.clear(); // Now read MM HV spark properties Read(); } ///-------------------------------------------------------------------- /// Setup vectors of strings for field names /// that will be querried in the database void ITPCMMSpark::SetupFieldNames(){ fSparks_names.clear(); char aname[32]; for (int itpc=0; itpc<3; itpc++){ for (int irp=0; irp<2; irp++){ for ( int imm=0; imm<12; imm++){ sprintf(aname,"tpc%d_rp%d_mm%02d_sparkcount",itpc+1,irp,imm); fSparks_names.push_back( std::string(aname) ); } } } return; } ///------------------------------------------------------------------------ /// Read another chunk of data from slow control database void ITPCMMSpark::ReadSlowDB(){ /// read next 500 entries starting from 5 minutes ago long astart = fTime - 300; fSparks_vec.clear(); fSparks_vec = ISlowControlDatabase::Get().QueryGetFieldNoCache( astart, "tpciseghv02_sparkcount", fSparks_names, 500 ); return; } ///-------------------------------------------------------------------- /// Print out the values for the current time void ITPCMMSpark::Print(){ std::cout<<" Record for "< fSparks_idx[0][0][0]+2 ){ start_time = (long) fSparks_vec[ fSparks_idx[0][0][0] ].first; end_time = (long) fSparks_vec[ fSparks_idx[0][0][0]+1 ].first; } else if ( fSparks_vec.size() < 2 ){ end_time = fEndTime+1; } return; } ///-------------------------------------------------------------------- /// Get unix time long ITPCMMSpark::GetUnixTime( int ayear, int amonth, int aday, int ahour, int amin, int asec){ tm mt; // use time structure from time.h // to build unix time from year,month, etc. mt.tm_year = ayear - 1900; mt.tm_mon = amonth-1; mt.tm_mday = aday; mt.tm_hour = ahour; mt.tm_min = amin; mt.tm_sec = asec; mt.tm_isdst = -1; return (long)mktime(&mt); } ///-------------------------------------------------------------------- /// Set the time for this object void ITPCMMSpark::SetTimeNoRead( int ayear, int amonth, int aday, int ahour, int amin, int asec){ fTime = (int)GetUnixTime(ayear, amonth, aday, ahour, amin, asec ); //std::cout<<"SetTimeNoRead "< "< long( fSparks_vec[ fSparks_vec.size()-2 ].first ) ){ //std::cout<<" About to ReadSlowDB_Plca"< fEnd){ amult = 1; fTime = fTime + adeltat; } else { if ( fEnd+1 <= fTime ){ // handle case where no readings for a while amult*=2; fTime += amult; } else { amult = 1; fTime = fEnd+1; } } Read(); return 1; }