MQwCodaControlEvent.cc
Go to the documentation of this file.00001 #include "MQwCodaControlEvent.h"
00002
00003 #include "QwLog.h"
00004
00005 MQwCodaControlEvent::MQwCodaControlEvent(){
00006 ResetControlParameters();
00007 }
00008
00009 MQwCodaControlEvent::~MQwCodaControlEvent() { }
00010
00011 void MQwCodaControlEvent::ResetControlParameters()
00012 {
00013 fFoundControlEvents = kFALSE;
00014 fPrestartTime = 0;
00015 fPrestartRunNumber = 0;
00016 fRunType = 0;
00017 fEndTime = 0;
00018 fEndEventCount = 0;
00019 fNumberPause = 0;
00020 fPauseTime.clear();
00021 fPauseEventCount.clear();
00022 fNumberGo = 0;
00023 fGoTime.clear();
00024 fGoEventCount.clear();
00025 fStartTime = 0;
00026 fPrestartDatime.Set(UInt_t(0));
00027 fStartDatime.Set(UInt_t(0));
00028 fEndDatime.Set(UInt_t(0));
00029 }
00030
00031 void MQwCodaControlEvent::ProcessControlEvent(UInt_t evtype, UInt_t* buffer){
00032 UInt_t local_time;
00033 UInt_t local_evcount;
00034
00035 local_time = buffer[0];
00036 local_evcount = buffer[2];
00037 if (evtype==kSYNC_EVENT){
00038 UInt_t local_status = buffer[1];
00039 ProcessSync(local_time, local_status);
00040 } else if (evtype==kPRESTART_EVENT){
00041 UInt_t local_runnumber = buffer[1];
00042 UInt_t local_runtype = buffer[2];
00043 ProcessPrestart(local_time, local_runnumber, local_runtype);
00044 } else if (evtype==kGO_EVENT){
00045 ProcessGo(local_time, local_evcount);
00046 } else if (evtype==kPAUSE_EVENT){
00047 ProcessPause(local_time, local_evcount);
00048 } else if (evtype==kEND_EVENT){
00049 ProcessEnd(local_time, local_evcount);
00050 } else {
00051
00052
00053 }
00054 }
00055
00056
00057 void MQwCodaControlEvent::ProcessSync(UInt_t local_time, UInt_t statuscode)
00058 {
00059 fFoundControlEvents = kTRUE;
00060
00061 }
00062
00063
00064 void MQwCodaControlEvent::ProcessPrestart(UInt_t local_time, UInt_t local_runnumber,
00065 UInt_t local_runtype)
00066 {
00067 fFoundControlEvents = kTRUE;
00068
00069 ResetControlParameters();
00070
00071 fPrestartTime = local_time;
00072 fPrestartRunNumber = local_runnumber;
00073 fRunType = local_runtype;
00074 fPrestartDatime.Set(fPrestartTime);
00075 }
00076
00077 void MQwCodaControlEvent::ProcessPause(UInt_t local_time, UInt_t evt_count)
00078 {
00079 fFoundControlEvents = kTRUE;
00080
00081 fNumberPause++;
00082 fPauseEventCount.push_back(evt_count);
00083 fPauseTime.push_back(local_time);
00084 }
00085
00086 void MQwCodaControlEvent::ProcessGo(UInt_t local_time, UInt_t evt_count)
00087 {
00088 fFoundControlEvents = kTRUE;
00089
00090 fNumberGo++;
00091 fGoEventCount.push_back(evt_count);
00092 fGoTime.push_back(local_time);
00093 if (fNumberGo == 1){
00094 fStartTime = fGoTime[0];
00095 fStartDatime.Set(fStartTime);
00096 }
00097 }
00098
00099 void MQwCodaControlEvent::ProcessEnd(UInt_t local_time, UInt_t evt_count)
00100 {
00101 fFoundControlEvents = kTRUE;
00102
00103 fEndTime = local_time;
00104 fEndEventCount = evt_count;
00105 fEndDatime.Set(fEndTime);
00106 }
00107
00108
00109 UInt_t MQwCodaControlEvent::GetGoTime(int index)
00110 {
00111 if (index>=0 && index<(Int_t)fNumberGo) return fGoTime[index];
00112 return 0;
00113 }
00114
00115 UInt_t MQwCodaControlEvent::GetGoEventCount(int index)
00116 {
00117 if (index>=0 && index<(Int_t)fNumberGo) return fGoEventCount[index];
00118 return 0;
00119 }
00120
00121 UInt_t MQwCodaControlEvent::GetPauseTime(int index)
00122 {
00123 if (index>=0 && index<(Int_t)fNumberPause) return fPauseTime[index];
00124 return 0;
00125 }
00126
00127 UInt_t MQwCodaControlEvent::GetPauseEventCount(int index)
00128 {
00129 if (index>=0 && index<(Int_t)fNumberPause) return fPauseEventCount[index];
00130 return 0;
00131 }
00132
00133
00134 TString MQwCodaControlEvent::GetStartSQLTime()
00135 {
00136 return fStartDatime.AsSQLString();
00137 }
00138
00139 TString MQwCodaControlEvent::GetEndSQLTime()
00140 {
00141 return fEndDatime.AsSQLString();
00142 }
00143
00144
00145 void MQwCodaControlEvent::ReportRunSummary()
00146 {
00147 if (fFoundControlEvents){
00148
00149
00150 Int_t i;
00151 QwMessage << "Run Number: " << fPrestartRunNumber << QwLog::endl;
00152 QwMessage << "Run Type: " << fRunType << QwLog::endl;
00153 QwMessage << "PreStart Time: " << fPrestartTime << QwLog::endl;
00154 QwMessage << "Start Time: " << fStartTime << QwLog::endl;
00155 QwMessage << "End Time: " << fEndTime << QwLog::endl;
00156 QwMessage << "End Event Counter: " << fEndEventCount << QwLog::endl;
00157 if (fEndTime>0 && fStartTime>0)
00158 QwMessage << "Run Duration (sec): " << fEndTime-fStartTime << QwLog::endl;
00159 else
00160 QwMessage << "Run Duration (sec): " << "n/a" << QwLog::endl;
00161 QwMessage << "SQL-Formatted Start Time: " << GetStartSQLTime()
00162 << QwLog::endl;
00163 QwMessage << "SQL-Formatted End Time: " << GetEndSQLTime()
00164 << QwLog::endl;
00165 QwMessage << "Number of Pauses during this run: " << fNumberPause
00166 << QwLog::endl;
00167 for (i=0; i<(Int_t)fNumberPause; i++) {
00168 QwMessage << "Pause Number: " << i
00169 <<"; Events so far: " << fPauseEventCount[i]
00170 << "; Runtime since start (sec): "
00171 << fPauseTime[i]-fStartTime;
00172 if ((Int_t)fNumberGo > i+1){
00173 QwMessage << "; Duration of Pause (sec): "
00174 << fGoTime[i+1]-fPauseTime[i]
00175 << QwLog::endl;
00176 }else {
00177 QwMessage << QwLog::endl;
00178 }
00179 }
00180 }
00181 }
00182
00183
00184 time_t MQwCodaControlEvent::GetStartUnixTime()
00185 {
00186 return (time_t) GetStartTime();
00187 }
00188
00189
00190 time_t MQwCodaControlEvent::GetEndUnixTime()
00191 {
00192
00193
00194
00195 UInt_t end_time = GetEndTime();
00196 UInt_t qweak_end_time = 1338523199;
00197
00198
00199
00200
00201 if(end_time) return (time_t) end_time;
00202 else return (time_t) qweak_end_time;
00203 }