/search.css" rel="stylesheet" type="text/css"/> /search.js">
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

PrintAdTempAlg.cc
Go to the documentation of this file.
00001 #include "PrintAdTempAlg.h"
00002 #include "DcsDataSvc/DcsAdTemp.h"
00003 #include "Context/ContextRange.h"
00004 #include "DaqRunInfoSvc/DaqRunInfo.h"
00005 #include "DbiRawDataFileSvc/DaqRawDataFileInfo.h"
00006 #include "DaqRunInfoSvc/IDaqRunInfoSvc.h"
00007 #include "Conventions/Site.h"
00008 #include "Conventions/SimFlag.h"
00009 
00010 #include "DatabaseInterface/DbiResultPtr.h"
00011 #include "DatabaseInterface/DbiValidityRec.h"
00012 #include "DatabaseInterface/DbiSqlContext.h"
00013 
00014 #include <fstream>
00015 
00016 PrintAdTempAlg::PrintAdTempAlg(const string& name, ISvcLocator* pSvcLocator)
00017 :GaudiAlgorithm(name, pSvcLocator)
00018 {
00019   declareProperty("runNo", m_runNo = 1576, "Input runNo to query the AD temperature"); //runNo=1576 is a long muon run
00020   declareProperty("fileName", m_fileName = "", "Name of input file to query the AD temperature data");
00021   declareProperty("outputFile", m_outputFile = "AdTemp.txt", "Name of file to print the AD temperature data");
00022 
00023 }
00024 
00025 PrintAdTempAlg::~PrintAdTempAlg()
00026 {
00027 }
00028 
00029 StatusCode PrintAdTempAlg::initialize()
00030 {
00031   // Initialize the necessary services
00032   StatusCode sc = this->service("DaqRunInfoSvc", m_daqRunInfoSvc, true);
00033   if(sc.isFailure()){
00034       error() << "Failed to get service: " << "DaqRunInfoSvc" << endreq;
00035       return sc;
00036   }
00037 
00038   return StatusCode::SUCCESS;
00039 }
00040 
00041 StatusCode PrintAdTempAlg::execute()
00042 {
00043   return StatusCode::SUCCESS;
00044 }
00045 
00046 StatusCode PrintAdTempAlg::finalize()
00047 {
00048   // Get the time Start and End for a run
00049   const DaqRunInfo* aRun;
00050   aRun = m_daqRunInfoSvc->GetRunInfo(m_runNo);
00051 
00052   if ( m_fileName == ""){
00053     warning() << "No raw data file name is provided!"<<endreq;
00054     warning() << "Use run number to access the run information."<<endreq;
00055 
00056     DbiResult* res = aRun->GetOwner();
00057     const DbiValidityRec vr = res->GetValidityRec();
00058     const ContextRange cr = vr.GetContextRange();
00059     m_start = cr.GetTimeStart();
00060     m_end = cr.GetTimeEnd();
00061   }
00062   else{
00063     const DaqRawDataFileInfo* fileInfo;
00064     fileInfo = m_daqRunInfoSvc->GetFileInfo(m_fileName);
00065     
00066     // Get the ContextRange for fileInfo
00067     DbiResult* res = fileInfo->GetOwner();
00068     const DbiValidityRec vr = res->GetValidityRec();
00069     const ContextRange cr = vr.GetContextRange();
00070 
00071     m_start = cr.GetTimeStart();
00072     m_end = cr.GetTimeEnd();
00073   }
00074 
00075   ofstream output;
00076   output.open(m_outputFile.c_str());
00077   output<<"The Data of four temperature sensors in one AD is listed:\n"<<endl;
00078 
00079   // Test of loading all data
00080   //DbiSqlContext vc("1=1");
00081   //DbiResultPtr<DcsAdTemp> ptr1("DcsAdTemp", vc);
00082 
00083   //Query the AD temperature at start time
00084   Context startContext( Site::kDayaBay, SimFlag::kData, m_start);
00085   Dbi::SubSite subsite = 1;
00086   DbiResultPtr<DcsAdTemp> ptr1("DcsAdTemp", startContext, subsite);
00087   unsigned int numRows = ptr1.GetNumRows();
00088   const DcsAdTemp* row;
00089   output<<"The AD temperature at start time is:"<<endl;
00090   for (unsigned int idx=0; idx < numRows; idx++) {
00091     row = ptr1.GetRowByIndex(idx);
00092     output<<row->GetTemp1()<<"  "<<row->GetTemp2()<<"  "
00093           <<row->GetTemp3()<<"  "<<row->GetTemp4()<<endl;
00094   }
00095 
00096   //Query the AD temperature at end time
00097   Context endContext( Site::kDayaBay, SimFlag::kData, m_end);
00098   DbiResultPtr<DcsAdTemp> ptr2("DcsAdTemp",endContext, subsite);
00099   numRows = ptr2.GetNumRows();
00100   output<<"\nThe AD temperature at end time is:"<<endl;
00101   for (unsigned int idx=0; idx < numRows; idx++) {
00102     row = ptr2.GetRowByIndex(idx);
00103     output<<row->GetTemp1()<<"  "<<row->GetTemp2()<<"  "
00104           <<row->GetTemp3()<<"  "<<row->GetTemp4()<<endl;
00105   }
00106   
00107   //Query the AD temperature between start and end time
00108   Dbi::Task task = Dbi::kDefaultTask;
00109   DbiSqlContext sqlContext(DbiSqlContext::kWithin, m_start, m_end, Site::kDayaBay, SimFlag::kData);
00110   DbiResultPtr<DcsAdTemp> ptr3("DcsAdTemp", sqlContext, subsite, task);
00111   numRows = ptr3.GetNumRows();
00112   output<<"\nThe AD temperature between start and end time is:"<<endl;
00113   for (unsigned int idx=0; idx < numRows; idx++) {
00114     row = ptr3.GetRowByIndex(idx);
00115     output<<row->GetTemp1()<<"  "<<row->GetTemp2()<<"  "
00116           <<row->GetTemp3()<<"  "<<row->GetTemp4()<<endl;
00117   }
00118 
00119   return StatusCode::SUCCESS;
00120 }
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Fri May 16 2014 09:57:12 for DcsDataSvc by doxygen 1.7.4