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

ArchTestResult.cpp

Go to the documentation of this file.
00001 #include "ArchTestResult.h"
00002 #include <TFile.h>
00003 #include <TKey.h>
00004 #include <TDirectory.h>
00005 #include <TSystem.h>
00006 #include <TNamed.h>
00007 #include <TObject.h>
00008 #include <TObjArray.h>
00009 #include <TString.h>
00010 #include <TObjString.h>
00011 #include <TVector.h>
00012 #include <TVectorD.h>
00013 #include <TH1.h>
00014 #include <TH2.h>
00015 #include <TCanvas.h>
00016 #include <TROOT.h>
00017 #include <is/isinfo.h>
00018 #include <iostream>
00019 #include <vector>
00020 #include <boost/shared_ptr.hpp>
00021 #include <iomanip>
00022 #include <fstream>
00023 #include <iostream>
00024 //#include "Sct/shared_ptr_utility.h"
00025 
00026 using namespace SctData;
00027 using namespace Sct;
00028 using boost::shared_ptr;
00029 
00030 
00031 
00032 //Global Variables:
00033 //TFile *storage_file = new TFile();
00034 
00035 
00036 
00037 /********************************** ArchScan Methods Definitions ************************/
00038 
00039 
00040 /***********************  Constructor  *************** */
00041 
00042 ArchTestResult::ArchTestResult(): Archiving()  {
00043 
00044   //cout<< "I am in the ArchTestResult Default Constructor"<< endl;
00045   runNumber = 0;
00046   moduleName = "0";
00047   NScans = 0; 
00048   names = new ArchTestNames();
00049   //names->SetTestType(testType);
00050   testSummary = NULL;
00051 }
00052   
00053   
00054 ArchTestResult::ArchTestResult(TestResult& test): Archiving()  {
00055 
00056   //cout<< "I am in the ArchTestResult Constructor"<< endl;
00057   
00058 
00059   /*--- Initialisation ---*/
00060 
00061   
00062   runNumber = test.getRunNumber();
00063   moduleName = test.getModuleName();
00064   testType = test.getClassName();
00065   NScans = test.getNScans ();
00066 
00067   names = new ArchTestNames(runNumber, moduleName, testType);
00068   
00069   
00070 
00071   //Retrieving Raw and Fitted Scans:
00072   for (unsigned int i=0; i<NScans; i++) {
00073     unsigned int scanNumber = test.getScanNumberAt(i);
00074     string RawISName = Archiving::GetRawISUniqueID(runNumber, scanNumber, moduleName);
00075     rawScans.push_back(ISRetrieveRawScanResult(RawISName));
00076     
00077     //Pipeline,FullBypass have no FitScans:
00078     if (testType != "SctData::PipelineTestResult" && testType != "SctData::FullBypassTestResult" && testType != "SctData::NMaskTestResult") {
00079       string FitISName = Archiving::GetFitISUniqueID(runNumber, scanNumber, moduleName);
00080       fitScans.push_back(ISRetrieveFitScanResult(FitISName));
00081     }
00082     
00083     //cout<<" @@@@@@@@@ RAW = " <<RawISName.c_str()<<endl;
00084     //cout<<" @@@@@@@@@ FIT = " <<FitISName.c_str()<<endl;
00085     //shared_ptr<RawScanResult> tmp_raw = ISRetrieveRawScanResult(RawISName);
00086     //shared_ptr<FitScanResult> tmp_fit = ISRetrieveFitScanResult(FitISName);
00087     //cout<< " NAME = " <<tmp_raw->getUniqueID()<<endl;
00088     //cout<< " NAME = " <<tmp_fit->getUniqueID()<<endl;
00089 
00090     
00091   }
00092 
00093   defects = test.getDefects().getAllDefects();
00094   
00095   
00096   testSummary = NULL; //It is filled in each single *TestResult sub-class
00097 
00098 
00099 }
00100 
00101 
00102 
00103 
00104 
00105 
00106 
00107 
00108 /**********************  Other Member Functions  *********************/
00109 
00110 ArchTestResult::~ArchTestResult()  {
00111   
00112   //cout << "I am in the ArchTestResult destructor" << endl;
00113   
00114 
00115   
00116 }
00117 
00118 
00119 
00120 
00121 void ArchTestResult::SaveRawScans()  {
00122   
00123   cout << "Saving RawScans " << endl;
00124   //TO DO : Save time and date of first and last saving
00125 
00126   
00127   
00128   for (vector<shared_ptr<const RawScanResult> >::iterator i = rawScans.begin(); i!=rawScans.end(); i++) {
00129     //shared_ptr<const RawScanResult> raw = *i;   //!!!!! Is there any other better way apart from writing an assignment operator ???????
00130     const RawScanResult *raw = i->get();
00131     //const RawScanResult *myraw = shared_ptr_release(raw);
00132     ArchRawScanResult rscan(*raw);
00133     rscan.SetTestType(testType);
00134     rscan.SaveRawScan();
00135     //delete &raw;
00136   }
00137   
00138 
00139   
00140   
00141 }
00142 
00143 
00144 
00145 void ArchTestResult::SaveFitScans()  {
00146   
00147   cout << "Saving FitScans " << endl;
00148   //TO DO : Save time and date of first and last saving
00149  
00150   for (vector<shared_ptr<const FitScanResult> >::iterator i = fitScans.begin(); i!=fitScans.end(); i++) {
00151     const FitScanResult *fit = i->get(); 
00152     ArchFitScanResult fscan(*fit);
00153     fscan.SetTestType(testType);
00154     fscan.SaveFitScan();
00155     //delete &fit;
00156   }
00157  
00158   
00159 }
00160 
00161 
00162 
00163 
00164 void ArchTestResult::SaveTestDataOnly()  {
00165   
00166   cout<<" Saving TestData " << endl;
00167   
00168 //TO DO : Save time and date of first and last saving  
00169   
00170   
00171   string filename = names->getfilename();
00172   string moduleID = names->getModuleID();
00173   string moduleDefectsID = names->getModuleDefectsID();
00174   string testType  = names->getTestType(); 
00175   string runID = names->getRunID();
00176   string DefectsID = names->getDefectsID();
00177 
00178 
00179   /* OPENING TEST FILE  */
00180   cout << "Opening file..."<<endl; 
00181  
00182 
00183   TFile *storage_file = new TFile(filename.c_str(),"update");
00184   //storage_file->ls();
00185   cout << "The file .root succesfully open"<<endl; 
00186 
00187   
00188 
00189 
00190   /* CREATING DIRECTORIES and SAVING DATA  */
00191   
00192     
00193     /* Making RunNumber   */
00194     //cout<<"I am making RunNumber Dir"<<endl;
00195     //storage_file->GetListOfKeys()->Print();
00196     TDirectory *this_run = (TDirectory*) gDirectory->Get(runID.c_str());
00197     //cout<<"The RUN is "<< runID <<endl;
00198     
00199     if (!this_run) {
00200       //cout<<"This NEW run "<< runID <<" doesn't exist"<<endl;
00201       this_run = storage_file->mkdir(runID.c_str());
00202       //cout<<"New RunNumber Dir made "<<endl;
00203     }
00204     //storage_file->GetListOfKeys()->Print();
00205     this_run->cd();  //make this_run the current directory
00206     
00207    
00208     /* Saving RunNumber as a TVector: it is saved only once, just the first time   */
00209     TObject* pers_runnumber = gDirectory->FindObjectAny(runID.c_str()); 
00210     if (!pers_runnumber) {
00211       double frunNumber = runNumber;
00212       TVector run(1,1,frunNumber, "END");
00213       run.Write(runID.c_str());
00214     }
00215     
00216     
00217     /* Making moduleNumber   */
00218     
00219     TDirectory* this_module = (TDirectory*) gDirectory->Get(moduleID.c_str()); //Can be made using FindAnyObject
00220     //cout<<"The MODULE is "<< moduleID <<endl;
00221     if (!this_module) {
00222       //cout<<"This NEW module "<< moduleID <<" doesn't exist"<<endl;
00223       this_module =gDirectory ->mkdir(moduleID.c_str());
00224     }
00225 
00226     /* Making ModuleDefects   */
00227     TDirectory* this_moduleDefects = (TDirectory*) gDirectory->Get(moduleDefectsID.c_str()); //Can be made using FindAnyObject
00228     if (!this_moduleDefects) {
00229       //cout<<"ModuleDefects doesn't exist"<<endl;
00230       this_moduleDefects =gDirectory ->mkdir(moduleDefectsID.c_str());
00231     }
00232 
00233     /* Saving ModuleDefects   */
00234     this_moduleDefects->cd();
00235     for (unsigned int i=0; i<defects.size(); ++i) {    //loop on the number of all kinds of defects per module
00236       this_moduleDefects->cd();
00237       
00238 
00239       TDirectory* this_defect = (TDirectory*) gDirectory->Get(defects[i]->getName().c_str()); 
00240       if (!this_defect) {
00241     cout<<defects[i]->getName().c_str()<<" doesn't exist"<<endl;
00242     this_defect =gDirectory ->mkdir(defects[i]->getName().c_str());
00243       }
00244       this_defect->cd();
00245       
00246       TObjString* sdefect = new TObjString(defects[i]->getDescription().c_str());
00247       sdefect->Write("Defect Desctiption");
00248       
00249       /* VERY SLOW
00250 
00251       TVector* vStartChannel = new TVector(1,1,defects[i]->getModuleElement().getFirst(),"END");
00252       vStartChannel->Write("Start Channel");
00253       TVector* vNChannels = new TVector(1,1,defects[i]->getModuleElement().getNChannels(),"END");
00254       vNChannels->Write("Number of Channels");
00255       TVector* vChipDefect = new TVector(1,1,defects[i]->isChipDefect(),"END");   //bool
00256       vChipDefect->Write("isChipDefect");
00257       TVector* vLinkDefect = new TVector(1,1,defects[i]->isLinkDefect(),"END");   //bool
00258       vLinkDefect->Write("isLinkDefect");
00259 
00260       delete vStartChannel;
00261       delete vNChannels;
00262       delete vChipDefect;
00263       delete vLinkDefect;
00264       
00265       */
00266 
00267       //AT: New code to speed up    
00268       double first = defects[i]->getModuleElement().getFirst();
00269       double Nchannels = defects[i]->getModuleElement().getNChannels();
00270       double chipDefect = defects[i]->isChipDefect();
00271       double linkDefect = defects[i]->isLinkDefect();
00272 
00273       TVector* vthisDefect = new TVector(0,3, first, Nchannels,chipDefect, linkDefect, "END"); 
00274       vthisDefect->Write("Defect");
00275      
00276       delete sdefect;
00277       delete vthisDefect;
00278       
00279       
00280     }
00281   
00282     
00283 
00284 
00285     
00286     
00287     /* Making TestType   */
00288     //cout<<"I am making TestType Dir "<<endl;
00289     this_module->cd();  //make this_module the current directory 
00290     TDirectory* this_testType = (TDirectory*) gDirectory->Get(testType.c_str());
00291     //cout<<"The test Type is "<< testType <<endl;
00292     
00293     if (!this_testType) {
00294       //cout<<"This NEW test "<< testType <<" doesn't exist"<<endl;
00295       this_testType = gDirectory->mkdir(testType.c_str());
00296     }
00297     this_testType->cd();
00298 
00299 
00300 
00301     /* Saving Test Data: ModuleDefects */
00302     //for (vector<const ModuleDefect*>::iterator i = defects.begin(); i!=defects.end(); i++) {
00303     //  (*i)->Write(DefectsID.c_str());
00304     //}
00305 
00306     
00307     
00308     /* CLOSING FILE  */
00309     //cout << "I am Closing File " << endl;
00310     storage_file->Close();
00311     delete storage_file;
00312     //cout << "File closed " << endl;
00313 }
00314 
00315 
00316 
00317 
00318 
00319 
00320 void ArchTestResult::AddTestToIndex()  {
00321   
00322   /* Append current Test to the Index */
00323 
00324   //cout << "I am in AddTestToIndex() " << endl;
00325   string index = names->getIndexFileName(); 
00326   ofstream index_file;
00327   index_file.open(index.c_str(),ios::app);  //append the Index File
00328   //assure(out, "Strfile.out");  //TO DO
00329 
00330   string indexTestName = names->getRunID() + ".";
00331   indexTestName = indexTestName + names->getModuleID();
00332   indexTestName = indexTestName + ".";
00333   indexTestName = indexTestName + names->getTestType() + ".";
00334   //cout << indexTestName <<endl;
00335   //if(TestIsPersisted()) {
00336    index_file << indexTestName <<endl;
00337    cout << "Test appended to Index"<<endl;    
00338   //} else {
00339   //  cout<<"Test NOT correctly saved in the archive...test NOT added to the Index"<<endl;
00340   //}
00341   
00342   index_file.close(); 
00343   
00344 }

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