RxThresholdDisplayer.cpp

00001 #include "RxThresholdDisplayer.h"
00002 #include "DisplayManager.h"
00003 #include "DisplayInfo.h"
00004 #include "RawDisplayer.h"
00005 
00006 #include "SctData/RawScanResult.h"
00007 #include "SctData/RxThresholdBasedOnConfigRegisterTestResult.h"
00008 #include "Sct/IS/IOManagerIS.h"
00009 #include "Sct/IS/IONameIS.h"
00010 #include "Sct/Archive/IONameArchiveFile.h"
00011 #include "Sct/Archive/IOManagerArchiveFile.h"
00012 
00013 #include <vector>
00014 #include <sstream>
00015 #include <algorithm>
00016 #include <boost/shared_ptr.hpp>
00017 
00018 #include <TCanvas.h>
00019 #include <TLine.h>
00020 #include <TAxis.h>
00021 #include <TH2.h>
00022 
00023 using namespace std;
00024 using namespace SctData;
00025 using namespace Sct;
00026 using namespace Sct::IS;
00027 using namespace boost;
00028 
00029 namespace SctDataDisplay {
00030 
00031 bool RxThresholdDisplayer::inMap = DisplayManager::addToMap("SctData::RxThresholdBasedOnConfigRegisterTestResult", shared_ptr<Displayer>(new RxThresholdDisplayer()));
00032 
00033 
00034 class RxThresholdDisplayData : public DisplayData {
00035  public:
00036   boost::shared_ptr<RawDisplayData> rawDisplayData;
00037   boost::shared_ptr<const RawScanResult> raw;
00038 };
00039 
00040 shared_ptr<DisplayData> RxThresholdDisplayer::display(shared_ptr<const Sct::Serializable> serial, const DisplayInfo& info, std::ostream& os) {  
00041     shared_ptr<RxThresholdDisplayData> data (new RxThresholdDisplayData());
00042     const RxThresholdBasedOnConfigRegisterTestResult& result = dynamic_cast<const RxThresholdBasedOnConfigRegisterTestResult&>(*serial);
00043     os << result.getHeader().getScanNumber() << endl;
00044     
00045     try {
00046         Sct::IS::IONameIS name_is(result.getUniqueID(), "SctData::RawScanResult");
00047     shared_ptr<Serializable> ob = IOManagerIS::instance().read(name_is.getIOName());
00048     data->raw = dynamic_pointer_cast<const RawScanResult>(ob);
00049     } catch (Sct::IoException& e) {
00050     e.sendToMrs(MRS_DIAGNOSTIC);
00051     }
00052     if (data->raw==0) try {
00053       Sct::Archive::IONameArchiveFile name(result.getHeader().getUniqueID(),"SctData::RawScanResult");
00054       shared_ptr<Serializable> ob = Sct::Archive::IOManagerArchiveFile::instance().read(name.getIOName());
00055       data->raw = dynamic_pointer_cast<const RawScanResult>(ob);
00056     } catch (Sct::IoException& e) {
00057     e.sendToMrs(MRS_DIAGNOSTIC);
00058     }
00059 
00060     if (data->raw == 0){
00061         cerr << "Couldn't get RawScanResult associated with this RxThresholdScanResult" << endl;    
00062     }else{
00063       boost::shared_ptr<DisplayData> ddata = DisplayManager::display(data->raw, info, os);
00064       data->rawDisplayData = dynamic_pointer_cast<RawDisplayData>(ddata);
00065 
00066       if (data->rawDisplayData->canvas.empty() || !data->rawDisplayData->canvas[0].get()) {
00067     std::cout << "Can not draw lines on empty canvas" << std::endl; 
00068       }else {
00069 
00070 
00071     TVirtualPad* pad = (TVirtualPad*)data->rawDisplayData->canvas[0]->GetPrimitive("Data");
00072     if (!pad) std::cerr << "no pad" << std::endl;
00073     for (unsigned int link=0; link<2; ++link) {
00074       
00075       if (pad) pad->cd(link+1);
00076       TAxis* axis = data->raw->getScanData(link).GetXaxis();
00077  
00078       double min = axis->GetXmin();
00079       double max = axis->GetXmax();
00080       TLine*l = new TLine(min, result.getStreamResult(link).bestRxThresh(), max,result.getStreamResult(link).bestRxThresh());
00081       l->SetLineWidth(2);
00082       l->SetLineColor(kBlue);
00083       l->Draw();
00084 
00085       TLine*lmax = new TLine(min, result.getStreamResult(link).maxErrorFreeRxThresh(), max,result.getStreamResult(link).maxErrorFreeRxThresh());
00086       lmax->SetLineWidth(1);
00087       lmax->SetLineColor(kRed);
00088       lmax->Draw();
00089 
00090       TLine*lmin = new TLine(min, result.getStreamResult(link).minErrorFreeRxThresh(), max,result.getStreamResult(link).minErrorFreeRxThresh());
00091       lmin->SetLineWidth(1);
00092       lmin->SetLineColor(kRed);
00093       lmin->Draw();
00094       
00095     }
00096     
00097       }
00098     }
00099     
00100     //Now print out defects:
00101     os << endl << "Defects: " << endl;
00102     printDefectList(result.getDefects(), os);   
00103     
00104     return data;
00105 }
00106 }

Generated on Mon Feb 6 14:01:27 2006 for SCT DAQ/DCS Software - C++ by  doxygen 1.4.6