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

ArchRawScanResult.cpp

00001 #include "ArchRawScanResult.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 <TBuffer.h>
00013 #include <TVector.h>
00014 #include <TVectorD.h>
00015 #include <TH1.h>
00016 #include <TH2.h>
00017 #include <TCanvas.h>
00018 #include <TROOT.h>
00019 #include <is/isinfo.h>
00020 #include <iostream>
00021 #include <vector>
00022 
00023 
00024 
00025 /********************************** ArchScan Methods Definitions ************************/
00026 
00027 
00028 bool ArchRawScanResult::inMap = ArchivingManager::instance().addScanArchiver("SctData::RawScanResult", shared_ptr<ArchScanResult>(new ArchRawScanResult())); 
00029 
00030 /***********************  Constructor  *************** */
00031 
00032 ArchRawScanResult::ArchRawScanResult(): ArchScanResult()  {
00033 
00034   cout<< "I am in the ArchRawScanResult Default Constructor"<< endl;
00035  
00036   
00037 }
00038   
00039   
00040 ArchRawScanResult::ArchRawScanResult(shared_ptr<const RawScanResult>  raw): ArchScanResult(raw)  {
00041 
00042   cout<< "I am in the ArchRawScanResult Constructor"<< endl;
00043   
00044 
00045   /*--- Initialisation ---*/
00046    
00047   theRaw=raw;
00048   
00049   //TH2D *scan0 = &raw->getScanData(0);
00050   //cout << "Scan 0 is: " << scan0 << endl;
00051   //scan0->Print();
00052   //RawData_link0 = shared_ptr<TH2D> ( new TH2D(raw->getScanData(0)) );
00053   //cout << "RawData_link0 is: " << RawData_link0.get() << endl;
00054 
00055   //TH2D *scan1 = &raw->getScanData(1);
00056   //cout << "Scan 1 is: " << scan1 << endl;
00057   //RawData_link1 = shared_ptr<TH2D> ( new TH2D(raw->getScanData(1)) );
00058   //cout << "RawData_link1 is: " << RawData_link1.get() << endl;
00059  
00060 
00061   //cout << "RawData link0 bins: " << RawData_link0->GetNbinsY() <<endl; 
00062   //cout << "RawData link1 bins: " << RawData_link1->GetNbinsY() <<endl;  
00063   
00064 }
00065 
00066 
00067 
00068 
00069 /**********************  Other Member Functions  *********************/
00070 
00071 ArchRawScanResult::~ArchRawScanResult()  {
00072   
00073   cout << "I am in the ArchRawScanResult destructor" << endl;
00074   
00075   
00076   
00077 }
00078 
00079 
00080 
00081 
00082 void ArchRawScanResult::SetRawScan(shared_ptr<RawScanResult> raw)  {
00083   
00084   /*--- Initialisation ---*/
00085   theRaw=raw;
00086 
00087   SetScan(raw);
00088 
00089   //RawData_link0 = shared_ptr<TH2D> ( new TH2D(raw->getScanData(0)) );
00090   //RawData_link1 = shared_ptr<TH2D> ( new TH2D(raw->getScanData(1)) );
00091   
00092 
00093   //cout << "RawData link0 bins: " << RawData_link0->GetNbinsY() <<endl; 
00094   //cout << "RawData link1 bins: " << RawData_link1->GetNbinsY() <<endl;  
00095   
00096   
00097 
00098 }
00099 
00100 
00101 
00102 void ArchRawScanResult::SaveRawScan() {   
00103 
00104   //TO DO : Save time and date of first and last saving
00105  
00106   string TH2Dlink0 = names->getTH2Dlink0();
00107   string TH2Dlink1 = names->getTH2Dlink1();
00108   string ScanPointsID = names->getScanPointsID() ;
00109   string vpointsID = names->getvpointsID();
00110   string vNEventsID = names->getvNEventsID();
00111   string vNErrorEventsID = names->getvNErrorEventsID(); 
00112   string filename = names->getfilename();
00113   //string objName = ;  //To be deleted
00114   string variable = names->getVariable(); 
00115   string moduleID = names->getModuleID(); 
00116   string testType  = names->getTestType(); 
00117   string runID = names->getRunID();
00118   string scanID = names->getScanID();
00119   string RODID = names->getRODID();
00120   string DCSID = names->getDCSID();
00121   string RawID = names->getRawID();
00122   string FitID = names->getFitID();
00123   string ModuleConfigID = names->getModuleConfigID();
00124 
00125 
00126 
00127   /* OPENING TEST FILE  */
00128   cout << "Opening file..."<<endl; 
00129  
00130 
00131   /*
00132   TObject *storage_file = gROOT->FindObjectAny(filename) ;
00133   if (!storage_file) { 
00134     cout << "no such file " << endl;
00135     //TFile *storage_file = new TFile(filename,"update");
00136   }
00137   else {
00138     cout << "The file already exists " << endl;
00139     TFile *storage_file = new TFile(filename,"update");
00140   }
00141   */
00142 
00143   TFile *storage_file = new TFile(filename.c_str(),"update");
00144   //storage_file->ls();
00145   cout << "The file .root succesfully open"<<endl; 
00146 
00147   
00148 
00149 
00150   /* CREATING DIRECTORIES and SAVING DATA  */
00151   
00152     
00153     /* Making RunNumber   */
00154     cout<<"I am making RunNumber Dir"<<endl;
00155     //storage_file->GetListOfKeys()->Print();
00156     TDirectory *this_run = (TDirectory*) gDirectory->Get(runID.c_str());
00157     cout<<"The RUN is "<< runID <<endl;
00158     
00159     if (!this_run) {
00160       cout<<"This NEW run "<< runID <<" doesn't exist"<<endl;
00161       this_run = storage_file->mkdir(runID.c_str());
00162       //cout<<"New RunNumber Dir made "<<endl;
00163     }
00164     //storage_file->GetListOfKeys()->Print();
00165     this_run->cd();  //make this_run the current directory
00166     
00167    
00168     /* Saving RunNumber as a TVector: it is saved only once, just the first time   */
00169     /* Already saved in ArchScanResult
00170     TObject* pers_runnumber = gDirectory->FindObjectAny(runID.c_str()); 
00171     if (!pers_runnumber) {
00172       double frunNumber = runNumber;
00173       TVector run(1,1,frunNumber, "END");
00174       run.Write(runID.c_str());
00175     }
00176     */
00177 
00178 
00179     
00180     /* Making moduleNumber   */
00181     
00182     TDirectory* this_module = (TDirectory*) gDirectory->Get(moduleID.c_str()); //Can be made using FindAnyObject
00183     cout<<"The MODULE is "<< moduleID <<endl;
00184     if (!this_module) {
00185       //cout<<"This NEW module "<< moduleID <<" doesn't exist"<<endl;
00186       this_module =gDirectory ->mkdir(moduleID.c_str());
00187     }
00188     
00189 
00190 
00191     
00192     /* Making TestType   */
00193     cout<<"I am making TestType Dir "<<endl;
00194     this_module->cd();  //make this_module the current directory 
00195     TDirectory* this_testType = (TDirectory*) gDirectory->Get(testType.c_str());
00196     //cout<<"The test Type is "<< testType <<endl;
00197     
00198     if (!this_testType) {
00199       //cout<<"This NEW test "<< testType <<" doesn't exist"<<endl;
00200       this_testType = gDirectory->mkdir(testType.c_str());
00201     }
00202 
00203     
00204     /* Making ScanType   */
00205     cout<<"I am making scanType Dir "<<endl;
00206     this_testType->cd();  //make this_testType the current directory 
00207     TDirectory* this_variable = (TDirectory*) gDirectory->Get(variable.c_str());
00208     //cout<<"The Scan Type is "<< variable <<endl;
00209     
00210     
00211     if (!this_variable) {
00212       //cout<<"This NEW test "<< variable <<" doesn't exist"<<endl;
00213       this_variable = gDirectory->mkdir(variable.c_str());
00214     }
00215      
00216 
00217     
00218 
00219     /* Making variable   */
00220     cout<<"I am making variable Dir "<<endl;
00221     this_variable->cd();  //make this_test the current directory
00222     TDirectory* this_scan = (TDirectory*) gDirectory->Get(scanID.c_str());
00223     //cout<<"The SCAN is "<< scanID <<endl;
00224     
00225     if (!this_scan) {
00226       //cout<<"This NEW scan "<< scanID <<" doesn't exist"<<endl;
00227       this_scan =gDirectory ->mkdir(scanID.c_str());
00228     }
00229     this_scan->cd(); 
00230 
00231 
00232     /* Saving ScanNumber as a TVector: it is saved only once, just the first time   */
00233     /* Already saved in ArchScanResult
00234     TObject* pers_scannumber = gDirectory->FindObjectAny(scanID.c_str());
00235     if (!pers_scannumber) {
00236       double fscanNumber = scanNumber;
00237       TVector vscan(1,1,fscanNumber,"END");
00238       vscan.Write(scanID.c_str());
00239     }
00240     */
00241 
00242 
00243     //Saving Module Configuration
00244     /* Already saved in ArchScanResult
00245     TObject* pers_ModuleConfig = gDirectory->FindObjectAny(ModuleConfigID.c_str());
00246     if (!pers_ModuleConfig) {
00247       //cout<<"%%%%%%% Just about to save ABCDModule %%%%%%%"<<endl;
00248       TObjString ModuleConfigTObjString = getModuleConfigTObjString();
00249       //TString tmp_string = ModuleConfigTObjString.String();
00250       //cout<< "Module Configuration :" << endl << tmp_string.Data()<<endl;
00251       ModuleConfigTObjString.Write(ModuleConfigID.c_str()); 
00252       //cout<<"%%%%%%% ABCDModule saved %%%%%%%"<<endl;
00253     }
00254     */
00255 
00256 
00257 
00258 
00259     /* Threshold saved as a TVector: it is saved only once, just the first time */ 
00260 /*    
00261       TObject* pers_Threshold = gDirectory->FindObjectAny(thresholdID.c_str());  
00262       if (!pers_Threshold) {
00263       cout << "The Threshold never saved before...saving now"<<endl;
00264       double fthreshold = threshold;
00265       TVectorD vthreshold(1,1,fthreshold,"END");
00266       vthreshold.Write(thresholdID.c_str());
00267     }
00268 
00269 */
00270 
00271 
00272     /* Saving ScanPoints as a TGraph: it is saved only once, just the first time  */
00273     //cout << "I am Saving ScanPoints as a TGraph" << endl;
00274     //TObject* pers_gscanpoints = gDirectory->FindObjectAny(ScanPointsID.c_str()); 
00275     //if (!pers_gscanpoints) {
00276       //cout << "The ScanPoints never saved before...saving now"<<endl;
00277       //AT  gpoints->Write(ScanPointsID.c_str());
00278     //}
00279     
00280 
00281     
00283     //cout << "I am Saving ScanPoints as  TVector's" << endl;
00284     //TObject* pers_vscanpoints = gDirectory->FindObjectAny(vpointsID.c_str()); 
00285     //if (!pers_vscanpoints) {
00286       //cout << "The ScanPoints never saved before...saving now"<<endl;
00287       //AT   vpoints->Write(vpointsID.c_str());  
00288     //}
00289     //TObject* pers_vNEvents = gDirectory->FindObjectAny(vNEventsID.c_str()); 
00290     //if (!pers_vNEvents) {
00291       //cout<< "I am here " << endl;
00292       //AT   vNEvents->Write(vNEventsID.c_str());  
00293     //}
00294      //TObject* pers_vNErrorEvents = gDirectory->FindObjectAny(vNErrorEventsID.c_str()); 
00295     //if (!pers_vNErrorEvents) {
00296     //AT   vNErrorEvents->Write(vNErrorEventsID.c_str());  
00297     //}      
00298 
00299 
00300 
00301     /* Making DCS   */
00302     //cout<<"I am making DCS Dir"<<endl;
00303       /*
00304     this_scan->cd();  //make this_scan the current directory
00305     TDirectory*  this_DCS = (TDirectory*) this_scan->Get(DCSID.c_str()); 
00306     //NB: DCS & ROD are at the same level. 
00307     if (!this_DCS) {
00308       //cout<<"This NEW DCS  doesn't exist"<<endl;
00309       this_DCS = this_scan->mkdir(DCSID.c_str());
00310     }
00311     
00312       */
00313    
00314 
00315     /* Saving DCS data members  */
00316       /*
00317     //cout << "I am Saving DCS RawScanResult Data Members" << endl;
00318     this_DCS->cd();  
00319       */
00320 
00321 
00322     /* Making ROD   */ 
00323     cout<<"I am making ROD Dir"<<endl;
00324     this_scan->cd();  //make this_scan the current directory
00325     TDirectory* this_ROD = (TDirectory*) this_scan->Get(RODID.c_str());
00326     //NB: DCS & ROD are at the same level: this_scan .Get(DCSID.c_str())
00327      
00328     if (!this_ROD) {
00329       //cout<<"This NEW ROD  doesn't exist"<<endl;
00330       this_ROD = this_scan->mkdir(RODID.c_str());
00331     }
00332     
00333   
00334         
00335 
00336     
00337     /* Making ROD Raw    */
00338     cout<<"I am making Raw Dir"<<endl;
00339     this_ROD->cd();
00340     TDirectory* this_raw = (TDirectory*) this_ROD->Get(RawID.c_str()); 
00341     /*NB: Fitted & Raw are at the same level: they can descend from DCS or ROD For this reason gDirectory.Get("...")*/
00342 
00343     if (!this_raw) {
00344       //cout<<"This NEW Raw Data  doesn't exist"<<endl;
00345       this_raw = this_ROD->mkdir(RawID.c_str());
00346     }
00347     
00348  
00349 
00350     /* Saving ROD Raw data members  */
00351     cout << "I am Saving ROD raw RawScanResult Data Members " << endl;
00352     this_raw->cd();  //make this_scan the current directory
00353     //for (vector<TH2D*>::iterator i = RawData.begin(); i!=RawData.end(); i++) {
00354     //(*i)->Write("RawData");
00355     //}
00356 
00357 
00358     cout<<"I am before Saving RawData_links"<<endl;
00359     //RawData_link0->Write(TH2Dlink0.c_str());
00360     //RawData_link1->Write(TH2Dlink1.c_str());
00361     
00362     theRaw->getScanData(0).Write(TH2Dlink0.c_str()); //crashes!!
00363     theRaw->getScanData(1).Write(TH2Dlink1.c_str()); //crashes!!
00364     
00365     cout<<"I am after Saving RawData_links"<<endl;
00366     
00367 
00368     /* CLOSING FILE  */
00369     cout << "I am Closing File " << endl;
00370     storage_file->Close();
00371     delete storage_file;
00372     cout << "File closed " << endl;
00373 
00374 }
00375 
00376 
00377 
00378 
00379 void ArchRawScanResult::SaveRawScan(shared_ptr<RawScanResult>  s) {
00380 
00381    ArchRawScanResult tmp_receiver(s); 
00382    tmp_receiver.SaveRawScan();
00383 
00384 }
00385 
00386 void ArchRawScanResult::Save() {
00387   
00388   ArchScanResult::Save();
00389   SaveRawScan();
00390 
00391 }
00392 
00393 
00394 void ArchRawScanResult::Save(shared_ptr<RawScanResult> s) {
00395   
00396   ArchRawScanResult tmp_receiver(s); 
00397   tmp_receiver.Save();
00398 
00399 }
00400 
00401 
00402 bool ArchRawScanResult::RawScanIsPersisted()  {
00403 
00404   /* Check if the current RawScanResult of the current Test has been persisted*/
00405    
00406 
00407   string TH2Dlink0 = names->getTH2Dlink0();
00408   string TH2Dlink1 = names->getTH2Dlink1();
00409   string ScanPointsID = names->getScanPointsID() ;
00410   string vpointsID = names->getvpointsID();
00411   string vNEventsID = names->getvNEventsID();
00412   string vNErrorEventsID = names->getvNErrorEventsID(); 
00413   string filename = names->getfilename();
00414   //string objName = ;  //To be deleted
00415   string variable = names->getVariable(); 
00416   string moduleID = names->getModuleID(); 
00417   string testType  = names->getTestType(); 
00418   string runID = names->getRunID();
00419   string scanID = names->getScanID();
00420   string RODID = names->getRODID();
00421   string DCSID = names->getDCSID();
00422   string RawID = names->getRawID();
00423   string FitID = names->getFitID();
00424   string thresholdID = names->getThresholdID();
00425 
00426 
00427   
00428   TFile *inspect_file = new TFile(filename.c_str(),"read");
00429   if (inspect_file->IsZombie() == true) {
00430     cout << "The RawScanResult has NOT been saved in any file"<<endl; 
00431     return 1;
00432   }
00433   
00434   
00435   gDirectory->cd(runID.c_str());
00436   TDirectory* inspect_dir = (TDirectory*) gDirectory->Get(moduleID.c_str());
00437   if (!inspect_dir) {
00438       cout<<"The RawScanResult has NOT been saved"<<endl;
00439       return 1;
00440   }
00441   gDirectory->cd(moduleID.c_str());
00442    
00443 
00444   gDirectory->cd(testType.c_str());
00445 
00446 
00447   gDirectory->cd(variable.c_str());
00448   inspect_dir = (TDirectory*) gDirectory->Get(scanID.c_str());
00449   if (!inspect_dir) {
00450       cout<<"The RawScanResult has NOT been saved"<<endl;
00451       return 1;
00452   }
00453   gDirectory->cd(scanID.c_str());
00454   
00455   /*
00456   TObject* pers_Threshold = gDirectory->FindObjectAny(thresholdID.c_str()); 
00457   if (!pers_Threshold) {
00458     cout << "The RawScanResult has NOT been saved"<<endl;
00459     return 1;
00460   }
00461 
00462 */
00463 
00464   //Check if ScanPoints are saved as TGraph
00465   TObject* pers_RawTH1 = gDirectory->FindObjectAny(ScanPointsID.c_str()); 
00466   if (!pers_RawTH1) {
00467     cout << "The RawScanResult has NOT been saved"<<endl;
00468     return 1;
00469   }
00470 
00471   
00472   //Check if ScanPoints are saved as TVector's
00473   TObject* pers_points = gDirectory->FindObjectAny(vpointsID.c_str()); 
00474   if (!pers_points) {
00475     cout << "The RawScanResult has NOT been saved...ScanPoints"<<endl;
00476     return 1;
00477   }
00478   TObject* pers_Nevents = gDirectory->FindObjectAny(vNEventsID.c_str()); 
00479   if (!pers_Nevents) {
00480     cout << "The RawScanResult has NOT been saved...ScanPoints"<<endl;
00481     return 1;
00482   }
00483   TObject* pers_vNErrorEvents = gDirectory->FindObjectAny(vNErrorEventsID.c_str()); 
00484   if (!pers_vNErrorEvents) {
00485     cout << "The RawScanResult has NOT been saved...ScanPoints"<<endl;
00486     return 1;
00487   }
00488 
00489   gDirectory->cd(RODID.c_str());
00490   gDirectory->cd(RawID.c_str());
00491 
00492   cout << "Looking for persisted histograms in Raw Data" << endl;
00493   //gDirectory->ls();
00494 
00495 
00496   //Check if the two TH2D hist's have been persisted
00497   TObject* pers_RawTH2link0 = gDirectory->FindObjectAny(TH2Dlink0.c_str()); 
00498   if (!pers_RawTH2link0) {
00499     cout << "The RawScanResult has NOT been saved"<<endl;
00500     return 1;
00501   }
00502 
00503   TObject* pers_RawTH2link1 = gDirectory->FindObjectAny(TH2Dlink1.c_str()); 
00504   if (!pers_RawTH2link1) {
00505     cout << "The RawScanResult has NOT been saved"<<endl;
00506     return 1;
00507   }
00508 
00509   inspect_file->Close();
00510   delete inspect_file;  
00511 
00512   cout << "RawScanResult has been PERSISTED" << endl;
00513   return 0;
00514 
00515 
00516 }
00517 
00518 
00519 
00520 
00521 
00522 
00523 bool ArchRawScanResult::RawScanIsPersisted(long scanNumber, long runNumber, string moduleName, const ConfigurationVariable& variable, unsigned int cycle)  {
00524 
00525   /* Check if the current RawScanResult of the current Test has been persisted*/
00526   
00527   ArchScanNames *new_names= new ArchScanNames(runNumber,moduleName,scanNumber, variable, cycle ); 
00528 
00529   string TH2Dlink0 = new_names->getTH2Dlink0();
00530   string TH2Dlink1 = new_names->getTH2Dlink1();
00531   string ScanPointsID = new_names->getScanPointsID() ;
00532   string vpointsID = new_names->getvpointsID();
00533   string vNEventsID = new_names->getvNEventsID();
00534   string vNErrorEventsID = new_names->getvNErrorEventsID(); 
00535   string filename = new_names->getfilename();
00536   //string objName = ;  //To be deleted
00537   string sVariable = new_names->getVariable();   
00538   string moduleID = new_names->getModuleID(); 
00539   string testType  = new_names->getTestType(); 
00540   string runID = new_names->getRunID();
00541   string scanID = new_names->getScanID();
00542   string RODID = new_names->getRODID();
00543   string DCSID = new_names->getDCSID();
00544   string RawID = new_names->getRawID();
00545   string FitID = new_names->getFitID();
00546   string thresholdID = new_names->getThresholdID();
00547 
00548   //
00549 
00550 
00551   /* Variable initialisation */
00552 
00553 
00554   /* Opening File */
00555   TFile *inspect_file = new TFile(filename.c_str(),"read");
00556   if (inspect_file->IsZombie() == true) {
00557     cout << "The RawScanResult has NOT been saved in any file"<<endl; 
00558     return 1;
00559   }
00560   
00561   
00562   gDirectory->cd(runID.c_str());
00563   TDirectory* inspect_dir = (TDirectory*) gDirectory->Get(moduleID.c_str());
00564   if (!inspect_dir) {
00565       cout<<"The RawScanResult has NOT been saved...moduleID"<<endl;
00566       return 1;
00567   }
00568   gDirectory->cd(moduleID.c_str());
00569 
00570 
00571   TDirectory* testType_dir = (TDirectory*) gDirectory->Get(testType.c_str());
00572   if (!testType_dir) {
00573       cout<<"The RawScanResult has NOT been saved...testType"<<endl;
00574       return 1;
00575   }
00576   gDirectory->cd(testType.c_str());
00577 
00578 
00579   TDirectory* pers_variable = (TDirectory*) gDirectory->Get(sVariable.c_str());
00580   if (!pers_variable) {
00581       cout<<"The RawScanResult has NOT been saved...variable"<<endl;
00582       return 1;
00583   }
00584   gDirectory->cd(sVariable.c_str());
00585 
00586 
00587   inspect_dir = (TDirectory*) gDirectory->Get(scanID.c_str());
00588   if (!inspect_dir) {
00589       cout<<"The RawScanResult has NOT been saved...scanID"<<endl;
00590       return 1;
00591   }
00592   gDirectory->cd(scanID.c_str());
00593   
00594   /*
00595   TObject* pers_Threshold = gDirectory->FindObjectAny(thresholdID.c_str()); 
00596   if (!pers_Threshold) {
00597     cout << "The RawScanResult has NOT been saved...thresholdID"<<endl;
00598     return 1;
00599   } 
00600   */
00601 
00602   //Check if ScanPoints are saved as TGraph
00603   TObject* pers_RawTH1 = gDirectory->FindObjectAny(ScanPointsID.c_str()); 
00604   if (!pers_RawTH1) {
00605     cout << "The RawScanResult has NOT been saved...ScanPointsID"<<endl;
00606     return 1;
00607   }
00608   
00609   //Check if ScanPoints are saved as TVector's
00610   TObject* pers_points = gDirectory->FindObjectAny(vpointsID.c_str()); 
00611   if (!pers_points) {
00612     cout << "The RawScanResult has NOT been saved...ScanPoints"<<endl;
00613     return 1;
00614   }
00615   TObject* pers_Nevents = gDirectory->FindObjectAny(vNEventsID.c_str()); 
00616   if (!pers_Nevents) {
00617     cout << "The RawScanResult has NOT been saved...ScanPoints"<<endl;
00618     return 1;
00619   }
00620   TObject* pers_vNErrorEvents = gDirectory->FindObjectAny(vNErrorEventsID.c_str()); 
00621   if (!pers_vNErrorEvents) {
00622     cout << "The RawScanResult has NOT been saved...ScanPoints"<<endl;
00623     return 1;
00624   }
00625 
00626 
00627   gDirectory->cd(RODID.c_str());
00628   gDirectory->cd(RawID.c_str());
00629 
00630   cout << "Looking for persisted histograms in Raw Data" << endl;
00631   //gDirectory->ls();
00632 
00633 
00634   //Check if the two TH2D hist's have been persisted
00635   TObject* pers_RawTH2link0 = gDirectory->FindObjectAny(TH2Dlink0.c_str()); 
00636   if (!pers_RawTH2link0) {
00637     cout << "The RawScanResult has NOT been saved...TH2Dlink0"<<endl;
00638     return 1;
00639   }
00640 
00641   TObject* pers_RawTH2link1 = gDirectory->FindObjectAny(TH2Dlink1.c_str()); 
00642   if (!pers_RawTH2link1) {
00643     cout << "The RawScanResult has NOT been saved...TH2Dlink1"<<endl;
00644     return 1;
00645   }
00646   
00647 
00648   cout << "RawScanResult has been PERSISTED" << endl;
00649   return 0;
00650 
00651 
00652 }
00653 
00654 
00655 
00656 
00657 
00658 
00659 
00660 
00661 bool ArchRawScanResult::RawScanIsPersisted(shared_ptr<RawScanResult>  rawdata)  {
00662 
00663   ArchRawScanResult temp_dir(rawdata);
00664   return temp_dir.RawScanIsPersisted();
00665 
00666 }
00667 
00668 
00669 
00670 
00671 RawScanResult* ArchRawScanResult::CreateRawScanResult() {
00672   
00673   
00674   string Pers_Modulename;
00675 
00676   if ( RawScanIsPersisted() == 0 ) //To be modified: retrieve histo's and data from file
00677   { 
00678       
00679       cout << "...creating new RawScanResult obj from persistency" << endl;
00680       //Add at the end of the Unique ID, after the ModuleName, the string "Persisted"
00681       int dot = Archheader->getModuleName().find('.');
00682       string Pers_ModuleID = Archheader->getModuleName().substr(0, dot).c_str();  
00683       Pers_Modulename = Pers_ModuleID + ".Persisted";
00684       
00685   
00686 
00687    } else {
00688 
00689      cout << "WARNING: the RawScanResult has NOT been persisted!!" <<endl;
00690      //Add at the end of the Unique ID, after the ModuleName, the string "Persisted"
00691      int dot = Archheader->getModuleName().find('.');
00692      string Pers_ModuleID = Archheader->getModuleName().substr(0, dot).c_str();   
00693      Pers_Modulename = Pers_ModuleID + ".Unpersisted";
00694      
00695      
00696    }
00697   
00698 
00699   shared_ptr<TH2D> RawData_link0 = shared_ptr<TH2D> ( new TH2D(theRaw->getScanData(0)) );
00700   shared_ptr<TH2D> RawData_link1 = shared_ptr<TH2D> ( new TH2D(theRaw->getScanData(1)) );
00701 
00702 
00703   ScanHeader s(scanNumber, runNumber, Pers_Modulename , *Archvariable);
00704   RawScanResult* r = new RawScanResult(s, *ArchmoduleConfig, *Archpoints, *RawData_link0, *RawData_link1 );
00705  
00706 
00707   cout<< r->getHeader().getModuleName()<<endl;
00708 
00709   return r;  //NB: it could be =NULL, as it is later 
00710 
00711 
00712 }
00713 
00714 
00715 
00716 
00717 
00718 RawScanResult* ArchRawScanResult::CreateRawScanResult(shared_ptr<RawScanResult> raw) {
00719 
00720   ArchRawScanResult tmp_createRaw(raw);
00721   return tmp_createRaw.CreateRawScanResult();
00722 
00723 }
00724 
00725 
00726 
00727 
00728 
00729 
00730 RawScanResult* ArchRawScanResult::CreateRawScanResult(long scanNumber, long runNumber, string moduleName, const ConfigurationVariable& variable, unsigned int cycle) {
00731   
00732   
00733   string Pers_Modulename;
00734   ModuleConfiguration m;
00735   //ScanPoints pts;
00736   TH2D* new_RawData_link0 = NULL;
00737   TH2D* new_RawData_link1 = NULL;
00738 
00739 
00740   ArchScanNames *new_names= new ArchScanNames(runNumber,moduleName,scanNumber, variable ); 
00741 
00742   string TH2Dlink0 = new_names->getTH2Dlink0();
00743   string TH2Dlink1 = new_names->getTH2Dlink1();
00744   string ScanPointsID = new_names->getScanPointsID() ;
00745   string vpointsID = new_names->getvpointsID();
00746   string vNEventsID = new_names->getvNEventsID();
00747   string vNErrorEventsID = new_names->getvNErrorEventsID(); 
00748   string filename = new_names->getfilename();
00749   //string objName = ;  //To be deleted
00750   string sVariable = new_names->getVariable(); 
00751   string moduleID = new_names->getModuleID(); 
00752   string testType  = new_names->getTestType(); 
00753   string runID = new_names->getRunID();
00754   string scanID = new_names->getScanID();
00755   string RODID = new_names->getRODID();
00756   string DCSID = new_names->getDCSID();
00757   string RawID = new_names->getRawID();
00758   string FitID = new_names->getFitID();
00759   string thresholdID = new_names->getThresholdID();
00760 
00761 
00762 
00763 
00764   if ( RawScanIsPersisted(scanNumber, runNumber, moduleName, variable) == 0 ) //To be modified: retrieve histo's and data from file
00765     { 
00766       
00767       cout << "...creating new RawScanResult obj from persistency" << endl;
00768       //Add at the end of the Unique ID, after the ModuleName, the string "Persisted"
00769       //string pers_
00770       int dot = moduleName.find('.');
00771       string Pers_ModuleID = moduleName.substr(0, dot).c_str();  
00772       Pers_Modulename = Pers_ModuleID + ".Persisted";
00773       
00774   
00775 
00776     } else {
00777 
00778       cout << "WARNING: the RawScanResult has NOT been persisted!!" <<endl;
00779       //Add at the end of the Unique ID, after the ModuleName, the string "Persisted"
00780       int dot = moduleName.find('.');
00781       string Pers_ModuleID = moduleName.substr(0, dot).c_str();   
00782       Pers_Modulename = Pers_ModuleID + ".Unpersisted";
00783       RawScanResult* r = NULL;   //NB: it's different from the previous two functions
00784       return r;                  
00785 
00786     }
00787 
00788   
00789   /* Variable initialisation */
00790 
00791 
00792   
00793   /* Opening File */
00794   TFile *inspect_file = new TFile(filename.c_str(),"read");
00795   if (inspect_file->IsZombie() == true) {
00796     cout << "Problem in opening the file"<<endl; 
00797  
00798   }
00799   
00800   
00801   gDirectory->cd(runID.c_str());
00802   gDirectory->cd(moduleID.c_str());
00803   gDirectory->cd(testType.c_str());
00804   gDirectory->cd(sVariable.c_str());
00805   gDirectory->cd(scanID.c_str());
00806   /*
00807 
00808   //Retrieve Threshold
00809   TObject* pers_Threshold = gDirectory->FindObjectAny(thresholdID.c_str()); 
00810   TVectorD* vpers_Threshold = dynamic_cast<TVectorD*>(pers_Threshold);
00811   double *temp_vpers_Threshold = vpers_Threshold->GetElements();
00812   m.threshold = temp_vpers_Threshold[0];
00813 */
00814   
00815   /* ?????????? Retrieve ScanPoints...!!!!I know it's a very bad coding!!!! ??????? TO BE CHECKED ???????*/
00816   TObject* pers_vscanpoints = gDirectory->FindObjectAny(vpointsID.c_str()); 
00817   TVector* vpers_vscanpoints = dynamic_cast<TVector*>(pers_vscanpoints); 
00818   //TVector* vpers_vscanpoints = NULL;
00819   //vpers_vscanpoints->Read(vpointsID.c_str());
00820   //float *temp_vpers_vscanpoints = vpers_vscanpoints->GetElements(); 
00821   float *temp_vpers_vscanpoints = NULL;
00822   temp_vpers_vscanpoints = vpers_vscanpoints->GetElements();
00823 
00824   TObject* pers_vNEvents = gDirectory->FindObjectAny(vNEventsID.c_str());
00825   TVector* vpers_vNEvents = dynamic_cast<TVector*>(pers_vNEvents); 
00826   
00827   int NoElements = vpers_vNEvents->GetNoElements();  
00828   
00830   unsigned int temp_vpers_vNEvents[NoElements];
00831   unsigned int truncated_vpers_vNEvents;
00832   for (int i=0; i<NoElements; ++i) {
00833     truncated_vpers_vNEvents = int(*vpers_vNEvents->GetElements());
00834     //cout<< " I am here" <<endl;
00835     temp_vpers_vNEvents[i] = truncated_vpers_vNEvents;
00836   }
00837 
00838  
00839   TObject* pers_vNErrorEvents = gDirectory->FindObjectAny(vNErrorEventsID.c_str());
00840   TVector* vpers_vNErrorEvents = dynamic_cast<TVector*>(pers_vNErrorEvents); 
00842   unsigned int temp_vpers_vNErrorEvents[NoElements];
00843   unsigned int truncated_vpers_vNErrorEvents;
00844   for (int i=0; i<NoElements; ++i) {
00845     truncated_vpers_vNErrorEvents = int(*vpers_vNErrorEvents->GetElements());
00846     temp_vpers_vNErrorEvents[i] = truncated_vpers_vNErrorEvents;
00847   }
00848 
00849 
00850   ScanPoints *pts = new ScanPoints( NoElements, temp_vpers_vscanpoints ,temp_vpers_vNEvents ,temp_vpers_vNErrorEvents );
00851   /*??????????????????????????????????????????????????????????????????????????*/
00852 
00853 
00854 
00855 
00856   gDirectory->cd(RODID.c_str());
00857   gDirectory->cd(RawID.c_str());
00858 
00859  
00860   //Check if the two TH2D hist's have been persisted
00861   TObject* pers_RawTH2link0 = gDirectory->FindObjectAny(TH2Dlink0.c_str()); 
00862   //Retrieve new_TH2Dlink0
00863 
00864   new_RawData_link0 = dynamic_cast<TH2D*>(pers_RawTH2link0);
00865 
00866   
00867   TObject* pers_RawTH2link1 = gDirectory->FindObjectAny(TH2Dlink1.c_str()); 
00868   //Retrieve new_TH2Dlink1
00869   new_RawData_link1 = dynamic_cast<TH2D*>(pers_RawTH2link1);
00870   
00871 
00872 
00873 
00874 
00875   /*Creating RawScanResult object */
00876   ScanHeader s(scanNumber, runNumber, Pers_Modulename , variable);
00877   RawScanResult* r = new RawScanResult(s, m, *pts, *new_RawData_link0, *new_RawData_link1 ); 
00878   cout<< r->getHeader().getModuleName()<<endl;
00879   return r;
00880 
00881 
00882 }
00883 
00884 
00885 
00886 
00887 
00888 
00889 void ArchRawScanResult::SaveRawComment() {
00890 
00891   // Saving Txt Comments at the Fun level
00892   
00893   string filename = names->getfilename();
00894   string runID = names->getRunID();
00895   string moduleID = names->getModuleID();
00896   string testType = names->getTestType();
00897   string variable = names->getVariable();
00898   string scanID = names->getScanID();
00899   string RODID = names->getRODID();
00900   string RawID = names->getRawID();
00901 
00902   TFile *file = new TFile(filename.c_str(),"update");
00903   if (file->IsZombie() == true) {
00904     cout << "The ScanResult has NOT been saved in any file"<<endl; 
00905     return ;
00906   }
00907   /* Making RunNumber */
00908   TDirectory *this_run = (TDirectory*) gDirectory->Get(runID.c_str()); 
00909   if (!this_run) {
00910     //cout<<"This NEW run "<< runID <<" doesn't exist"<<endl;
00911     this_run = file->mkdir(runID.c_str());
00912     //cout<<"New RunNumber Dir made "<<endl;
00913   }
00914   this_run->cd();  //make this_run the current directory
00915 
00916   /* Making moduleNumber   */
00917   
00918   TDirectory* this_module = (TDirectory*) gDirectory->Get(moduleID.c_str()); //Can be made using FindAnyObject
00919   if (!this_module) {
00920     //cout<<"This NEW module "<< moduleID <<" doesn't exist"<<endl;
00921     this_module =gDirectory ->mkdir(moduleID.c_str());
00922   }
00923   this_module->cd();
00924 
00925 
00926   /* Making TestType   */
00927   TDirectory* this_testType = (TDirectory*) gDirectory->Get(testType.c_str());
00928   if (!this_testType) {
00929     //cout<<"This NEW test "<< testType <<" doesn't exist"<<endl;
00930     this_testType = gDirectory->mkdir(testType.c_str());
00931   }
00932   this_testType->cd();
00933 
00934   
00935   /* Making Variable   */
00936   TDirectory* this_variable = (TDirectory*) gDirectory->Get(variable.c_str());
00937   if (!this_variable) {
00938     //cout<<"This NEW test "<< variable <<" doesn't exist"<<endl;
00939     this_variable = gDirectory->mkdir(variable.c_str());
00940   }
00941   this_variable->cd();
00942 
00943   /* Making scanNumber   */
00944   TDirectory* this_scan = (TDirectory*) gDirectory->Get(scanID.c_str());
00945   if (!this_scan) {
00946     //cout<<"This NEW scan "<< scanID <<" doesn't exist"<<endl;
00947     this_scan =gDirectory ->mkdir(scanID.c_str());
00948   }
00949   this_scan->cd();   
00950 
00951   /* Making ROD   */ 
00952   TDirectory* this_ROD = (TDirectory*) this_scan->Get(RODID.c_str());
00953   if (!this_ROD) {
00954     //cout<<"This NEW ROD  doesn't exist"<<endl;
00955     this_ROD = this_scan->mkdir(RODID.c_str());
00956   }
00957   this_ROD->cd();
00958  
00959   /* Making ROD Raw    */
00960     TDirectory* this_raw = (TDirectory*) this_ROD->Get(RawID.c_str()); 
00961     if (!this_raw) {
00962       //cout<<"This NEW Raw Data  doesn't exist"<<endl;
00963       this_raw = this_ROD->mkdir(RawID.c_str());
00964     }
00965     this_raw->cd();  
00966 
00967 
00968 
00969   //...Opening TxtComment file 
00970   ifstream in;
00971   in.open(names->getTxtCommentRawName().c_str());
00972 
00973   int commentN;
00974     int sz = 1000; // Buffer size;
00975     char buf[sz];
00976     
00977     //char TxtComment[40];
00978     int nlines = 0;
00979     while (1) {
00980       in >> commentN;
00981       in.get(buf, sz);
00982       if (!in.good()) break;
00983       //cout<< " CommentN = "<< commentN << " String = "<< buf <<endl;
00984       TObjString Comment(buf);
00985       //sprintf(TxtComment,"TxtComment_%i",commentN);
00986       TObject* pers_TxtCommentN = gDirectory->FindObjectAny(names->getRawTxtComment(commentN).c_str());
00987       if (!pers_TxtCommentN) {
00988     //cout<<" TxtComment Never Persisted...persisting" <<endl;
00989     Comment.Write(names->getRawTxtComment(commentN).c_str());
00990       }
00991       nlines++;   
00992     }
00993     //printf(" found %d points \n",nlines);
00994     
00995     
00996     in.close();
00997     file->Close();
00998 
00999 }
01000 

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