00001 #include "ArchNMaskTestResult.h"
00002 #include <TFile.h>
00003 #include <TKey.h>
00004 #include <TDirectory.h>
00005 #include <TSystem.h>
00006 #include <TNamed.h>
00007 #include <TObject.h>
00008 #include <TString.h>
00009 #include <TObjString.h>
00010 #include <TH1.h>
00011 #include <TH2.h>
00012 #include <TCanvas.h>
00013 #include <TROOT.h>
00014 #include <TVector.h>
00015 #include <is/isinfo.h>
00016 #include <iostream>
00017 #include <vector>
00018 #include "SummaryWriter/SummaryWriter.h"
00019 #include "SummaryWriter/SummaryManager.h"
00020 
00021 
00022 
00023 
00024 ArchNMaskTestResult::ArchNMaskTestResult(): ArchTestResult()  {
00025 
00026   
00027   
00028   
00029   
00030 }
00031 
00032 
00033 ArchNMaskTestResult::ArchNMaskTestResult(NMaskTestResult& NMasktest): ArchTestResult(NMasktest)  {
00034 
00035   
00036   
00037   
00038 
00039 
00040   
00041   try{
00042     TestSummary(NMasktest);
00043   } catch(...) {
00044     cout<<" ERROR in retrieving Test Summary from IS" <<endl;
00045   }
00046 
00047 
00048 
00049 }
00050 
00051 
00052 
00053 
00054 
00055 
00056 ArchNMaskTestResult::~ArchNMaskTestResult()  {
00057   
00058   
00059   
00060 
00061   
00062 }
00063 
00064 
00065 
00066 void ArchNMaskTestResult::SaveNMaskTestDataOnly() {
00067 
00068   cout<<"Saving NMaskTestData "<<endl;
00069   
00070 
00071   string filename = names->getfilename();
00072   string moduleID = names->getModuleID(); 
00073   string testType  = names->getTestType(); 
00074   string runID = names->getRunID();
00075   
00076   
00077 
00078   
00079   
00080   
00081  
00082   TFile *storage_file = new TFile(filename.c_str(),"update");
00083   
00084   
00085 
00086   
00087 
00088 
00089   
00090   
00091     
00092     
00093     
00094     
00095     TDirectory *this_run = (TDirectory*) gDirectory->Get(runID.c_str());
00096     
00097     
00098     if (!this_run) {
00099       
00100       this_run = storage_file->mkdir(runID.c_str());
00101       
00102     }
00103     storage_file->GetListOfKeys()->Print();
00104     this_run->cd();  
00105     
00106    
00107     
00108     TObject* pers_runnumber = gDirectory->FindObjectAny(runID.c_str()); 
00109     if (!pers_runnumber) {
00110       double frunNumber = runNumber;
00111       TVector run(1,1,frunNumber, "END");
00112       run.Write(runID.c_str());
00113     }
00114     
00115     
00116     
00117     
00118     TDirectory* this_module = (TDirectory*) gDirectory->Get(moduleID.c_str()); 
00119     
00120     if (!this_module) {
00121       
00122       this_module =gDirectory ->mkdir(moduleID.c_str());
00123     }
00124     
00125     
00126     
00127     
00128     this_module->cd();  
00129     TDirectory* this_testType = (TDirectory*) gDirectory->Get(testType.c_str());
00130     
00131     
00132     if (!this_testType) {
00133       
00134       this_testType = gDirectory->mkdir(testType.c_str());
00135     }
00136     this_testType->cd();
00137 
00138 
00139     
00140 
00141     
00142     if(testSummary != NULL) {
00143       
00144       TObject* pers_testSummary = gDirectory->FindObjectAny(names->getTestSummaryID().c_str());
00145       if (!pers_testSummary) {
00146     testSummary->Write(names->getTestSummaryID().c_str());
00147     
00148       }
00149     }
00150    
00151 
00152 
00153 
00154 
00155     
00156     
00157     storage_file->Close();
00158     delete storage_file;
00159     
00160 
00161 
00162 
00163 
00164 
00165 
00166 
00167 }
00168 
00169 
00170 
00171 
00172 
00173 void ArchNMaskTestResult::SaveNMask() {
00174 
00175   SaveTestDataOnly();
00176   SaveNMaskTestDataOnly();
00177   SaveRawScans();
00178   SaveFitScans();
00179   AddTestToIndex();
00180 
00181 }
00182 
00183 
00184 
00185 void ArchNMaskTestResult::TestSummary(NMaskTestResult & NMtest) {
00186   
00187   ostringstream datastream;
00188   shared_ptr<const SctData::TestSummary::SummaryWriter> writer = 
00189     SctData::TestSummary::SummaryManager::instance().getWriter(NMtest.getClassName());
00190   writer->writeHeader(NMtest, datastream);
00191   writer->write(NMtest, datastream);
00192   string myString = datastream.str();
00193   
00194 
00195   testSummary = new TObjString(myString.c_str());
00196 
00197   
00198 
00199 
00200   return;
00201 
00202 
00203 }
00204