00001 #include "ArchTrimRangeTestResult.h"
00002 #include <is/isinfo.h>
00003 #include <iostream>
00004 #include <vector>
00005 #include "SctData/Stat.h"
00006 #include "Sct/SctParameters.h"
00007 #include <TFile.h>
00008 #include <TDirectory.h>
00009 #include <TObject.h>
00010 #include <TVector.h>
00011 #include <TVectorD.h>
00012 #include "SummaryWriter/SummaryWriter.h"
00013 #include "SummaryWriter/SummaryManager.h"
00014
00015
00016 using namespace SctData;
00017
00018
00019
00020
00021 ArchTrimRangeTestResult::ArchTrimRangeTestResult(): ArchTestResult() {
00022
00023
00024
00025
00026
00027 }
00028
00029
00030 ArchTrimRangeTestResult::ArchTrimRangeTestResult(TrimRangeTestResult& trimtest): ArchTestResult(trimtest) {
00031
00032
00033
00034
00035 TGraph* g = new TGraph();
00036 TF1* f = new TF1("tf1","pol1");
00037 for (unsigned int ichip = 0; ichip < nChipModule; ++ichip) {
00038 for (unsigned ichannel=0; ichannel<nChannelChip; ++ichannel){
00039 Stat<TrimRangeTestResult::TrimData> trim = trimtest.chipTrimData[ichip]->channelData.getAt(ichannel);
00040
00041
00042 g->SetMarkerColor(ichannel);
00043 f->SetLineColor(ichannel);
00044 g->Set(trim.value.graph.size());
00045 for (unsigned ipt=0; ipt<trim.value.graph.size(); ++ipt){
00046 g->SetPoint(ipt,trim.value.graph[ipt].first, trim.value.graph[ipt].second);
00047 }
00048 f->SetParameters(trim.value.p0,trim.value.p1);
00049
00050 chipTrim.push_back(g);
00051 chipTrimFit.push_back(f);
00052
00053
00054 }
00055
00056
00057 }
00058
00059
00060
00061 try{
00062 TestSummary(trimtest);
00063 } catch(...) {
00064 cout<<" ERROR in retrieving Test Summary from IS" <<endl;
00065 }
00066
00067 }
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077 ArchTrimRangeTestResult::~ArchTrimRangeTestResult() {
00078
00079
00080
00081
00082
00083 }
00084
00085
00086
00087 void ArchTrimRangeTestResult::SaveTrimRangeTestDataOnly() {
00088
00089
00090 cout<<"Saving TrimRangeTestData "<<endl;
00091
00092
00093
00094 string filename = names->getfilename();
00095 string moduleID = names->getModuleID();
00096 string testType = names->getTestType();
00097 string runID = names->getRunID();
00098
00099
00100
00101
00102
00103
00104
00105
00106 TFile *storage_file = new TFile(filename.c_str(),"update");
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119 TDirectory *this_run = (TDirectory*) gDirectory->Get(runID.c_str());
00120
00121
00122 if (!this_run) {
00123
00124 this_run = storage_file->mkdir(runID.c_str());
00125
00126 }
00127 storage_file->GetListOfKeys()->Print();
00128 this_run->cd();
00129
00130
00131
00132 TObject* pers_runnumber = gDirectory->FindObjectAny(runID.c_str());
00133 if (!pers_runnumber) {
00134 double frunNumber = runNumber;
00135 TVector run(1,1,frunNumber, "END");
00136 run.Write(runID.c_str());
00137 }
00138
00139
00140
00141
00142 TDirectory* this_module = (TDirectory*) gDirectory->Get(moduleID.c_str());
00143
00144 if (!this_module) {
00145
00146 this_module =gDirectory ->mkdir(moduleID.c_str());
00147 }
00148
00149
00150
00151
00152 this_module->cd();
00153 TDirectory* this_testType = (TDirectory*) gDirectory->Get(testType.c_str());
00154
00155
00156 if (!this_testType) {
00157
00158 this_testType = gDirectory->mkdir(testType.c_str());
00159 }
00160 this_testType->cd();
00161
00162
00163
00164 int chipN = 0;
00165
00166 for (vector<TGraph*>::iterator i = chipTrim.begin(); i!=chipTrim.end(); i++) {
00167 (*i)->Write(names->getChipTrimID(chipN).c_str());
00168 chipN++;
00169 }
00170
00171
00172
00173
00174 chipN = 0;
00175 for (vector<TF1*>::iterator i = chipTrimFit.begin(); i!=chipTrimFit.end(); i++) {
00176 (*i)->Write(names->getChipTrimFitID(chipN).c_str());
00177 chipN++;
00178 }
00179
00180
00181
00182 if(testSummary != NULL) {
00183
00184 TObject* pers_testSummary = gDirectory->FindObjectAny(names->getTestSummaryID().c_str());
00185 if (!pers_testSummary) {
00186 testSummary->Write(names->getTestSummaryID().c_str());
00187
00188 }
00189 }
00190
00191
00192
00193
00194 storage_file->Close();
00195 delete storage_file;
00196
00197
00198
00199
00200
00201 }
00202
00203
00204
00205 void ArchTrimRangeTestResult::SaveTrimRange() {
00206
00207
00208 SaveTestDataOnly();
00209 SaveTrimRangeTestDataOnly();
00210 SaveRawScans();
00211 SaveFitScans();
00212 AddTestToIndex();
00213
00214
00215
00216 }
00217
00218
00219 void ArchTrimRangeTestResult::TestSummary(TrimRangeTestResult & trimtest) {
00220
00221 ostringstream datastream;
00222 shared_ptr<const SctData::TestSummary::SummaryWriter> writer =
00223 SctData::TestSummary::SummaryManager::instance().getWriter(trimtest.getClassName());
00224 writer->writeHeader(trimtest, datastream);
00225 writer->write(trimtest, datastream);
00226 string myString = datastream.str();
00227
00228
00229 testSummary = new TObjString(myString.c_str());
00230
00231
00232
00233
00234 return;
00235
00236
00237 }
00238
00239
00240