00001
00002
00003
00004
00005
00006
00008 #include "MessageService/MsgService.h"
00009 #include "CandDigit/CandDigitHandle.h"
00010 #include "Calibrator/TimeCalibrator.h"
00011 #include "Plex/PlexSEIdAltL.h"
00012 #include "Plex/PlexStripEndId.h"
00013 #include "DatabaseInterface/DbiValidityRec.h"
00014 #include "Validity/VldRange.h"
00015
00016 CVSID("$Id: TimeCalibrator.cxx,v 1.1 2004/07/26 16:52:20 tagg Exp $");
00017
00018 TimeCalibrator::TimeCalibrator(int calMode)
00019 :fResPtr(), fCalMode(calMode)
00020 {
00021 MSG("Calibrator",Msg::kVerbose) << "TimeCalibrator::TimeCalibrator"
00022 << endl;
00023 }
00024
00025 TimeCalibrator::TimeCalibrator(const VldContext vc, int calMode)
00026 : fResPtr(vc),fCalMode(calMode)
00027 {
00028
00029
00030 if(fCalMode>0){
00031 if(fResPtr.GetNumRows()==0) {
00032 MSG("Time Calibrator",Msg::kWarning)
00033 << "No rows in database table with validity context "
00034 << vc.AsString() << " will assert() here" << ".\n";
00035 MSG("Time Calibrator",Msg::kWarning)
00036 << "TimeStamp " << vc.GetTimeStamp() << "\n";
00037 MSG("Time Calibrator",Msg::kWarning)
00038 << "SimFlag " << (int)vc.GetSimFlag() << "\n";
00039 MSG("Time Calibrator",Msg::kWarning)
00040 << "Detector " << (int)vc.GetDetector() << "\n";
00041
00042
00043 if ( ! ((int)vc.GetDetector() & 127) ) {
00044 MSG("Time Calibrator",Msg::kWarning)
00045 << "Detector " << (int)vc.GetDetector()
00046 << " is the problem.\n";
00047 }
00048 if ( ! ((int)vc.GetSimFlag() & 127) ) {
00049 MSG("Time Calibrator",Msg::kWarning)
00050 << "Simflag " << (int)vc.GetSimFlag()
00051 << " is the problem.\n";
00052 }
00053
00054
00055
00056 const DbiValidityRec* fred = fResPtr.GetValidityRec();
00057 const VldRange freda=fred->GetVldRange();
00058 MSG("Time Calibrator",Msg::kWarning)
00059 << "bugger "
00060 << freda.AsString() << ".\n";
00061 }
00062 }
00063 else{
00064 static int msglimit = 20;
00065 if (msglimit) {
00066 MSG("Time Calibrator",Msg::kInfo ) << "No Time Cal Table Loaded.\n";
00067 if (--msglimit == 0)
00068 MSG("Time Calibrator",Msg::kInfo )
00069 << "... last warning of this type." << endl;
00070 }
00071
00072 }
00073 }
00074
00075
00076
00077 Double_t TimeCalibrator::Calibrate(Double_t rawtime,
00078 PlexStripEndId seid) const
00079 {
00080
00081
00082
00083 return ApplyCalib(rawtime,seid);
00084
00085 }
00086
00087
00088
00089 Double_t TimeCalibrator::ApplyCalib(Double_t rawtime,
00090 PlexStripEndId seid) const
00091 {
00092
00093
00094
00095
00096
00097 MSG("Calibrator",Msg::kVerbose) << "TimeCalibrator on " << rawtime
00098 << " seid " << seid.BuildPlnStripEndKey() <<"\n";
00099
00100
00101 const CalTimeCalibration* dpgc = fResPtr.GetRowByIndex(seid.BuildPlnStripEndKey());
00102 if(dpgc ==0) {
00103
00104
00105 return rawtime;
00106 }
00107 return dpgc->GetTime(rawtime);
00108 }
00109
00110
00111
00112
00113 const CalTimeCalibration* TimeCalibrator::GetCalTimeCalibration(PlexStripEndId seid) const
00114 {
00115 return fResPtr.GetRowByIndex(seid.BuildPlnStripEndKey());
00116 }
00117
00118
00119
00120
00121 void TimeCalibrator::ReInit(VldContext vc) {
00122 MSG("Calibrator",Msg::kVerbose) << "TimeCalibrator::ReInit(VldContext)" << endl;
00123
00124 fResPtr.NewQuery(vc,0);
00125
00126
00127 if(fResPtr.GetNumRows()==0) {
00128 static int msglimit = 20;
00129 if (msglimit) {
00130 MSG("Time Calibrator",Msg::kWarning)
00131 << "No rows in database table with validity context "
00132 << vc.AsString() << " will assert() here" << ".\n";
00133 MSG("Time Calibrator",Msg::kWarning)
00134 << "TimeStamp " << vc.GetTimeStamp() << "\n";
00135 MSG("Time Calibrator",Msg::kWarning)
00136 << "SimFlag " << (int)vc.GetSimFlag() << "\n";
00137 MSG("Time Calibrator",Msg::kWarning)
00138 << "Detector " << (int)vc.GetDetector() << "\n";
00139
00140
00141 if ( ! ((int)vc.GetDetector() & 127) ) {
00142 MSG("Time Calibrator",Msg::kWarning)
00143 << "Detector " << (int)vc.GetDetector()
00144 << " is the problem.\n";
00145 }
00146 if ( ! ((int)vc.GetSimFlag() & 127) ) {
00147 MSG("Time Calibrator",Msg::kWarning)
00148 << "Simflag " << (int)vc.GetSimFlag()
00149 << " is the problem.\n";
00150 }
00151
00152
00153
00154 const DbiValidityRec* fred = fResPtr.GetValidityRec();
00155 const VldRange freda=fred->GetVldRange();
00156 MSG("Time Calibrator",Msg::kWarning)
00157 << "bugger "
00158 << freda.AsString() << ".\n";
00159
00160 if (--msglimit == 0)
00161 MSG("Calibrator",Msg::kWarning)
00162 << " ... last warning of this type" << endl;
00163 }
00164 }
00165 }
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177