00001 #include "ArchNoiseOccupancyTestResult.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 "SummaryWriter/SummaryWriter.h"
00021 #include "SummaryWriter/SummaryManager.h"
00022
00023 #include "Sct/SctParameters.h"
00024
00025 using namespace Sct;
00026 using namespace SctData;
00027
00028
00029
00030
00031
00032
00033
00034 ArchNoiseOccupancyTestResult::ArchNoiseOccupancyTestResult(): ArchTestResult() {
00035
00036
00037
00038
00039
00040 }
00041
00042
00043 ArchNoiseOccupancyTestResult::ArchNoiseOccupancyTestResult(NoiseOccupancyTestResult& NOtest): ArchTestResult(NOtest) {
00044
00045
00046
00047
00048 double x[nChipModule];
00049
00050
00051 for (unsigned int i = 0; i<nChipModule;i++) {
00052 ChipNOResult& result = NOtest.getChipResult(i);
00053 chipNOGraph.push_back(result.graph.get());
00054 chipNOFit.push_back(result.fit.get());
00055 x[i] = result.getNoise() ;
00056 }
00057
00058 vchipNoise = new TVectorD(12 ,x);
00059
00060
00061
00062 try{
00063 TestSummary(NOtest);
00064 } catch(...) {
00065 cout<<" ERROR in retrieving Test Summary from IS" <<endl;
00066 }
00067
00068
00069 }
00070
00071
00072
00073
00074
00075 ArchNoiseOccupancyTestResult::~ArchNoiseOccupancyTestResult() {
00076
00077
00078
00079
00080
00081 }
00082
00083
00084
00085
00086
00087 void ArchNoiseOccupancyTestResult::SaveNOTestDataOnly() {
00088
00089 cout<<"Saving NoiseOccupancyTestData "<<endl;
00090
00091
00092
00093 string filename = names->getfilename();
00094 string moduleID = names->getModuleID();
00095 string testType = names->getTestType();
00096 string runID = names->getRunID();
00097 string vchipNoiseID = names->getChipNONoiseID();
00098 string chipNOFitID = names->getChipNOFitID();
00099 string chipNOGraphID = names->getChipNOGraphID();
00100
00101
00102
00103
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
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 TDirectory* pers_ChipNOFit = (TDirectory*) gDirectory->Get(chipNOFitID.c_str());
00165 if (!pers_ChipNOFit) {
00166
00167 pers_ChipNOFit = this_testType->mkdir(chipNOFitID.c_str());
00168
00169 }
00170 pers_ChipNOFit->cd();
00171
00172 unsigned int chipN=0;
00173 for (vector<TF1*>::iterator i = chipNOFit.begin(); i!=chipNOFit.end(); i++) {
00174 (*i)->Write(names->getChipNOFitID(chipN).c_str());
00175 ++chipN;
00176 }
00177 this_testType->cd();
00178
00179
00180
00181 TDirectory* pers_ChipNOGraph = (TDirectory*) gDirectory->Get(chipNOGraphID.c_str());
00182 if (!pers_ChipNOGraph) {
00183
00184 pers_ChipNOGraph = this_testType->mkdir(chipNOGraphID.c_str());
00185
00186 }
00187 pers_ChipNOGraph->cd();
00188 chipN=0;
00189 for (vector<TGraph*>::iterator i = chipNOGraph.begin(); i!=chipNOGraph.end(); i++) {
00190 (*i)->Write(names->getChipNOGraphID(chipN).c_str());
00191 ++chipN;
00192 }
00193 this_testType->cd();
00194
00195
00196
00197
00198
00199
00200 vchipNoise->Write(vchipNoiseID.c_str());
00201
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 storage_file->Close();
00219 delete storage_file;
00220
00221
00222
00223
00224
00225 }
00226
00227
00228
00229 void ArchNoiseOccupancyTestResult::SaveNoiseOccupancy() {
00230
00231
00232 SaveTestDataOnly();
00233 SaveNOTestDataOnly();
00234 SaveRawScans();
00235 SaveFitScans();
00236 AddTestToIndex();
00237
00238
00239
00240
00241
00242
00243 }
00244
00245
00246
00247 void ArchNoiseOccupancyTestResult::TestSummary(NoiseOccupancyTestResult & NOtest) {
00248
00249 ostringstream datastream;
00250 shared_ptr<const SctData::TestSummary::SummaryWriter> writer =
00251 SctData::TestSummary::SummaryManager::instance().getWriter(NOtest.getClassName());
00252 writer->writeHeader(NOtest, datastream);
00253 writer->write(NOtest, datastream);
00254 string myString = datastream.str();
00255
00256
00257 testSummary = new TObjString(myString.c_str());
00258
00259
00260
00261
00262 return;
00263
00264
00265 }
00266