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

ArchTestResult.cpp

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 #include "ArchivingManager.h"
00026 #include "ArchModuleDefects.h"
00027 
00028 using namespace SctData;
00029 using namespace Sct;
00030 using namespace boost;
00031 using boost::shared_ptr;
00032 
00033 
00034 
00035 //Global Variables:
00036 //TFile *storage_file = new TFile();
00037 
00038 
00039 
00040 /********************************** ArchTestResult Methods Definitions ************************/
00041 
00042 
00043 /***********************  Constructor  *************** */
00044 
00045 ArchTestResult::ArchTestResult(): Archiving()  {
00046 
00047   cout<< "I am in the ArchTestResult Default Constructor"<< endl;
00048   runNumber = 0;
00049   moduleName = "0";
00050   NScans = 0; 
00051   names = new ArchTestNames();
00052   //names->SetTestType(testType);
00053   testSummary = NULL;
00054 }
00055   
00056   
00057 ArchTestResult::ArchTestResult(shared_ptr<TestResult> test): Archiving()  {
00058 
00059   cout<< "I am in the ArchTestResult Constructor"<< endl;
00060   
00061 
00062   /*--- Initialisation ---*/
00063 
00064   
00065   runNumber = test->getRunNumber();
00066   moduleName = test->getModuleName();
00067   NScans = test->getNScans();
00068   names = new ArchTestNames(runNumber, moduleName,test->getClassName());
00069   testType = names->getTestType();
00070   
00071   for (unsigned int i=0; i<NScans; i++) {
00072     scanNumbers.push_back(test->getScanNumberAt(i));
00073   }
00074 
00075   
00076   defects = test->getDefects().getAllDefects();
00077   //defects = DeleteRepetedDefects( test->getDefects().getAllDefects() );  //Apparently there are no repetitions
00078   
00079   
00080 
00081   
00082   testSummary = NULL; //It is filled in each single *TestResult sub-class
00083 
00084 
00085 }
00086 
00087 
00088 
00089 
00090 
00091 
00092 
00093 
00094 /**********************  Other Member Functions  *********************/
00095 
00096 ArchTestResult::~ArchTestResult()  {
00097   
00098   //cout << "I am in the ArchTestResult destructor" << endl;
00099   
00100 
00101   
00102 }
00103 
00104 
00105 
00106 void ArchTestResult::SaveRawScans()  {
00107   
00108   cout << "Saving RawScans " << endl;
00109   //TO DO : Save time and date of first and last saving
00110 
00111   
00112   
00113   for (vector<shared_ptr<RawScanResult> >::iterator i = rawScans.begin(); i!=rawScans.end(); i++) {
00114     
00115     shared_ptr<RawScanResult> raw = *i;
00116     
00117     shared_ptr<ArchScanResult> myScanArchiving = ArchivingManager::instance().getScanFromMap(raw);
00118     shared_ptr<ArchScanResult> cloned_scan = myScanArchiving->clone(raw);
00119     
00120     cloned_scan->SetTestType(testType);
00121     cloned_scan->Save();
00122   
00123   }
00124   
00125 
00126   
00127   
00128 }
00129 
00130 
00131 
00132 void ArchTestResult::SaveFitScans()  {
00133   
00134   cout << "Saving FitScans " << endl;
00135   //TO DO : Save time and date of first and last saving
00136  
00137   for (vector<shared_ptr<FitScanResult> >::iterator i = fitScans.begin(); i!=fitScans.end(); i++) {
00138     shared_ptr<FitScanResult> fit = *i; 
00139     shared_ptr<ArchScanResult> myScanArchiving = ArchivingManager::instance().getScanFromMap(fit);
00140     shared_ptr<ArchScanResult> cloned_scan = myScanArchiving->clone(fit);
00141     
00142     cloned_scan->SetTestType(testType);
00143     cloned_scan->Save();
00144 
00145 
00146   }
00147  
00148   
00149 }
00150 
00151 
00152 vector<shared_ptr<const ModuleDefect> > ArchTestResult::DeleteRepetedDefects( vector<shared_ptr<const ModuleDefect> >  tmp_defects ) {
00153   //cout<<"     I am in DeleteRepetedDefects " <<endl;
00154   vector<shared_ptr<const ModuleDefect> > skimmedDefects;  
00155   vector<shared_ptr<const ModuleDefect> >::iterator ibegin=tmp_defects.begin();
00156   shared_ptr<const ModuleDefect> tmp_mydefect = *ibegin;
00157   skimmedDefects.push_back(tmp_mydefect);
00158 
00159   //cout<<" tmp_defects.size() = "<<tmp_defects.size() << endl;
00160   
00161   for (unsigned int i=0; i<tmp_defects.size(); ++i) { 
00162     
00163       //cout<<" i = "<< i << endl;
00164       string Name = tmp_defects[i]->getName();
00165       double first = tmp_defects[i]->getModuleElement().getFirst();
00166       double Nchannels = tmp_defects[i]->getModuleElement().getNChannels();
00167       double chipDefect = tmp_defects[i]->isChipDefect();
00168       double linkDefect = tmp_defects[i]->isLinkDefect();
00169       double unfittable = tmp_defects[i]->isUnfittable();
00170       double unusable = tmp_defects[i]->isUnuseable();
00171       double dodgy = tmp_defects[i]->isDodgy();
00172       //cout << "tmp_defects = "<<first<<" "<< Nchannels<<" "<<chipDefect<<" "<<linkDefect<<" "<<unfittable<<" "<<unusable<<" "<<dodgy<<endl; 
00173       
00174       bool defectToBeSaved = true;
00175       
00176       //for (unsigned int iSkimmed = tmp_defects.size()-1; iSkimmed >= 0 ; --iSkimmed){
00177       for (vector<shared_ptr<const ModuleDefect> >::iterator iSkimmed=skimmedDefects.begin();iSkimmed<skimmedDefects.end(); ++iSkimmed) {      
00178      string skimmed_Name = (*iSkimmed)->getName();
00179          double skimmed_first = (*iSkimmed)->getModuleElement().getFirst();
00180      double skimmed_Nchannels = (*iSkimmed)->getModuleElement().getNChannels();
00181      double skimmed_chipDefect = (*iSkimmed)->isChipDefect();
00182      double skimmed_linkDefect = (*iSkimmed)->isLinkDefect();
00183      double skimmed_unfittable = (*iSkimmed)->isUnfittable();
00184      double skimmed_unusable =(*iSkimmed)->isUnuseable();
00185      double skimmed_dodgy = (*iSkimmed)->isDodgy();
00186 
00187      
00188       
00189      //cout << "skimmed_defects = "<<skimmed_first<<" "<< skimmed_Nchannels<<" "<<skimmed_chipDefect<<" "<<skimmed_linkDefect<<" "<<skimmed_unfittable<<" "<<skimmed_unusable<<" "<<skimmed_dodgy<<endl; 
00190      //cout<<" I am in iSkimmed..before break"<<endl;
00191      
00192      if (Name == skimmed_Name && 
00193          first == skimmed_first &&  
00194          Nchannels == skimmed_Nchannels && 
00195          chipDefect == skimmed_chipDefect && 
00196          linkDefect == skimmed_linkDefect &&
00197          unfittable == skimmed_unfittable &&
00198          unusable == skimmed_unusable &&
00199          dodgy == skimmed_dodgy ) 
00200        { 
00201          //cout<<" I am IN break"<<endl; 
00202          defectToBeSaved = false;
00203          break; 
00204        }
00205       
00206      
00207       
00208        }
00209       
00210     
00211       if ( defectToBeSaved == true ) {
00212     skimmedDefects.push_back(tmp_defects[i]); 
00213     //cout<<" I am push_back"<<endl;
00214       }
00215 
00216        
00217   }
00218 
00219 
00220   
00221     return skimmedDefects;
00222     
00223 }
00224 
00225 
00226 void ArchTestResult::Save()  {
00227   
00228   cout<<" Saving TestData " << endl;
00229   
00230 //TO DO : Save time and date of first and last saving  
00231   
00232   
00233   string filename = names->getfilename();
00234   string moduleID = names->getModuleID();
00235   string moduleDefectsID = names->getModuleDefectsID();
00236   string testType  = names->getTestType(); 
00237   string runID = names->getRunID();
00238   string DefectsID = names->getDefectsID();
00239 
00240 
00241   /* OPENING TEST FILE  */
00242   cout << "Opening file..."<<endl; 
00243  
00244 
00245   TFile *storage_file = new TFile(filename.c_str(),"update");
00246   //storage_file->ls();
00247   cout << "The file .root succesfully open"<<endl; 
00248 
00249   
00250 
00251 
00252   /* CREATING DIRECTORIES and SAVING DATA  */
00253   
00254     
00255     /* Making RunNumber   */
00256     //cout<<"I am making RunNumber Dir"<<endl;
00257     //storage_file->GetListOfKeys()->Print();
00258     TDirectory *this_run = (TDirectory*) gDirectory->Get(runID.c_str());
00259     //cout<<"The RUN is "<< runID <<endl;
00260     
00261     if (!this_run) {
00262       //cout<<"This NEW run "<< runID <<" doesn't exist"<<endl;
00263       this_run = storage_file->mkdir(runID.c_str());
00264       //cout<<"New RunNumber Dir made "<<endl;
00265     }
00266     //storage_file->GetListOfKeys()->Print();
00267     this_run->cd();  //make this_run the current directory
00268     
00269    
00270     /* Saving RunNumber as a TVector: it is saved only once, just the first time   */
00271     TObject* pers_runnumber = gDirectory->FindObjectAny(runID.c_str()); 
00272     if (!pers_runnumber) {
00273       double frunNumber = runNumber;
00274       TVector run(1,1,frunNumber, "END");
00275       run.Write(runID.c_str());
00276     }
00277     
00278     
00279     /* Making moduleNumber   */
00280     
00281     TDirectory* this_module = (TDirectory*) gDirectory->Get(moduleID.c_str()); //Can be made using FindAnyObject
00282     //cout<<"The MODULE is "<< moduleID <<endl;
00283     if (!this_module) {
00284       //cout<<"This NEW module "<< moduleID <<" doesn't exist"<<endl;
00285       this_module =gDirectory ->mkdir(moduleID.c_str());
00286     }
00287     this_module->cd();  //make this_module the current directory 
00288 
00289 
00290     /* Making ModuleDefects   */
00291     TDirectory* this_moduleDefects = (TDirectory*) gDirectory->Get(moduleDefectsID.c_str()); //Can be made using FindAnyObject
00292     if (!this_moduleDefects) {
00293       //cout<<"ModuleDefects doesn't exist"<<endl;
00294       this_moduleDefects =gDirectory ->mkdir(moduleDefectsID.c_str());
00295     }
00296 
00297 
00298 
00299 
00300 
00301     /* -----------------------------------   */
00302     /* -----  Saving ModuleDefects  ------   */
00303     /* -----------------------------------   */
00304 
00305 
00306 
00307     /* OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD
00308     for (unsigned int i=0; i<defects.size(); ++i) {    //loop on the number of all kinds of defects per module
00309       
00310      
00311 
00312       this_moduleDefects->cd();
00313       
00314 
00315       TDirectory* this_defect = (TDirectory*) gDirectory->Get(defects[i]->getName().c_str()); 
00316       if (!this_defect) {
00317     cout<<defects[i]->getName().c_str()<<" doesn't exist"<<endl;
00318     this_defect =gDirectory ->mkdir(defects[i]->getName().c_str());
00319       }
00320       this_defect->cd();
00321       
00322 
00323       TObject* pers_sdefect = gDirectory->FindObjectAny("Defect Description"); 
00324       if (!pers_sdefect) {
00325     TObjString* sdefect = new TObjString(defects[i]->getDescription().c_str());
00326     sdefect->Write("Defect Description");
00327       }
00328       
00329       
00330       //TObject* defectList = gDirectory->FindObjectAny(defects[i]->getName().c_str()); 
00331       //if (!defectList) ....create defectList
00332       
00333       //AT: New code to speed up    
00334       double first = defects[i]->getModuleElement().getFirst();
00335       double Nchannels = defects[i]->getModuleElement().getNChannels();
00336       double chipDefect = defects[i]->isChipDefect();
00337       double linkDefect = defects[i]->isLinkDefect();
00338       double unfittable = defects[i]->isUnfittable();
00339       double unusable = defects[i]->isUnuseable();
00340       double dodgy = defects[i]->isDodgy();
00341 
00342       TVector* vthisDefect = new TVector(0,6, first, Nchannels,chipDefect, linkDefect, unfittable, unusable, dodgy, "END"); 
00343       cout << "defects = "<<first<<" "<< Nchannels<<" "<<chipDefect<<" "<<linkDefect<<" "<<unfittable<<" "<<unusable<<" "<<dodgy<<endl; 
00344       //OLD vthisDefect->Write( names->getDefectID(first,Nchannels).c_str() );
00345       
00346       //defectList must be defined!!!!
00347       //defectList->Add(vthisDefect);
00348       
00349 
00350       
00351       delete vthisDefect;
00352       
00353       
00354       
00355     }
00356    
00357     */
00358 
00359     this_moduleDefects->cd();
00360 
00361     ArchModuleDefects archDefects(defects);
00362     //cout<<"ArchTestResult:  archDefects defined"<<endl;
00363     vector< shared_ptr<TObjArray> > sortedDefectList = archDefects.getDefects();
00364     //cout<<"ArchTestResult: sortedDefectList defined"<<endl;
00365     cout<<" sortedDefectList size = " << sortedDefectList.size() <<endl;
00366 
00367     
00368     for (vector<shared_ptr<TObjArray> >::iterator it = sortedDefectList.begin();it != sortedDefectList.end() ; ++it)
00369       {  
00370       this_moduleDefects->cd();
00371 
00372 
00373       shared_ptr<TObject> objFirst = (*it)->First();
00374       shared_ptr<TObjString> this_name = dynamic_pointer_cast<TObjString>(objFirst);
00375       const char *this_defectName = this_name->GetName();
00376       cout<< "Name = " <<this_defectName<<endl;
00377       
00378 
00379       cout<<"ArchTestResult: about to write sortedDefectList obj..."<<endl;
00380       
00381       (*it)->Write(this_defectName,TObject::kSingleKey );
00382       cout<<"ArchTestResult: sortedDefectList obj written"<<endl;
00383 
00384     }
00385    
00386 
00387 
00388     /* -----------------------------------   */
00389     
00390 
00391 
00392     
00393     
00394     /* Making TestType   */
00395     //cout<<"I am making TestType Dir "<<endl;
00396     this_module->cd();  //make this_module the current directory 
00397     TDirectory* this_testType = (TDirectory*) gDirectory->Get(testType.c_str());
00398     //cout<<"The test Type is "<< testType <<endl;
00399     
00400     if (!this_testType) {
00401       //cout<<"This NEW test "<< testType <<" doesn't exist"<<endl;
00402       this_testType = gDirectory->mkdir(testType.c_str());
00403     }
00404     this_testType->cd();
00405 
00406 
00407 
00408     /* CLOSING FILE  */
00409     //cout << "I am Closing File " << endl;
00410     storage_file->Close();
00411     delete storage_file;
00412     cout << "File closed " << endl;
00413 }
00414 
00415 
00416 void ArchTestResult::RetrieveRawFitScans()  {
00417 
00418   //Retrieving Raw and Fitted Scans:
00419   for (vector<unsigned int>::iterator i = scanNumbers.begin(); i!=scanNumbers.end(); i++) { 
00420     unsigned int scanNumber =  *i;
00421     string RawISName = Archiving::GetRawISUniqueID(runNumber, scanNumber, moduleName);
00422     rawScans.push_back(ISRetrieveRawScanResult(RawISName));
00423     
00424     //Pipeline,FullBypass have no FitScans:
00425     if (testType != "SctData::PipelineTestResult" && testType != "SctData::FullBypassTestResult" && testType != "SctData::NMaskTestResult") {
00426       //if (testType != "PipelineTestResult" && testType != "FullBypassTestResult" && testType != "NMaskTestResult") {
00427       if (testType != "PipelineTest" && testType != "FullBypassTest" && testType != "NMaskTest") {
00428     string FitISName = Archiving::GetFitISUniqueID(runNumber, scanNumber, moduleName);
00429     fitScans.push_back(ISRetrieveFitScanResult(FitISName));
00430       }
00431    
00432       
00433     }
00434     
00435     
00436 
00437   }
00438 
00439 }
00440 
00441 
00442 
00443 void ArchTestResult::AddTestToIndex()  {
00444   
00445   /* Append current Test to the Index */
00446 
00447   //cout << "I am in AddTestToIndex() " << endl;
00448   string index = names->getIndexFileName(); 
00449   ofstream index_file;
00450   index_file.open(index.c_str(),ios::app);  //append the Index File
00451   //assure(out, "Strfile.out");  //TO DO
00452 
00453   string indexTestName = names->getRunID() + ".";
00454   indexTestName = indexTestName + names->getModuleID();
00455   indexTestName = indexTestName + ".";
00456   indexTestName = indexTestName + names->getTestType() + ".";
00457   //cout << indexTestName <<endl;
00458   //if(TestIsPersisted()) {
00459    index_file << indexTestName <<endl;
00460    cout << "Test appended to Index"<<endl;    
00461   //} else {
00462   //  cout<<"Test NOT correctly saved in the archive...test NOT added to the Index"<<endl;
00463   //}
00464   
00465   index_file.close(); 
00466   
00467 }

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