Main Page   Modules   Namespace List   Class Hierarchy   Data Structures   File List   Namespace Members   Data Fields   Globals   Related Pages  

ArchTrimRangeTestResult.cpp

Go to the documentation of this file.
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 /***********************  Constructor  *************** */
00020 
00021 ArchTrimRangeTestResult::ArchTrimRangeTestResult(): ArchTestResult()  {
00022 
00023   //cout<< "I am in the ArchTrimRangeTestResult Default Constructor"<< endl;
00024   
00025   
00026   
00027 }
00028   
00029   
00030 ArchTrimRangeTestResult::ArchTrimRangeTestResult(TrimRangeTestResult& trimtest): ArchTestResult(trimtest)  {
00031 
00032   //cout<< "I am in the ArchTrimRangeTestResult Constructor"<< endl;
00033   
00034   /*--- Initialisation ---*/
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       //TGraph* g = new TGraph();
00041       //TF1* f = new TF1("tf1","pol1");
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   //Retrieve Test Summary from IS
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 /**********************  Other Member Functions  *********************/
00076 
00077 ArchTrimRangeTestResult::~ArchTrimRangeTestResult()  {
00078   
00079   //cout << "I am in the ArchTrimRangeTestResult destructor" << endl;
00080   
00081 
00082   
00083 }
00084 
00085 
00086 
00087 void ArchTrimRangeTestResult::SaveTrimRangeTestDataOnly() {
00088 
00089 
00090   cout<<"Saving TrimRangeTestData "<<endl;
00091      
00092   //TO DO : Save time and date of first and last saving  
00093   
00094   string filename = names->getfilename();
00095   string moduleID = names->getModuleID(); 
00096   string testType  = names->getTestType(); 
00097   string runID = names->getRunID();
00098   //string chipTrimID = names->getChipTrimID();
00099   //string chipTrimFitID = names->getChipTrimFitID();
00100 
00101 
00102   /* OPENING TEST FILE  */
00103   //cout << "Opening file..."<<endl; 
00104  
00105 
00106   TFile *storage_file = new TFile(filename.c_str(),"update");
00107   //storage_file->ls();
00108   //cout << "The file .root succesfully open"<<endl; 
00109 
00110   
00111 
00112 
00113   /* CREATING DIRECTORIES and SAVING DATA  */
00114   
00115     
00116     /* Making RunNumber   */
00117     //cout<<"I am making RunNumber Dir"<<endl;
00118     //storage_file->GetListOfKeys()->Print();
00119     TDirectory *this_run = (TDirectory*) gDirectory->Get(runID.c_str());
00120     //cout<<"The RUN is "<< runID <<endl;
00121     
00122     if (!this_run) {
00123       //cout<<"This NEW run "<< runID <<" doesn't exist"<<endl;
00124       this_run = storage_file->mkdir(runID.c_str());
00125       //cout<<"New RunNumber Dir made "<<endl;
00126     }
00127     storage_file->GetListOfKeys()->Print();
00128     this_run->cd();  //make this_run the current directory
00129     
00130    
00131     /* Saving RunNumber as a TVector: it is saved only once, just the first time   */
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     /* Making moduleNumber   */
00141     
00142     TDirectory* this_module = (TDirectory*) gDirectory->Get(moduleID.c_str()); 
00143     //cout<<"The MODULE is "<< moduleID <<endl;
00144     if (!this_module) {
00145       //cout<<"This NEW module "<< moduleID <<" doesn't exist"<<endl;
00146       this_module =gDirectory ->mkdir(moduleID.c_str());
00147     }
00148     
00149     
00150     /* Making TestType   */
00151     //cout<<"I am making TestType Dir "<<endl;
00152     this_module->cd();  //make this_module the current directory 
00153     TDirectory* this_testType = (TDirectory*) gDirectory->Get(testType.c_str());
00154     //cout<<"The test Type is "<< testType <<endl;
00155     
00156     if (!this_testType) {
00157       //cout<<"This NEW test "<< testType <<" doesn't exist"<<endl;
00158       this_testType = gDirectory->mkdir(testType.c_str());
00159     }
00160     this_testType->cd();
00161 
00162 
00163     /* Saving chipTrim */
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     /* Saving chipTrimFit */
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     //Save TestSummery (if it has been retrieved)
00182     if(testSummary != NULL) {
00183       //cout<<"testSummary != NULL...";
00184       TObject* pers_testSummary = gDirectory->FindObjectAny(names->getTestSummaryID().c_str());
00185       if (!pers_testSummary) {
00186     testSummary->Write(names->getTestSummaryID().c_str());
00187     //cout<<"testSummary SAVED"<<endl;
00188       }
00189     }
00190  
00191     
00192     /* CLOSING FILE  */
00193     //cout << "I am Closing File " << endl;
00194     storage_file->Close();
00195     delete storage_file;
00196     //cout << "File closed " << endl;
00197 
00198 
00199 
00200 
00201 }
00202 
00203 
00204 
00205 void ArchTrimRangeTestResult::SaveTrimRange() {
00206 
00207   //cout << "I am in SaveTrimRange() " <<endl;
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   //cout<< "TestSummary = " << myString;
00228 
00229   testSummary = new TObjString(myString.c_str());
00230 
00231   
00232 
00233 
00234   return;
00235 
00236 
00237 }
00238 
00239 
00240 

Generated on Mon Dec 15 19:35:58 2003 for SCT DAQ/DCS Software by doxygen1.3-rc3