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

ArchStrobeDelayTestResult.cpp

00001 #include "ArchStrobeDelayTestResult.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 
00025 bool ArchStrobeDelayTestResult::inMap = ArchivingManager::instance().addTestArchiver("SctData::StrobeDelayTestResult", shared_ptr<ArchTestResult>(new ArchStrobeDelayTestResult()));  
00026 
00027 
00028 /***********************  Constructor  *************** */
00029 
00030 ArchStrobeDelayTestResult::ArchStrobeDelayTestResult(): ArchTestResult()  {
00031 
00032   //cout<< "I am in the ArchStrobeDelayTestResult Default Constructor"<< endl;
00033   
00034   
00035   
00036 }
00037 
00038 
00039 ArchStrobeDelayTestResult::ArchStrobeDelayTestResult(shared_ptr<StrobeDelayTestResult> SDtest): ArchTestResult(SDtest)  {
00040 
00041   //cout<< "I am in the ArchStrobeDelayTestResult Constructor"<< endl;
00042   
00043   /*--- Initialisation ---*/
00044 
00045   fraction = SDtest->getFraction();
00046 
00047   for (unsigned int i = 0; i<SDtest->getNOptima();i++) { 
00048     optima.push_back(SDtest->getOptimum(i));
00049   }
00050 
00051 
00052   //Save fraction as TVectorD's      
00053   vfraction = new TVectorD(1,1,fraction,"END");
00054       
00055   //Save optima as TVectorD's  
00056   double x[12];
00057   for(unsigned int i=0;i<SDtest->getNOptima();++i) {
00058     x[i] = SDtest->getOptimum(i) ;
00059   }
00060   voptima = new TVectorD(SDtest->getNOptima(),x);
00061 
00062 
00063 
00064   //Retrieve Test Summary from IS
00065   try{
00066     TestSummary(SDtest);
00067   } catch(...) {
00068     cout<<" ERROR in retrieving Test Summary from IS" <<endl;
00069   }
00070 
00071 
00072 
00073 }
00074 
00075 
00076 
00077 /**********************  Other Member Functions  *********************/
00078 
00079 
00080 ArchStrobeDelayTestResult::~ArchStrobeDelayTestResult()  {
00081   
00082   //cout << "I am in the ArchStrobeDelayTestResult destructor" << endl;
00083   
00084 
00085   
00086 }
00087 
00088 
00089 
00090 void ArchStrobeDelayTestResult::SaveStrobeDelayTestDataOnly() {
00091 
00092   cout<<"Saving StrobeDelayTestData "<<endl;
00093   //TO DO : Save time and date of first and last saving  
00094 
00095   string filename = names->getfilename();
00096   string moduleID = names->getModuleID(); 
00097   string testType  = names->getTestType(); 
00098   string runID = names->getRunID();
00099   string vfractionID = names->getFractionID();
00100   string voptimaID = names->getOptimaID();
00101   
00102 
00103   
00104   /* OPENING TEST FILE  */
00105   //cout << "Opening file..."<<endl; 
00106  
00107   TFile *storage_file = new TFile(filename.c_str(),"update");
00108   //storage_file->ls();
00109   //cout << "The file .root succesfully open"<<endl; 
00110 
00111   
00112 
00113 
00114   /* CREATING DIRECTORIES and SAVING DATA  */
00115   
00116     
00117     /* Making RunNumber   */
00118     //cout<<"I am making RunNumber Dir"<<endl;
00119     //storage_file->GetListOfKeys()->Print();
00120     TDirectory *this_run = (TDirectory*) gDirectory->Get(runID.c_str());
00121     //cout<<"The RUN is "<< runID <<endl;
00122     
00123     if (!this_run) {
00124       //cout<<"This NEW run "<< runID <<" doesn't exist"<<endl;
00125       this_run = storage_file->mkdir(runID.c_str());
00126       //cout<<"New RunNumber Dir made "<<endl;
00127     }
00128     storage_file->GetListOfKeys()->Print();
00129     this_run->cd();  //make this_run the current directory
00130     
00131    
00132     /* Saving RunNumber as a TVector: it is saved only once, just the first time   */
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     /* Making moduleNumber   */
00142     
00143     TDirectory* this_module = (TDirectory*) gDirectory->Get(moduleID.c_str()); //Can be made using FindAnyObject
00144     //cout<<"The MODULE is "<< moduleID <<endl;
00145     if (!this_module) {
00146       //cout<<"This NEW module "<< moduleID <<" doesn't exist"<<endl;
00147       this_module =gDirectory ->mkdir(moduleID.c_str());
00148     }
00149     
00150     
00151     /* Making TestType   */
00152     //cout<<"I am making TestType Dir "<<endl;
00153     this_module->cd();  //make this_module the current directory 
00154     TDirectory* this_testType = (TDirectory*) gDirectory->Get(testType.c_str());
00155     //cout<<"The test Type is "<< testType <<endl;
00156     
00157     if (!this_testType) {
00158       //cout<<"This NEW test "<< testType <<" doesn't exist"<<endl;
00159       this_testType = gDirectory->mkdir(testType.c_str());
00160     }
00161     this_testType->cd();
00162 
00163 
00164     
00165     
00166     /* Saving vfraction and voptima  as a TVector */
00167     //cout << "I am Saving vfraction as  TVectorD's" << endl;
00168     TObject* pers_vfraction = gDirectory->FindObjectAny(vfractionID.c_str()); 
00169     if (!pers_vfraction) {
00170       //cout << "The vfraction never saved before...saving now"<<endl;
00171       vfraction->Write(vfractionID.c_str());
00172     }
00173     
00174     //cout << "I am Saving voptima as  TVectorD's" << endl;
00175     TObject* pers_voptima = gDirectory->FindObjectAny(voptimaID.c_str()); 
00176     if (!pers_voptima) {
00177       //cout << "The voptima never saved before...saving now"<<endl;
00178       voptima->Write(voptimaID.c_str());
00179     }
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 
00195 
00196     /* CLOSING FILE  */
00197     //cout << "I am Closing File " << endl;
00198     storage_file->Close();
00199     delete storage_file;
00200     //cout << "File closed " << endl;
00201 
00202 
00203 
00204 
00205 
00206 
00207 
00208 }
00209 
00210 
00211 
00212 
00213 
00214 void ArchStrobeDelayTestResult::Save() {
00215 
00216   ArchTestResult::Save();
00217   SaveStrobeDelayTestDataOnly();
00218   //SaveRawScans();
00219   //SaveFitScans();
00220   AddTestToIndex();
00221 
00222 }
00223 
00224 
00225 
00226 void ArchStrobeDelayTestResult::TestSummary(shared_ptr<StrobeDelayTestResult> SDtest) {
00227   
00228   ostringstream datastream;
00229   shared_ptr<const SctData::TestSummary::SummaryWriter> writer = 
00230     SctData::TestSummary::SummaryManager::instance().getWriter(SDtest->getClassName());
00231   writer->writeHeader(*(SDtest.get()), datastream);
00232   writer->write(*(SDtest.get()), datastream);
00233   string myString = datastream.str();
00234   //cout<< "TestSummary = " << myString;
00235 
00236   testSummary = new TObjString(myString.c_str());
00237 
00238   
00239 
00240 
00241   return;
00242 
00243 
00244 }
00245 

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