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

ArchFitScanResult.cpp

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

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