00001 #include "ArchStrobeDelayTestResult.h"
00002 #include "ArchivingManager.h"
00003 #include <TFile.h>
00004 #include <TKey.h>
00005 #include <TDirectory.h>
00006 #include <TSystem.h>
00007 #include <TNamed.h>
00008 #include <TObject.h>
00009 #include <TObjArray.h>
00010 #include <TString.h>
00011 #include <TObjString.h>
00012 #include <TVector.h>
00013 #include <TVectorD.h>
00014 #include <TH1.h>
00015 #include <TH2.h>
00016 #include <TCanvas.h>
00017 #include <TROOT.h>
00018 #include <is/isinfo.h>
00019 #include <iostream>
00020 #include <vector>
00021 #include "SummaryWriter/SummaryWriter.h"
00022 #include "SummaryWriter/SummaryManager.h"
00023
00024
00025 bool ArchStrobeDelayTestResult::inMap = ArchivingManager::instance().addTestArchiver("SctData::StrobeDelayTestResult", shared_ptr<ArchTestResult>(new ArchStrobeDelayTestResult()));
00026
00027
00028
00029
00030 ArchStrobeDelayTestResult::ArchStrobeDelayTestResult(): ArchTestResult() {
00031
00032
00033
00034
00035
00036 }
00037
00038
00039 ArchStrobeDelayTestResult::ArchStrobeDelayTestResult(shared_ptr<StrobeDelayTestResult> SDtest): ArchTestResult(SDtest) {
00040
00041
00042
00043
00044
00045 fraction = SDtest->getFraction();
00046
00047 for (unsigned int i = 0; i<SDtest->getNOptima();i++) {
00048 optima.push_back(SDtest->getOptimum(i));
00049 }
00050
00051
00052
00053 vfraction = new TVectorD(1,1,fraction,"END");
00054
00055
00056 double x[12];
00057 for(unsigned int i=0;i<SDtest->getNOptima();++i) {
00058 x[i] = SDtest->getOptimum(i) ;
00059 }
00060 voptima = new TVectorD(SDtest->getNOptima(),x);
00061
00062
00063
00064
00065 try{
00066 TestSummary(SDtest);
00067 } catch(...) {
00068 cout<<" ERROR in retrieving Test Summary from IS" <<endl;
00069 }
00070
00071
00072
00073 }
00074
00075
00076
00077
00078
00079
00080 ArchStrobeDelayTestResult::~ArchStrobeDelayTestResult() {
00081
00082
00083
00084
00085
00086 }
00087
00088
00089
00090 void ArchStrobeDelayTestResult::SaveStrobeDelayTestDataOnly() {
00091
00092 cout<<"Saving StrobeDelayTestData "<<endl;
00093
00094
00095 string filename = names->getfilename();
00096 string moduleID = names->getModuleID();
00097 string testType = names->getTestType();
00098 string runID = names->getRunID();
00099 string vfractionID = names->getFractionID();
00100 string voptimaID = names->getOptimaID();
00101
00102
00103
00104
00105
00106
00107 TFile *storage_file = new TFile(filename.c_str(),"update");
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120 TDirectory *this_run = (TDirectory*) gDirectory->Get(runID.c_str());
00121
00122
00123 if (!this_run) {
00124
00125 this_run = storage_file->mkdir(runID.c_str());
00126
00127 }
00128 storage_file->GetListOfKeys()->Print();
00129 this_run->cd();
00130
00131
00132
00133 TObject* pers_runnumber = gDirectory->FindObjectAny(runID.c_str());
00134 if (!pers_runnumber) {
00135 double frunNumber = runNumber;
00136 TVector run(1,1,frunNumber, "END");
00137 run.Write(runID.c_str());
00138 }
00139
00140
00141
00142
00143 TDirectory* this_module = (TDirectory*) gDirectory->Get(moduleID.c_str());
00144
00145 if (!this_module) {
00146
00147 this_module =gDirectory ->mkdir(moduleID.c_str());
00148 }
00149
00150
00151
00152
00153 this_module->cd();
00154 TDirectory* this_testType = (TDirectory*) gDirectory->Get(testType.c_str());
00155
00156
00157 if (!this_testType) {
00158
00159 this_testType = gDirectory->mkdir(testType.c_str());
00160 }
00161 this_testType->cd();
00162
00163
00164
00165
00166
00167
00168 TObject* pers_vfraction = gDirectory->FindObjectAny(vfractionID.c_str());
00169 if (!pers_vfraction) {
00170
00171 vfraction->Write(vfractionID.c_str());
00172 }
00173
00174
00175 TObject* pers_voptima = gDirectory->FindObjectAny(voptimaID.c_str());
00176 if (!pers_voptima) {
00177
00178 voptima->Write(voptimaID.c_str());
00179 }
00180
00181
00182
00183
00184 if(testSummary != NULL) {
00185
00186 TObject* pers_testSummary = gDirectory->FindObjectAny(names->getTestSummaryID().c_str());
00187 if (!pers_testSummary) {
00188 testSummary->Write(names->getTestSummaryID().c_str());
00189
00190 }
00191 }
00192
00193
00194
00195
00196
00197
00198 storage_file->Close();
00199 delete storage_file;
00200
00201
00202
00203
00204
00205
00206
00207
00208 }
00209
00210
00211
00212
00213
00214 void ArchStrobeDelayTestResult::Save() {
00215
00216 ArchTestResult::Save();
00217 SaveStrobeDelayTestDataOnly();
00218
00219
00220 AddTestToIndex();
00221
00222 }
00223
00224
00225
00226 void ArchStrobeDelayTestResult::TestSummary(shared_ptr<StrobeDelayTestResult> SDtest) {
00227
00228 ostringstream datastream;
00229 shared_ptr<const SctData::TestSummary::SummaryWriter> writer =
00230 SctData::TestSummary::SummaryManager::instance().getWriter(SDtest->getClassName());
00231 writer->writeHeader(*(SDtest.get()), datastream);
00232 writer->write(*(SDtest.get()), datastream);
00233 string myString = datastream.str();
00234
00235
00236 testSummary = new TObjString(myString.c_str());
00237
00238
00239
00240
00241 return;
00242
00243
00244 }
00245