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

ArchTimeWalkTestResult.cpp

00001 #include "ArchTimeWalkTestResult.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 <boost/shared_ptr.hpp>
00022 #include "SummaryWriter/SummaryWriter.h"
00023 #include "SummaryWriter/SummaryManager.h"
00024 
00025 
00026 bool ArchTimeWalkTestResult::inMap = ArchivingManager::instance().addTestArchiver("SctData::TimeWalkTestResult", shared_ptr<ArchTestResult>(new ArchTimeWalkTestResult()));  
00027 
00028 /***********************  Constructor  *************** */
00029 
00030 ArchTimeWalkTestResult::ArchTimeWalkTestResult(): ArchTestResult()  {
00031 
00032   //cout<< "I am in the ArchTimeWalkTestResult Default Constructor"<< endl;
00033   
00034   
00035   
00036 }
00037 
00038 
00039 ArchTimeWalkTestResult::ArchTimeWalkTestResult(shared_ptr<TimeWalkTestResult> TWtest): ArchTestResult(TWtest)  {
00040 
00041   //cout<< "I am in the ArchTimeWalkTestResult Constructor"<< endl;
00042   
00043   /*--- Initialisation ---*/
00044 
00045   for (unsigned int i = 0; i<12;i++) { 
00046     //*----status_direct:
00047     timewalk.push_back(TWtest->getChipResult(i).timewalk);
00048     shared_ptr<TVector> tmp_v_timewalk (new TVector(1,1,TWtest->getChipResult(i).timewalk,"END"));
00049     v_timewalk.push_back(tmp_v_timewalk);
00050 
00051 
00052     //*----calibration:
00053     calibration.push_back(TWtest->getChipResult(i).calibration);
00054     shared_ptr<TVector> tmp_v_calibration (new TVector(1,1,TWtest->getChipResult(i).calibration,"END"));
00055     v_calibration.push_back(tmp_v_calibration);
00056 
00057 
00058   }
00059 
00060 
00061      
00062 
00063 
00064 
00065   //Retrieve Test Summary from IS
00066   try{
00067     TestSummary(TWtest);
00068   } catch(...) {
00069     cout<<" ERROR in retrieving Test Summary from IS" <<endl;
00070   }
00071 
00072 
00073 
00074 }
00075 
00076 
00077 
00078 /**********************  Other Member Functions  *********************/
00079 
00080 
00081 ArchTimeWalkTestResult::~ArchTimeWalkTestResult()  {
00082   
00083   //cout << "I am in the ArchTimeWalkTestResult destructor" << endl;
00084   
00085 
00086   
00087 }
00088 
00089 
00090 
00091 void ArchTimeWalkTestResult::SaveTimeWalkTestDataOnly() {
00092 
00093   cout<<"Saving TimeWalkTestData "<<endl;
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 timewalkID = names->getTimewalkID();
00101   string calibrationID = names->getCalibrationID();
00102  
00103 
00104   
00105   /* OPENING TEST FILE  */
00106   cout << "Opening file..."<<endl; 
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()); //Can be made using FindAnyObject
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     
00166     
00167     /* Saving timewalk as a TVector */
00168     //cout << "I am Saving  as  TVectorD's" << endl;
00169     //TObject* pers_timewalk = gDirectory->FindObjectAny(timewalkID.c_str()); 
00170     TDirectory* pers_timewalk = (TDirectory*) gDirectory->Get(timewalkID.c_str());
00171     if (!pers_timewalk) {
00172       //cout << "The timewalk never saved before...saving now"<<endl;
00173       pers_timewalk = this_testType->mkdir(timewalkID.c_str());
00174       
00175     }
00176     pers_timewalk->cd();
00177 
00178     int chipN=0;
00179     for (vector<shared_ptr<TVector> >::iterator i = v_timewalk.begin(); i!=v_timewalk.end(); i++) {
00180       (*i)->Write(names->getTimewalkID(chipN).c_str());
00181       ++chipN;
00182     } 
00183     this_testType->cd();
00184 
00185 
00186     /* Saving calibration  as a TVector */
00187     //cout << "I am Saving calibration as  TVectorD's" << endl;
00188     //TObject* pers_calibration = gDirectory->FindObjectAny(calibrationID.c_str()); 
00189      TDirectory* pers_calibration = (TDirectory*) gDirectory->Get(calibrationID.c_str());
00190     if (!pers_calibration) {
00191       //cout << "The calibration never saved before...saving now"<<endl;
00192       pers_calibration = this_testType->mkdir(calibrationID.c_str());
00193     }
00194     pers_calibration->cd();
00195 
00196     chipN=0;
00197     for (vector<shared_ptr<TVector> >::iterator i = v_timewalk.begin(); i!=v_timewalk.end(); i++) {
00198       (*i)->Write(names->getCalibrationID(chipN).c_str());
00199       ++chipN;
00200     } 
00201     this_testType->cd();
00202     
00203 
00204 
00205     //Save TestSummery (if it has been retrieved)
00206     if(testSummary != NULL) {
00207       //cout<<"testSummary != NULL...";
00208       TObject* pers_testSummary = gDirectory->FindObjectAny(names->getTestSummaryID().c_str());
00209       if (!pers_testSummary) {
00210     testSummary->Write(names->getTestSummaryID().c_str());
00211     //cout<<"testSummary SAVED"<<endl;
00212       }
00213     }
00214    
00215 
00216 
00217 
00218 
00219     /* CLOSING FILE  */
00220     //cout << "I am Closing File " << endl;
00221     storage_file->Close();
00222     delete storage_file;
00223     //cout << "File closed " << endl;
00224 
00225 
00226 
00227 
00228 }
00229 
00230 
00231 
00232 
00233 
00234 void ArchTimeWalkTestResult::Save() {
00235 
00236   ArchTestResult::Save();
00237   SaveTimeWalkTestDataOnly();
00238   //SaveRawScans();
00239   //SaveFitScans();
00240   AddTestToIndex();
00241 
00242 }
00243 
00244 
00245 
00246 void ArchTimeWalkTestResult::TestSummary(shared_ptr<TimeWalkTestResult> TWtest) {
00247   
00248   ostringstream datastream;
00249   shared_ptr<const SctData::TestSummary::SummaryWriter> writer = 
00250     SctData::TestSummary::SummaryManager::instance().getWriter(TWtest->getClassName());
00251   writer->writeHeader(*(TWtest.get()), datastream);
00252   writer->write(*(TWtest.get()), datastream);
00253   string myString = datastream.str();
00254   //cout<< "TestSummary = " << myString;
00255 
00256   testSummary = new TObjString(myString.c_str());
00257 
00258   
00259 
00260 
00261   return;
00262 
00263 
00264 }
00265 

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