/// Class to hold TPC MM status for /// a particular time. The class /// holds information to indicate whether: /// Low Voltages are on /// FEMs are Powered /// MM HV > 245V /// DCC Power on /// Cathode HV 24950 to 25050 V /// Blair Jamieson (C) 2010 #ifndef TTPCMMStatus_hxx__ #define TTPCMMStatus_hxx__ #include #include #include #include #include //#include #include "ISlowControlDatabase.hxx" #include "ITPCGas.hxx" class ITPCMMStatus { public: /// Initialize TPC MM status object using unix time /// If it is intended to use this class to read many /// sequential values, set ancache to some value large /// enough to reduce the number of sql queries ITPCMMStatus( long autime = 1224118800, long atstart= 1224118800, long atend = 1224118800); /// Initialize TPC MM status object using year, month(0-11), /// day(1-31),... ITPCMMStatus( int ayear, int amonth, int aday, int ahour, int amin, int asec=0, long atstart=0, long atend=0); /// Destructor does nothing... may leave a histogram /// floating around ~ITPCMMStatus(){}; /// Get time interval this record is valid for void GetTimeInterval(long &start_time, long &end_time); /// Get unix time for this temperature reading long GetTime(){ return fTime; } /// Get time for this reading as year, month(0-11), day(1-31),... void GetTime( int &ayear, int &amonth, int &aday, int &ahour, int &amin, int &asec); /// Set the unix time for this object, and read MM properties closest /// to this time from database void SetTime( long autime ){ fTime=autime; Read(); } /// Get unix time long GetUnixTime( int ayear, int amonth, int aday, int ahour, int amin, int asec=0); /// Set the time for this object void SetTimeNoRead( int ayear, int amonth, int aday, int ahour, int amin, int asec=0 ); /// Set the time for this object and read MM status properties void SetTime( int ayear, int amonth, int aday, int ahour, int amin, int asec=0 ){ SetTimeNoRead(ayear, amonth, aday, ahour, amin, asec); ReadNext(); } /// Read (increment time) and update all /// object gas property readings. Argument passed is the minimum /// time increment to use (default 120 seconds) int ReadNext(int adeltat=120); /// Return timestamp char * GetTimeStamp(){ return fTimeStamp; } /// Print variables to screen void Print(); /// Set Debug output flag void SetDebug( bool aOnOff = true ){ fDebug = aOnOff; } // Access methods // itpc is 0-2 // irp is 0-1 // imm is 0-11 float LV_I (int itpc, int irp, int imm){ return fLV_I[itpc][irp][imm]; } ///< Low voltage I(A) for given MM float FEM_V (int itpc, int irp, int imm){ return fFEM_V[itpc][irp][imm]; } ///< FEM V(V) for given MM float MM_HV (int itpc, int irp, int imm){ return fMM_HV[itpc][irp][imm]; } ///< MM HV(V) for given MM float DCC_V (int itpc, int irp, int imm){ return fDCC_V[itpc][irp][imm]; } ///< DCC (V) for given MM float Cathode_V(int itpc ) { return fCath_V[itpc]; } ///< Cathode HV (V) for a given TPC long MMStatus (int itpc, int irp, int imm){ return fMMStatus[itpc][irp][imm]; } ///< Status for given MM = 0 for good long TPCStatus(int itpc ) { return fTPCStatus[itpc]; } ///< Status for given TPC = 0 for good long Status () { return fStatus; } ///< Status for All TPC = 0 for good private: long fTime; ///< Unix time for get methods long fStart; ///< start of validity range long fEnd; ///< end of validity range long fStartTime; ///< used to keep track of ultimate time range that may be queried long fEndTime; ///< used to keep track of ultimate time range that may be queried char * fTimeStamp; ///< local time as character array (for titles) long fTimeSwap1; ///< approximate time of swap1 MMHV channel TPC3RP0MM01 to XSp_TPC3_RP0_13 long fTimeSwap2; ///< approximate time of swap2 MMHV channel TPC3RP0MM01 to nominal // variables to monitor status of MM //ITPCGas * fGas; ///< use to check if gas is okay /// LV power for groups of 6 MM /// Tables: tpc_lv_ps_tlv0, and tpc_lv_ps_tlv1 /// Variables: c0m0_umeas, c0m0_imeas, ... /// index is [TPC][RP][MM] (groups of six will be off/on) /// V should be >4550V /// I should be > 38 A float fLV_I[3][2][12]; float fLV_I_next[3][2][12]; std::vector< std::string > fLV0_names; ///< database field names for LV0 std::vector< std::string > fLV1_names; ///< database field names for LV1 std::vector< std::pair< double, std::vector< double > > > fLV0_vec; ///< LV0 query result std::vector< std::pair< double, std::vector< double > > > fLV1_vec; ///< LV1 query result unsigned int fLV0_idx; ///< index to fLV0_vec for current time bool fLV0_isok; ///< keep track of whether db query for given time is found unsigned int fLV1_idx; ///< index to fLV1_vec for current time bool fLV1_isok; ///< keep track of whether db query for given time is found unsigned int fLV0_next_idx; ///< index to fLV0_vec for current time bool fLV0_next_isok; ///< keep track of whether db query for given time is found unsigned int fLV1_next_idx; ///< index to fLV1_vec for current time bool fLV1_next_isok; ///< keep track of whether db query for given time is found /// FEM power for each MM on each endplate /// Tables: tpc_fe_sc_tsc0, ..., tpc_fe_sc_tsc5 /// Variables: e0m00fem_v33, ... /// index is [TPC][RP][MM] /// V should be >3100V float fFEM_V[3][2][12]; ///< FEM_V for current time float fFEM_V_next[3][2][12]; ///< FEM_V for next reading after current time std::string fFEM_V_tabnames[6]; ///< database table names for FEM_V std::vector< std::string > fFEM_V_names[6]; ///< database field names for FEM_V std::vector< std::pair< double, std::vector< double > > > fFEM_V_vec[6]; ///< FEM_V query results unsigned int fFEM_V_idx[6]; ///< index to fFEM_V_vec for current time bool fFEM_V_isok[6]; ///< keep track of whether db query for given time is found unsigned int fFEM_V_next_idx[6]; ///< index to fFEM_V_vec for current time bool fFEM_V_next_isok[6]; ///< keep track of whether db query for given time is found bool fFEMCheck[6]; ///< should this fem be checked? /// MM High voltage for each MM /// Tables: tpciseghv02_sensevoltage /// Variables: tpc0_rp0_mm00_sensevoltage, ... /// index is [TPC][RP][MM] /// V should be >345V <355V float fMM_HV[3][2][12]; ///< MM_HV for current time float fMM_HV_next[3][2][12]; ///< MM_HV for next reading after current time float fMM_HVminV[3][2][12]; ///< Minimum HV to call this MM okay std::vector< std::string > fMM_HV_names; ///< database field names fore MM_HV std::vector< std::pair< double, std::vector< double > > > fMM_HV_vec; ///< MM_HV query results unsigned int fMM_HV_idx; ///< index to fMM_HV_vec for current time bool fMM_HV_isok; ///< keep track of whether db query for given time is found unsigned int fMM_HV_next_idx; ///< index to fMM_HV_vec for current time bool fMM_HV_next_isok; ///< keep track of whether db query for given time is found /// DCC Power for each group of four FEM readout /// Tables: tpcdccpwr01_gp01, tpcdccpwr02_gp02, tpcdccpwr03_gp03 /// Variables: gp01_outvolt1, ... , gp03_outvolt6 /// index is [TPC][RP][MM] /// V should be > 4.5V float fDCC_V[3][2][12]; ///< DCC_V for current time float fDCC_V_next[3][2][12]; ///< DCC_V for next reading after current time bool fDCC_V_Check[3][2][12]; ///< Check the DCC voltage for given tpc, rp, mm? bool fDCCCheck[18]; ///< Check the voltage for given DCC? std::string fDCC_V_tabnames[3]; ///< database table names for DCC_V std::vector< std::string > fDCC_V_names[3]; ///< database field names for DCC_V std::vector< std::pair< double, std::vector< double > > > fDCC_V_vec[3]; ///< DCC_V query results unsigned int fDCC_V_idx[3]; ///< index to fDCC_V_vec for current time bool fDCC_V_isok[3]; ///< keep track of whether db query for given time is found unsigned int fDCC_V_next_idx[3]; ///< index to fDCC_V_vec for current time bool fDCC_V_next_isok[3]; ///< keep track of whether db query for given time is found /// Cathode HV for each TPC float fCath_V[3]; ///< Cath_V for current time float fCath_V_next[3]; ///< Cath_V for next reading after current time std::vector< std::string > fCath_V_names; ///< database field names for Cath_V std::vector< std::pair< double, std::vector< double > > > fCath_V_vec; ///< Cath_V query results unsigned int fCath_V_idx; ///< index to fCath_V_vec for current time bool fCath_V_isok; ///< keep track of whether db query for given time is found unsigned int fCath_V_next_idx; ///< index to fCath_V_vec for current time bool fCath_V_next_isok; ///< keep track of whether db query for given time is found /// Calculate overall status of each MM /// status is 0 if everything is okay /// status is 1 if LV is bad /// status is 2 if FEM is off /// status is 4 if MMHV is off /// status is 8 if DCC is off /// index is [TPC][RP][MM] long fMMStatus[3][2][12]; /// Calculate overall status for each TPC /// status is 0 if all okay /// status is maximum of MM statuses otherwise /// index is TPC long fTPCStatus[3]; /// Calculate overall status for TPCs /// status is 0 if everything is okay /// status is maximum of MM statuses otherwise long fStatus; bool fDebug; ///< Flag to print debug information to std::cout /// Set character timestamp from integer unix timestamp void SetupTimeStamp(); /// Read the MM system readings void Read( int adeltat=120 ); /// Initialize MM system object Sets offsets, makes histogram, /// reads properties, and fills histogram? void Init(); /// Read in the oaRunParameters settings for what to check void SetupCheck(); /// sets up the field names that are read from the slow control database void SetupFieldNames(); /// Update Status done after every read void UpdateStatus(); /// Check if any of the slow control vectors need an update void CheckReadDB( int adeltat = 120 ); // Read another chunk of data from slow control database void ReadSlowDB_LV0( int adeltat = 120 ); ///< Read DB for LV0 void ReadSlowDB_LV1( int adeltat = 120 ); ///< Read DB for LV0 void ReadSlowDB_FEM_V( int adeltat = 120 ); ///< Read DB for LV0 void ReadSlowDB_MM_HV( int adeltat = 120 ); ///< Read DB for LV0 void ReadSlowDB_DCC_V( int adeltat = 120 ); ///< Read DB for LV0 void ReadSlowDB_Cath_V( int adeltat = 120 ); ///< Read DB for LV0 /// Get index into each of the vectors of database query /// results for the current time void UpdateVectorTimeIdx( int adeltat=120 ); }; #endif //TTPCMMStatus_hxx__