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

ArchTrimRangeTestResult.cpp

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

Generated on Thu Jul 15 09:50:43 2004 for SCT DAQ/DCS Software - C++ by doxygen 1.3.5