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

ArchFitScanResult.cpp

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

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