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