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