00001 #include "ArchTestResult.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 <iomanip>
00022 #include <fstream>
00023 #include <iostream>
00024
00025
00026 using namespace SctData;
00027 using namespace Sct;
00028 using boost::shared_ptr;
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 ArchTestResult::ArchTestResult(): Archiving() {
00043
00044
00045 runNumber = 0;
00046 moduleName = "0";
00047 NScans = 0;
00048 names = new ArchTestNames();
00049
00050 testSummary = NULL;
00051 }
00052
00053
00054 ArchTestResult::ArchTestResult(TestResult& test): Archiving() {
00055
00056
00057
00058
00059
00060
00061
00062 runNumber = test.getRunNumber();
00063 moduleName = test.getModuleName();
00064 testType = test.getClassName();
00065 NScans = test.getNScans ();
00066
00067 names = new ArchTestNames(runNumber, moduleName, testType);
00068
00069
00070
00071
00072 for (unsigned int i=0; i<NScans; i++) {
00073 unsigned int scanNumber = test.getScanNumberAt(i);
00074 string RawISName = Archiving::GetRawISUniqueID(runNumber, scanNumber, moduleName);
00075 rawScans.push_back(ISRetrieveRawScanResult(RawISName));
00076
00077
00078 if (testType != "SctData::PipelineTestResult" && testType != "SctData::FullBypassTestResult" && testType != "SctData::NMaskTestResult") {
00079 string FitISName = Archiving::GetFitISUniqueID(runNumber, scanNumber, moduleName);
00080 fitScans.push_back(ISRetrieveFitScanResult(FitISName));
00081 }
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091 }
00092
00093 defects = test.getDefects().getAllDefects();
00094
00095
00096 testSummary = NULL;
00097
00098
00099 }
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110 ArchTestResult::~ArchTestResult() {
00111
00112
00113
00114
00115
00116 }
00117
00118
00119
00120
00121 void ArchTestResult::SaveRawScans() {
00122
00123 cout << "Saving RawScans " << endl;
00124
00125
00126
00127
00128 for (vector<shared_ptr<const RawScanResult> >::iterator i = rawScans.begin(); i!=rawScans.end(); i++) {
00129
00130 const RawScanResult *raw = i->get();
00131
00132 ArchRawScanResult rscan(*raw);
00133 rscan.SetTestType(testType);
00134 rscan.SaveRawScan();
00135
00136 }
00137
00138
00139
00140
00141 }
00142
00143
00144
00145 void ArchTestResult::SaveFitScans() {
00146
00147 cout << "Saving FitScans " << endl;
00148
00149
00150 for (vector<shared_ptr<const FitScanResult> >::iterator i = fitScans.begin(); i!=fitScans.end(); i++) {
00151 const FitScanResult *fit = i->get();
00152 ArchFitScanResult fscan(*fit);
00153 fscan.SetTestType(testType);
00154 fscan.SaveFitScan();
00155
00156 }
00157
00158
00159 }
00160
00161
00162
00163
00164 void ArchTestResult::SaveTestDataOnly() {
00165
00166 cout<<" Saving TestData " << endl;
00167
00168
00169
00170
00171 string filename = names->getfilename();
00172 string moduleID = names->getModuleID();
00173 string moduleDefectsID = names->getModuleDefectsID();
00174 string testType = names->getTestType();
00175 string runID = names->getRunID();
00176 string DefectsID = names->getDefectsID();
00177
00178
00179
00180 cout << "Opening file..."<<endl;
00181
00182
00183 TFile *storage_file = new TFile(filename.c_str(),"update");
00184
00185 cout << "The file .root succesfully open"<<endl;
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196 TDirectory *this_run = (TDirectory*) gDirectory->Get(runID.c_str());
00197
00198
00199 if (!this_run) {
00200
00201 this_run = storage_file->mkdir(runID.c_str());
00202
00203 }
00204
00205 this_run->cd();
00206
00207
00208
00209 TObject* pers_runnumber = gDirectory->FindObjectAny(runID.c_str());
00210 if (!pers_runnumber) {
00211 double frunNumber = runNumber;
00212 TVector run(1,1,frunNumber, "END");
00213 run.Write(runID.c_str());
00214 }
00215
00216
00217
00218
00219 TDirectory* this_module = (TDirectory*) gDirectory->Get(moduleID.c_str());
00220
00221 if (!this_module) {
00222
00223 this_module =gDirectory ->mkdir(moduleID.c_str());
00224 }
00225
00226
00227 TDirectory* this_moduleDefects = (TDirectory*) gDirectory->Get(moduleDefectsID.c_str());
00228 if (!this_moduleDefects) {
00229
00230 this_moduleDefects =gDirectory ->mkdir(moduleDefectsID.c_str());
00231 }
00232
00233
00234 this_moduleDefects->cd();
00235 for (unsigned int i=0; i<defects.size(); ++i) {
00236 this_moduleDefects->cd();
00237
00238
00239 TDirectory* this_defect = (TDirectory*) gDirectory->Get(defects[i]->getName().c_str());
00240 if (!this_defect) {
00241 cout<<defects[i]->getName().c_str()<<" doesn't exist"<<endl;
00242 this_defect =gDirectory ->mkdir(defects[i]->getName().c_str());
00243 }
00244 this_defect->cd();
00245
00246 TObjString* sdefect = new TObjString(defects[i]->getDescription().c_str());
00247 sdefect->Write("Defect Desctiption");
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268 double first = defects[i]->getModuleElement().getFirst();
00269 double Nchannels = defects[i]->getModuleElement().getNChannels();
00270 double chipDefect = defects[i]->isChipDefect();
00271 double linkDefect = defects[i]->isLinkDefect();
00272
00273 TVector* vthisDefect = new TVector(0,3, first, Nchannels,chipDefect, linkDefect, "END");
00274 vthisDefect->Write("Defect");
00275
00276 delete sdefect;
00277 delete vthisDefect;
00278
00279
00280 }
00281
00282
00283
00284
00285
00286
00287
00288
00289 this_module->cd();
00290 TDirectory* this_testType = (TDirectory*) gDirectory->Get(testType.c_str());
00291
00292
00293 if (!this_testType) {
00294
00295 this_testType = gDirectory->mkdir(testType.c_str());
00296 }
00297 this_testType->cd();
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310 storage_file->Close();
00311 delete storage_file;
00312
00313 }
00314
00315
00316
00317
00318
00319
00320 void ArchTestResult::AddTestToIndex() {
00321
00322
00323
00324
00325 string index = names->getIndexFileName();
00326 ofstream index_file;
00327 index_file.open(index.c_str(),ios::app);
00328
00329
00330 string indexTestName = names->getRunID() + ".";
00331 indexTestName = indexTestName + names->getModuleID();
00332 indexTestName = indexTestName + ".";
00333 indexTestName = indexTestName + names->getTestType() + ".";
00334
00335
00336 index_file << indexTestName <<endl;
00337 cout << "Test appended to Index"<<endl;
00338
00339
00340
00341
00342 index_file.close();
00343
00344 }