00001 #include "ArchTimeWalkTestResult.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 <TObjArray.h>
00009 #include <TString.h>
00010 #include <TObjString.h>
00011 #include <TVector.h>
00012 #include <TVectorD.h>
00013 #include <TH1.h>
00014 #include <TH2.h>
00015 #include <TCanvas.h>
00016 #include <TROOT.h>
00017 #include <is/isinfo.h>
00018 #include <iostream>
00019 #include <vector>
00020 #include <boost/shared_ptr.hpp>
00021 #include "SummaryWriter/SummaryWriter.h"
00022 #include "SummaryWriter/SummaryManager.h"
00023
00024
00025
00026
00027 ArchTimeWalkTestResult::ArchTimeWalkTestResult(): ArchTestResult() {
00028
00029
00030
00031
00032
00033 }
00034
00035
00036 ArchTimeWalkTestResult::ArchTimeWalkTestResult(TimeWalkTestResult& TWtest): ArchTestResult(TWtest) {
00037
00038
00039
00040
00041
00042 for (unsigned int i = 0; i<12;i++) {
00043
00044 timewalk.push_back(TWtest.getChipResult(i).timewalk);
00045 shared_ptr<TVector> tmp_v_timewalk (new TVector(1,1,TWtest.getChipResult(i).timewalk,"END"));
00046 v_timewalk.push_back(tmp_v_timewalk);
00047
00048
00049
00050 calibration.push_back(TWtest.getChipResult(i).calibration);
00051 shared_ptr<TVector> tmp_v_calibration (new TVector(1,1,TWtest.getChipResult(i).calibration,"END"));
00052 v_calibration.push_back(tmp_v_calibration);
00053
00054
00055 }
00056
00057
00058
00059
00060
00061
00062
00063 try{
00064 TestSummary(TWtest);
00065 } catch(...) {
00066 cout<<" ERROR in retrieving Test Summary from IS" <<endl;
00067 }
00068
00069
00070
00071 }
00072
00073
00074
00075
00076
00077
00078 ArchTimeWalkTestResult::~ArchTimeWalkTestResult() {
00079
00080
00081
00082
00083
00084 }
00085
00086
00087
00088 void ArchTimeWalkTestResult::SaveTimeWalkTestDataOnly() {
00089
00090 cout<<"Saving TimeWalkTestData "<<endl;
00091
00092
00093 string filename = names->getfilename();
00094 string moduleID = names->getModuleID();
00095 string testType = names->getTestType();
00096 string runID = names->getRunID();
00097 string timewalkID = names->getTimewalkID();
00098 string calibrationID = names->getCalibrationID();
00099
00100
00101
00102
00103 cout << "Opening file..."<<endl;
00104
00105 TFile *storage_file = new TFile(filename.c_str(),"update");
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118 TDirectory *this_run = (TDirectory*) gDirectory->Get(runID.c_str());
00119
00120
00121 if (!this_run) {
00122
00123 this_run = storage_file->mkdir(runID.c_str());
00124
00125 }
00126 storage_file->GetListOfKeys()->Print();
00127 this_run->cd();
00128
00129
00130
00131 TObject* pers_runnumber = gDirectory->FindObjectAny(runID.c_str());
00132 if (!pers_runnumber) {
00133 double frunNumber = runNumber;
00134 TVector run(1,1,frunNumber, "END");
00135 run.Write(runID.c_str());
00136 }
00137
00138
00139
00140
00141 TDirectory* this_module = (TDirectory*) gDirectory->Get(moduleID.c_str());
00142
00143 if (!this_module) {
00144
00145 this_module =gDirectory ->mkdir(moduleID.c_str());
00146 }
00147
00148
00149
00150
00151 this_module->cd();
00152 TDirectory* this_testType = (TDirectory*) gDirectory->Get(testType.c_str());
00153
00154
00155 if (!this_testType) {
00156
00157 this_testType = gDirectory->mkdir(testType.c_str());
00158 }
00159 this_testType->cd();
00160
00161
00162
00163
00164
00165
00166
00167 TDirectory* pers_timewalk = (TDirectory*) gDirectory->Get(timewalkID.c_str());
00168 if (!pers_timewalk) {
00169
00170 pers_timewalk = this_testType->mkdir(timewalkID.c_str());
00171
00172 }
00173 pers_timewalk->cd();
00174
00175 int chipN=0;
00176 for (vector<shared_ptr<TVector> >::iterator i = v_timewalk.begin(); i!=v_timewalk.end(); i++) {
00177 (*i)->Write(names->getTimewalkID(chipN).c_str());
00178 ++chipN;
00179 }
00180 this_testType->cd();
00181
00182
00183
00184
00185
00186 TDirectory* pers_calibration = (TDirectory*) gDirectory->Get(calibrationID.c_str());
00187 if (!pers_calibration) {
00188
00189 pers_calibration = this_testType->mkdir(calibrationID.c_str());
00190 }
00191 pers_calibration->cd();
00192
00193 chipN=0;
00194 for (vector<shared_ptr<TVector> >::iterator i = v_timewalk.begin(); i!=v_timewalk.end(); i++) {
00195 (*i)->Write(names->getCalibrationID(chipN).c_str());
00196 ++chipN;
00197 }
00198 this_testType->cd();
00199
00200
00201
00202
00203 if(testSummary != NULL) {
00204
00205 TObject* pers_testSummary = gDirectory->FindObjectAny(names->getTestSummaryID().c_str());
00206 if (!pers_testSummary) {
00207 testSummary->Write(names->getTestSummaryID().c_str());
00208
00209 }
00210 }
00211
00212
00213
00214
00215
00216
00217
00218 storage_file->Close();
00219 delete storage_file;
00220
00221
00222
00223
00224
00225 }
00226
00227
00228
00229
00230
00231 void ArchTimeWalkTestResult::SaveTimeWalk() {
00232
00233 SaveTestDataOnly();
00234 SaveTimeWalkTestDataOnly();
00235 SaveRawScans();
00236 SaveFitScans();
00237 AddTestToIndex();
00238
00239 }
00240
00241
00242
00243 void ArchTimeWalkTestResult::TestSummary(TimeWalkTestResult & TWtest) {
00244
00245 ostringstream datastream;
00246 shared_ptr<const SctData::TestSummary::SummaryWriter> writer =
00247 SctData::TestSummary::SummaryManager::instance().getWriter(TWtest.getClassName());
00248 writer->writeHeader(TWtest, datastream);
00249 writer->write(TWtest, datastream);
00250 string myString = datastream.str();
00251
00252
00253 testSummary = new TObjString(myString.c_str());
00254
00255
00256
00257
00258 return;
00259
00260
00261 }
00262