00001 #include "DaqRunInfoTestAlg.h"
00002 #include "DaqRunInfoSvc/DaqRunInfo.h"
00003 #include "DaqRunInfoSvc/DaqCalibRunInfo.h"
00004 #include "DatabaseSvc/IDatabaseSvc.h"
00005 #include "DaqRunInfoSvc/IDaqRunInfoSvc.h"
00006
00007 #include "Conventions/Site.h"
00008 #include "Conventions/SimFlag.h"
00009 #include "Context/TimeStamp.h"
00010 #include "Context/ContextRange.h"
00011 #include "DatabaseInterface/DbiResultPtr.h"
00012 #include "DatabaseInterface/DbiValidityRec.h"
00013 #include "DatabaseInterface/DbiSqlContext.h"
00014
00015 #include <fstream>
00016
00017 DaqRunInfoTestAlg::DaqRunInfoTestAlg(const string& name, ISvcLocator* pSvcLocator)
00018 :GaudiAlgorithm(name, pSvcLocator), m_daqRunInfoSvc(0)
00019 {
00020 declareProperty("daqRunInfoSvcName", m_daqRunInfoSvcName = "DaqRunInfoSvc",
00021 "Name of the service for access run information");
00022 declareProperty("fileName", m_fileName = "", "Name of the raw data file");
00023 declareProperty("outputFile", m_outputFile = "runConfig.txt", "Name of the output file holding run configuration");
00024 declareProperty("runNo", m_runNo = 400, "run number");
00025 declareProperty("verbose", m_verbose = "simple", "Verbose to print run information, simple or full");
00026 }
00027
00028 DaqRunInfoTestAlg::~DaqRunInfoTestAlg()
00029 {
00030 }
00031
00032 StatusCode DaqRunInfoTestAlg::initialize()
00033 {
00034
00035 StatusCode sc = this->service(m_daqRunInfoSvcName, m_daqRunInfoSvc, true);
00036 if(sc.isFailure()){
00037 error() << "Failed to get service: " << m_daqRunInfoSvcName << endreq;
00038 return sc;
00039 }
00040 return StatusCode::SUCCESS;
00041 }
00042
00043 StatusCode DaqRunInfoTestAlg::execute()
00044 {
00045 return StatusCode::SUCCESS;
00046 }
00047
00048 StatusCode DaqRunInfoTestAlg::finalize()
00049 {
00050 if ( m_fileName == ""){
00051 warning() << "No raw data file name is provided!"<<endreq;
00052 warning() << "Use run number to access the run information."<<endreq;
00053 }
00054 else{
00055 m_runNo = m_daqRunInfoSvc->runNumber(m_fileName);
00056 info() << "The run number of "<<m_fileName<<" is "<<m_runNo<<endreq;
00057 }
00058
00059 if(m_runNo == 0)
00060 warning() << "No run number is provided!"<<endreq;
00061 else
00062 printRunInfo(m_runNo);
00063
00064 m_daqRunInfoSvc->release();
00065 return StatusCode::SUCCESS;
00066 }
00067
00068 StatusCode DaqRunInfoTestAlg::printRunInfo(int runNo)
00069 {
00070 const DaqRunInfo* row;
00071 row = m_daqRunInfoSvc->GetRunInfo(runNo);
00072 if(!row){
00073 warning() << "runNo: "<<runNo<<" is not found in table DaqRunInfo."<<endreq;
00074 return StatusCode::FAILURE;
00075 }
00076
00077 DbiResult* res = row->GetOwner();
00078 const DbiValidityRec vr = res->GetValidityRec();
00079 const ContextRange cr = vr.GetContextRange();
00080 info() <<"runNo: "<<row->GetRunNo()<<endreq;
00081 info() <<"timeStart: "<<cr.GetTimeStart()<<endreq;
00082 info() <<"timeEnd: "<<cr.GetTimeEnd()<<endreq;
00083 info() <<"triggerType: "<<row->GetTriggerType()<<endreq;
00084 info() <<"runType: "<<row->GetRunType()<<endreq;
00085 info() <<"detectorMask: "<<row->GetDetectorMask()<<endreq;
00086 info() <<"partitionName: "<<row->GetPartitionName()<<endreq;
00087 info() <<"schemaVersion: "<<row->GetSchemaVersion()<<endreq;
00088 info() <<"dataVersion: "<<row->GetDataVersion()<<endreq;
00089 info() <<"baseVersion: "<<row->GetBaseVersion()<<endreq;
00090
00091 string runType = row->GetRunType();
00092 if(runType == "ADCalib"){
00093 info() <<"runNo: "<<runNo<<" is a AD calibration run."<<endreq;
00094 }
00095
00096 vector<DayaBay::DaqRunConfig> vec;
00097 if(m_verbose == "simple")
00098 m_daqRunInfoSvc->simpRunConfigList(runNo, vec);
00099 else if (m_verbose == "full")
00100 m_daqRunInfoSvc->fullRunConfigList(runNo, vec);
00101 else
00102 m_daqRunInfoSvc->simpRunConfigList(runNo, vec);
00103
00104 info() <<"runNo: "<<runNo<<" has "<<vec.size()<<" records of DaqRunConfig "<<endreq;
00105 ofstream output;
00106 output.open(m_outputFile.c_str());
00107 output <<"------- Overview of run information ----------"<<endl;
00108 output <<"runNo: "<<row->GetRunNo()<<endl;
00109 output <<"timeStart: "<<cr.GetTimeStart()<<endl;
00110 output <<"timeEnd: "<<cr.GetTimeEnd()<<endl;
00111 output <<"triggerType: "<<row->GetTriggerType()<<endl;
00112 output <<"runType: "<<row->GetRunType()<<endl;
00113 output <<"detectorMask: "<<row->GetDetectorMask()<<endl;
00114 output <<"partitionName: "<<row->GetPartitionName()<<endl;
00115 output <<"schemaVersion: "<<row->GetSchemaVersion()<<endl;
00116 output <<"dataVersion: "<<row->GetDataVersion()<<endl;
00117 output <<"baseVersion: "<<row->GetBaseVersion()<<endl;
00118
00119 if(runType == "ADCalib"){
00120 output <<"\n"<<"------- AD calibration run information ----------"<<endl;
00121 const DaqCalibRunInfo* calib = m_daqRunInfoSvc->GetCalibRunInfo(runNo);
00122 if(!calib){
00123 warning() << "runNo: "<<runNo<<" is not found in table DaqCalibRunInfo."<<endreq;
00124 }
00125 else{
00126 output<<"AdNo: "<<calib->GetAdNo()<<endl;
00127 output<<"DetectorId: "<<calib->GetDetectorId()<<endl;
00128 output<<"SourceIdA: "<<calib->GetSourceIdA()<<endl;
00129 output<<"ZPositionA: "<<calib->GetZPositionA()<<" cm"<<endl;
00130 output<<"SourceIdB: "<<calib->GetSourceIdB()<<endl;
00131 output<<"ZPositionB: "<<calib->GetZPositionB()<<" cm"<<endl;
00132 output<<"SourceIdC: "<<calib->GetSourceIdC()<<endl;
00133 output<<"ZPositionC: "<<calib->GetZPositionC()<<" cm"<<endl;
00134 output<<"Duration: "<<calib->GetDuration()<<" seconds"<<endl;
00135 output<<"LedNumber1: "<<calib->GetLedNumber1()<<endl;
00136 output<<"LedNumber2: "<<calib->GetLedNumber2()<<endl;
00137 output<<"LedVoltage1: "<<calib->GetLedVoltage1()<<" mV"<<endl;
00138 output<<"LedVoltage2: "<<calib->GetLedVoltage2()<<" mV"<<endl;
00139 output<<"LedFreq: "<<calib->GetLedFreq()<<" Hz"<<endl;
00140 output<<"LedPulseSep: "<<calib->GetLedPulseSep()<<endl;
00141 output<<"LtbMode: "<<calib->GetLtbMode()<<endl;
00142 }
00143 }
00144
00145 if(vec.size() != 0){
00146
00147 vector<string> dets;
00148 vector<string> crates;
00149 vector<string> ltbs;
00150 vector<string> fees;
00151 vector<string>::iterator itr;
00152 m_daqRunInfoSvc->findHWList(vec, dets, crates, ltbs, fees);
00153 output <<"\n"<<"------ Hardware setting --------------"<<endl;
00154 output<<"Detector:";
00155 for( itr = dets.begin(); itr != dets.end(); itr++)
00156 output << " "<<(*itr);
00157 output << endl;
00158 output <<"Crates:";
00159 for( itr = crates.begin(); itr != crates.end(); itr++)
00160 output << " "<<(*itr);
00161 output << endl;
00162 output <<"LTBs:";
00163 for( itr = ltbs.begin(); itr != ltbs.end(); itr++)
00164 output <<" "<<(*itr);
00165 output << endl;
00166 output <<"FEEs:";
00167 for( itr = fees.begin(); itr != fees.end(); itr++)
00168 output << " "<<(*itr);
00169 output << endl;
00170
00171
00172 map<string, string> th_obj;
00173 map<string, bool> isuni;
00174 map<string, int> thrsuni;
00175 map<string, map<string, int> > thrs;
00176 m_daqRunInfoSvc->findFEEThreshold(runType, vec, fees, th_obj, isuni, thrsuni, thrs);
00177 map<string, string>::iterator obj;
00178 for( obj = th_obj.begin(); obj != th_obj.end(); obj++){
00179 if( isuni[obj->first]){
00180 output<<"Uniform thresholds for channels of "<<obj->first<<" ["<<obj->second<<"]: "<<thrsuni[obj->first]<<endl;
00181 }
00182 else
00183 {
00184
00185 output<<"Thresholds for channels of "<<obj->first<<" ["<<obj->second<<"] is as following. "<<endl;
00186 map<string, int> amap;
00187 map<string, int>::iterator itt;
00188 amap = thrs[obj->first];
00189 for (itt = amap.begin(); itt != amap.end(); itt++){
00190 output<<"Threshold for one chaneel: "<<itt->first<<" = "<<itt->second<<endl;
00191 }
00192 }
00193 }
00194
00195
00196 map<string, string> mode;
00197 map<string, int> trig_src;
00198 map<string, string> trig_name;
00199 map<string, map<string, int> > trig_thres;
00200 m_daqRunInfoSvc->findLtbTrigger(runType, vec, ltbs, mode, trig_src, trig_name, trig_thres);
00201
00202 map<string, string>::iterator mapit;
00203 for( mapit = mode.begin(); mapit != mode.end(); mapit++){
00204 output<<"LTB object: "<<mapit->first<<endl;
00205 output<<"LTB work mode: "<<mapit->second<<endl;
00206 output<<"LTB_triggerSource: "<<trig_src[mapit->first]<<endl;
00207 output<<"LTB trigger setting: "<<trig_name[mapit->first]<<endl;
00208 map<string, int> thres;
00209 thres = trig_thres[mapit->first];
00210 map<string, int>::iterator th;
00211 for(th = thres.begin(); th != thres.end(); th++){
00212 if(th->first.find("MULTIPLICITY") != string::npos)
00213 output<<th->first<<" threshold >= "<<th->second + 1<<endl;
00214 else
00215 output<<th->first<<" threshold > "<<th->second<<endl;
00216 }
00217 }
00218
00219
00220 output<<"\n"<<"------ Table of run configuration ------------"<<endl;
00221 output<<"dataVersion "<<"creationVersion "<<"className "<<"objectId "<<"name "<<"parentPosition "<<"intValue "<<"floatValue "<<"stringValue "<<endl;
00222 vector<DayaBay::DaqRunConfig>::iterator it;
00223 for( it = vec.begin(); it != vec.end(); it++){
00224 output<<it->m_DataVersion<<" "
00225 <<it->m_CreationVersion<<" "
00226 <<it->m_ClassName<<" "
00227 <<it->m_ObjectId<<" "
00228 <<it->m_Name<<" "
00229 <<it->m_ParentPosition<<" "
00230 <<it->m_IntValue<<" "
00231 <<it->m_FloatValue<<" "
00232 <<it->m_StringValue<<endl;
00233 }
00234 output.close();
00235 }
00236
00237 return StatusCode::SUCCESS;
00238 }