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

ArchRawScanResult.cpp

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

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