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

ArchScanResult.cpp

00001 #include "ArchScanResult.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 <fstream>
00019 #include <iostream>
00020 #include <vector>
00021 
00022 #include "sctConfIPC/configipc.h"
00023 
00024 using namespace SctConfiguration;
00025 
00026 
00027 /********************************** ArchScan Methods Definitions ************************/
00028 
00029 
00030 /***********************  Constructor  *************** */
00031 
00032 ArchScanResult::ArchScanResult()  {
00033 
00034   //cout<< "I am in the ArchScanResult Default Constructor"<< endl;
00035   
00036 
00037   /*--- Initialisation ---*/
00038   Archheader = NULL;
00039   ArchmoduleConfig = NULL;
00040   Archpoints = NULL;
00041   Archvariable = NULL;
00042   //TABCDModuleConfig = NULL;
00043 
00044   runNumber = 0;
00045   scanNumber = 0;
00046   //threshold = 0;
00047 
00048   names = new ArchScanTxtNames();
00049 
00050   
00051 
00052   gpoints = NULL;
00053   vpoints = NULL;
00054   vNEvents = NULL;
00055   vNErrorEvents = NULL;
00056 
00057 }
00058   
00059   
00060 ArchScanResult::ArchScanResult(shared_ptr<const ScanResult>  scan)  {
00061 
00062   //cout<< "I am in the ArchScanResult Constructor"<< endl;
00063   
00064   
00065 
00066   /*--- SCTData Initialisation ---*/
00067     Archheader = &scan->getHeader();          //These might me deleted at some point
00068     ArchmoduleConfig = &scan->getConfiguration();
00069     Archpoints = &scan->getPoints();
00070     Archvariable = &Archheader->getVariable();
00071     
00072 
00073     // Initialise ModuleConfiguration    
00074     const ABCDModule ABCDModuleConfig = ArchmoduleConfig->getABCDModule();
00075     
00076     
00077 
00078 
00079 
00080   /*--- Archiving Variables Initialisation ---*/
00081 
00082     runNumber = Archheader->getRunNumber() ;
00083     scanNumber = Archheader->getScanNumber() ;
00084     moduleName = Archheader->getModuleName();
00085 
00086 //    threshold = ArchmoduleConfig->threshold;
00087 
00088     //cout<< "runNumber = " <<runNumber<<endl;
00089     //cout<< "scanNumber = " <<scanNumber<<endl;
00090 //    cout<< "threshold = " <<threshold<<endl;
00091 
00092 
00093     names = new ArchScanTxtNames(runNumber, Archheader->getModuleName(), scanNumber, *Archvariable );
00094     objName = scan->getUniqueID();   
00095 
00096 
00097     
00098     float x[Archpoints->getNPoints()], y[Archpoints->getNPoints()],err[Archpoints->getNPoints()] ;
00099     for(unsigned int i=0;i<Archpoints->getNPoints();++i) {
00100       x[i] = Archpoints->getPoint(i);
00101       y[i] = Archpoints->getNEvents(i);
00102       err[i] = Archpoints->getNErrorEvents(i);
00103     }
00104     gpoints = new TGraph(Archpoints->getNPoints(),x,y);
00105 
00106 
00107     
00108     //Save points as TVector's    
00109     vpoints = new TVector(0, Archpoints->getNPoints(),x);
00110     vNEvents = new TVector(0, Archpoints->getNPoints(),y);
00111     vNErrorEvents = new TVector(0, Archpoints->getNPoints(),err);
00112     
00113     
00114 
00115 
00116 
00117 }
00118 
00119 
00120 
00121 
00122 
00123 /**********************  Other Member Functions  *********************/
00124 
00125 ArchScanResult::~ArchScanResult()  {
00126   
00127   //cout << "I am in the ArchScanResult Destructor" << endl;
00128   
00129   
00130   
00131 
00132   
00133 }
00134 
00135 
00136 
00137 
00138 
00139 TObjString ArchScanResult::getModuleConfigTObjString() {
00140   /*
00141     Gets the current ABCDModule Comfiguration from sctConfig, through IPC, as an xml file, 
00142     and converts it into a TObjString
00143   **/
00144   ConfigIPC config;
00145   string tmp_ModuleConfig = config.getModuleConfigurationString(moduleName, ABCDModuleConfig);
00146   const char* tmp_char = tmp_ModuleConfig.c_str();
00147   TObjString ABCDModuleTObjString(tmp_char);
00148   TString tmp_string = ABCDModuleTObjString.String();
00149   cout<< "Module Configuration :" << endl << tmp_string.Data()<<endl;
00150   
00151   return ABCDModuleTObjString;
00152   
00153 
00154 
00155 }
00156     
00157 
00158 
00159 
00160 
00161 
00162 void ArchScanResult::SetScan(shared_ptr<const ScanResult>  scan) {
00163 
00164   /* This functions sets all the ArchScanResult member data*/
00165 
00166 
00167 /*--- SctData Initialisation ---*/
00168     Archheader = &scan->getHeader();          //These might me deleted at some point
00169     ArchmoduleConfig = &scan->getConfiguration();
00170     Archpoints = &scan->getPoints();
00171     Archvariable = &Archheader->getVariable();
00172 
00173 
00174   /*--- Archiving Variables Initialisation ---*/
00175 
00176     runNumber = Archheader->getRunNumber() ;
00177     scanNumber = Archheader->getScanNumber() ;
00178 //    threshold = ArchmoduleConfig->threshold;
00179 
00180     //cout<< "runNumber = " <<runNumber<<endl;
00181     //cout<< "scanNumber = " <<scanNumber<<endl;
00182 //    cout<< "threshold = " <<threshold<<endl;
00183 
00184     
00185     names = new ArchScanTxtNames(runNumber, Archheader->getModuleName(), scanNumber, *Archvariable );
00186     objName = scan->getUniqueID();   
00187 
00188 
00189     
00190     float x[Archpoints->getNPoints()], y[Archpoints->getNPoints()],err[Archpoints->getNPoints()];
00191     for(unsigned int i=0;i<Archpoints->getNPoints();++i) {
00192       x[i] = Archpoints->getPoint(i);
00193       y[i] = Archpoints->getNEvents(i);
00194       err[i] = Archpoints->getNErrorEvents(i);
00195     }
00196     gpoints = new TGraph(Archpoints->getNPoints(),x,y);
00197     
00198 
00199     vpoints = new TVector(0, Archpoints->getNPoints(),x);
00200     vNEvents = new TVector(0, Archpoints->getNPoints(),y);
00201     vNErrorEvents = new TVector(0, Archpoints->getNPoints(),err);
00202 
00203 
00204 
00205 
00206 
00207 
00208 }
00209 
00210 
00211 
00212 
00213 
00214 void ArchScanResult::SetTestType(string tType) {
00215 
00216   names->setTestType( tType );
00217   //cout <<" TestType = " << names->getTestType()<<endl;
00218 }
00219 
00220 
00221 const vector <string>& ArchScanResult::getAllSavedScansList() {
00222 
00223  /* Check if the current RawScanResult of the current Test has been persisted*/
00224    
00225 
00226  
00227   //TO DO: Extend to all files in DataArchive dir and loop over all of them
00228   string filename = names->getfilename(); 
00229   TFile *inspect_file = new TFile(filename.c_str(),"read");
00230   if (inspect_file->IsZombie() == true) {
00231     cout << "Problem in opening file"<<endl; 
00232     return SavedScansList;
00233     
00234   } 
00235   
00236   //TDirectory *gRunDir = new TDirectory();
00237   TDirectory *gModuleDir = new TDirectory();
00238   TDirectory *gRODDir = new TDirectory();
00239   TDirectory *gtestTypeDir = new TDirectory();
00240   TDirectory *gvariableDir = new TDirectory();
00241   TDirectory *gscanDir = new TDirectory();
00242 
00243 
00244   //gDirectory->ls();
00245   TList* runsList = gDirectory->GetListOfKeys();
00246   TListIter itruns(runsList);
00247   while (TObject *runsobj = itruns.Next()) { 
00248     //runsobj->Print();
00249     //cout<< "Run OBJ Name = " << runsobj->GetName() <<endl;
00250     string runID = runsobj->GetName();
00251     if (runsobj->GetTitle() == runID ) {
00252       if (gDirectory->cd(runID.c_str())==1) {
00253     
00254     gModuleDir = gDirectory;
00255     TList* modulesList = gDirectory->GetListOfKeys();
00256     TListIter itmodules(modulesList); 
00257     while (TObject *modulesobj = itmodules.Next()) { 
00258       string moduleID = modulesobj->GetName();
00259       string modulesobjID = modulesobj->GetTitle(); 
00261       if (modulesobj->GetTitle() == moduleID ) {
00262         gModuleDir->cd();
00263         if (gDirectory->cd(moduleID.c_str())== 1) {
00264 
00265           gtestTypeDir = gDirectory;
00266           TList* testTypeList = gDirectory->GetListOfKeys();
00267           TListIter ittestType(testTypeList); 
00268           while (TObject *testTypeobj = ittestType.Next()) { 
00269         string testTypeID = testTypeobj->GetName();
00270         if (testTypeobj->GetTitle() == testTypeID ) {
00271           gtestTypeDir->cd();
00272           if (gDirectory->cd(testTypeID.c_str())==1 ) {
00273             
00274             gvariableDir = gDirectory;
00275             TList* variableList = gDirectory->GetListOfKeys();
00276             TListIter itvariable(variableList); 
00277             while (TObject *variableobj = itvariable.Next()) { 
00278               string variableID = variableobj->GetName();
00279               if (variableobj->GetTitle() == variableID ) {
00280             gvariableDir->cd();
00281             if (gDirectory->cd(variableID.c_str())==1 ) {
00282               gDirectory->Print();
00283 
00284               gscanDir = gDirectory;
00285               TList* scanList = gDirectory->GetListOfKeys();
00286               TListIter itscan(scanList); 
00287               while (TObject *scanobj = itscan.Next()) { 
00288                 string scanID = scanobj->GetName();
00289                 if (scanobj->GetTitle() == scanID ) {
00290                   gscanDir->cd();
00291                   if (gDirectory->cd(scanID.c_str())==1 ) {
00292                 
00293                 if (gDirectory->cd(names->getDCSID().c_str())==1 ) {    // TO BE DONE
00294                   
00295                   gDirectory->cd("../");
00296                   if (gDirectory->cd(names->getRODID().c_str())==1 ) {
00297                     
00298                     
00299                     gRODDir = gDirectory;
00300                     if (gDirectory->cd(names->getRawID().c_str())==1 ) {
00301                       string tmp_SavedScan = gDirectory->GetPath();
00302                       SavedScansList.push_back(tmp_SavedScan);
00303                       
00304                     }  
00305             
00306                     gRODDir->cd();
00307                     if (gDirectory->cd(names->getFitID().c_str())==1 ) {
00308                       string tmp_SavedScan = gDirectory->GetPath();
00309                       SavedScansList.push_back(tmp_SavedScan);
00310                
00311                     }  
00312                   }
00313                 }
00314                   }
00315                 }
00316               }
00317             }
00318               }
00319             }
00320           }
00321         }
00322           }
00323         }
00324       }
00325     }
00326       }
00327     }
00328   }
00329   
00330   
00331 
00332   return SavedScansList;
00333 
00334 }
00335 
00336 
00337 
00338 
00339 void ArchScanResult::AddScanToIndex()  {
00340   
00341   /* Append current Test to the Index  */
00342 
00343   //cout << "I am in AddScanToIndex() " << endl;
00344   string index = names->getIndexFileName(); 
00345   ofstream index_file;
00346   index_file.open(index.c_str(),ios::app);  //append the Index File
00347   //assure(index_file,index.c_str());  //TO DO
00348  
00349   string indexScanName = names->getRunID() + ".";
00350   indexScanName = indexScanName + names->getModuleID();
00351   indexScanName = indexScanName + ".";
00352   indexScanName = indexScanName + names->getTestType() + ".";
00353   indexScanName = indexScanName + names->getScanID();
00354   cout << indexScanName <<endl;
00355   //if(ScanIsPersisted()) {
00356     index_file << indexScanName <<endl;
00357     cout << "Scan appended to Index"<<endl;    
00358   //} else {
00359   //  cout<<"Scan NOT correctly saved in the archive...test NOT added to the Index"<<endl;
00360   //}
00361   
00362   index_file.close(); 
00363   
00364 }
00365 
00366 
00367 void ArchScanResult::SaveFileComment() {
00368 
00369   // Saving Txt Comments at the Fun level
00370 
00371   string filename = names->getfilename();
00372   
00373   TFile *file = new TFile(filename.c_str(),"update");
00374   if (file->IsZombie() == true) {
00375     cout << "The ScanResult has NOT been saved in any file"<<endl; 
00376     return ;
00377   }
00378   
00379 
00380   //...Opening TxtComment file 
00381   ifstream in;
00382   in.open(names->getTxtCommentAllFilesName().c_str());
00383 
00384   int commentN;
00385     int sz = 1000; // Buffer size;
00386     char buf[sz];
00387     
00388     //char FileTxtComment[40];
00389     int nlines = 0;
00390     while (1) {
00391       in >> commentN;
00392       in.get(buf, sz);
00393       if (!in.good()) break;
00394       //cout<< " CommentN = "<< commentN << " String = "<< buf <<endl;
00395       TObjString FileComment(buf);
00396       //sprintf(FileTxtComment,"FileTxtComment_%i",commentN);
00397       TObject* pers_FileTxtCommentN = gDirectory->FindObjectAny(names->getAllFilesTxtComment(commentN).c_str());
00398       if (!pers_FileTxtCommentN) {
00399     //cout<<" FileTxtComment Never Persisted...persisting" <<endl;
00400     FileComment.Write(names->getAllFilesTxtComment(commentN).c_str());
00401       }
00402       nlines++;   
00403     }
00404     //printf(" found %d points \n",nlines);
00405     
00406     
00407     in.close();
00408     file->Close();
00409 
00410 }
00411 
00412 
00413 
00414 void ArchScanResult::SaveRunComment() {
00415 
00416   // Saving Txt Comments at the Fun level
00417 
00418   string filename = names->getfilename();
00419   string runID = names->getRunID();
00420   TFile *file = new TFile(filename.c_str(),"update");
00421   if (file->IsZombie() == true) {
00422     cout << "The ScanResult has NOT been saved in any file"<<endl; 
00423     return ;
00424   }
00425   /* Making RunNumber */
00426   TDirectory *this_run = (TDirectory*) gDirectory->Get(runID.c_str()); 
00427   if (!this_run) {
00428     //cout<<"This NEW run "<< runID <<" doesn't exist"<<endl;
00429     this_run = file->mkdir(runID.c_str());
00430     //cout<<"New RunNumber Dir made "<<endl;
00431   }
00432   this_run->cd();  //make this_run the current directory
00433 
00434 
00435   //...Opening TxtComment file 
00436   ifstream in;
00437   in.open(names->getTxtCommentRunName().c_str());
00438 
00439   int commentN;
00440     int sz = 1000; // Buffer size;
00441     char buf[sz];
00442     
00443     //char RunTxtComment[40];
00444     int nlines = 0;
00445     while (1) {
00446       in >> commentN;
00447       in.get(buf, sz);
00448       if (!in.good()) break;
00449       //cout<< " CommentN = "<< commentN << " String = "<< buf <<endl;
00450       TObjString RunComment(buf);
00451       //sprintf(RunTxtComment,"RunTxtComment_%i",commentN);
00452       TObject* pers_RunTxtCommentN = gDirectory->FindObjectAny(names->getRunTxtComment(commentN).c_str());
00453       if (!pers_RunTxtCommentN) {
00454     //cout<<" RunTxtComment Never Persisted...persisting" <<endl;
00455     RunComment.Write(names->getRunTxtComment(commentN).c_str());
00456       }
00457       nlines++;   
00458     }
00459     //printf(" found %d points \n",nlines);
00460     
00461     
00462     in.close();
00463     file->Close();
00464 
00465 }
00466 
00467 
00468 void ArchScanResult::SaveModuleComment() {
00469 
00470   // Saving Txt Comments at the Fun level
00471   
00472   string filename = names->getfilename();
00473   string runID = names->getRunID();
00474   string moduleID = names->getModuleID();
00475 
00476   TFile *file = new TFile(filename.c_str(),"update");
00477   if (file->IsZombie() == true) {
00478     cout << "The ScanResult has NOT been saved in any file"<<endl; 
00479     return ;
00480   }
00481   /* Making RunNumber */
00482   TDirectory *this_run = (TDirectory*) gDirectory->Get(runID.c_str()); 
00483   if (!this_run) {
00484     //cout<<"This NEW run "<< runID <<" doesn't exist"<<endl;
00485     this_run = file->mkdir(runID.c_str());
00486     //cout<<"New RunNumber Dir made "<<endl;
00487   }
00488   this_run->cd();  //make this_run the current directory
00489 
00490   /* Making moduleNumber   */
00491   
00492   TDirectory* this_module = (TDirectory*) gDirectory->Get(moduleID.c_str()); //Can be made using FindAnyObject
00493   if (!this_module) {
00494     //cout<<"This NEW module "<< moduleID <<" doesn't exist"<<endl;
00495     this_module =gDirectory ->mkdir(moduleID.c_str());
00496   }
00497   this_module->cd();
00498 
00499   
00500   
00501   //...Opening TxtComment file 
00502   ifstream in;
00503   in.open(names->getTxtCommentModuleName().c_str());
00504   
00505 
00506   int commentN;
00507     int sz = 1000; // Buffer size;
00508     char buf[sz];
00509     
00510     
00511     //char ModuleTxtComment[40];
00512     int nlines = 0;
00513     while (1) {
00514       in >> commentN;
00515       in.get(buf, sz);
00516       if (!in.good()) break;
00517       //cout<< " CommentN = "<< commentN << " String = "<< buf <<endl;
00518       TObjString Comment(buf);
00519       //sprintf(ModuleTxtComment,"TxtComment_%i",ModulecommentN);
00520       TObject* pers_ModuleTxtCommentN = gDirectory->FindObjectAny(names->getModuleTxtComment(commentN).c_str());
00521       if (!pers_ModuleTxtCommentN) {
00522     //cout<<" TxtComment Never Persisted...persisting" <<endl;
00523       Comment.Write(names->getModuleTxtComment(commentN).c_str());
00524       }
00525       nlines++;   
00526     }
00527     //printf(" found %d points \n",nlines);
00528     
00529 
00530     in.close();
00531     file->Close();
00532     
00533 
00534 }
00535 
00536 
00537 
00538 void ArchScanResult::SaveTestComment() {
00539 
00540   // Saving Txt Comments at the Fun level
00541   
00542   string filename = names->getfilename();
00543   string runID = names->getRunID();
00544   string moduleID = names->getModuleID();
00545   string testType = names->getTestType();
00546   TFile *file = new TFile(filename.c_str(),"update");
00547   if (file->IsZombie() == true) {
00548     cout << "The ScanResult has NOT been saved in any file"<<endl; 
00549     return ;
00550   }
00551   /* Making RunNumber */
00552   TDirectory *this_run = (TDirectory*) gDirectory->Get(runID.c_str()); 
00553   if (!this_run) {
00554     //cout<<"This NEW run "<< runID <<" doesn't exist"<<endl;
00555     this_run = file->mkdir(runID.c_str());
00556     //cout<<"New RunNumber Dir made "<<endl;
00557   }
00558   this_run->cd();  //make this_run the current directory
00559 
00560   /* Making moduleNumber   */
00561   
00562   TDirectory* this_module = (TDirectory*) gDirectory->Get(moduleID.c_str()); //Can be made using FindAnyObject
00563   if (!this_module) {
00564     //cout<<"This NEW module "<< moduleID <<" doesn't exist"<<endl;
00565     this_module =gDirectory ->mkdir(moduleID.c_str());
00566   }
00567   this_module->cd();
00568 
00569 
00570   /* Making TestType   */
00571   TDirectory* this_testType = (TDirectory*) gDirectory->Get(testType.c_str());
00572   if (!this_testType) {
00573     //cout<<"This NEW test "<< testType <<" doesn't exist"<<endl;
00574     this_testType = gDirectory->mkdir(testType.c_str());
00575   }
00576   this_testType->cd();
00577 
00578 
00579 
00580   //...Opening TxtComment file 
00581   ifstream in;
00582   in.open(names->getTxtCommentTestName().c_str());
00583 
00584   int commentN;
00585     int sz = 1000; // Buffer size;
00586     char buf[sz];
00587     
00588     //char TxtComment[40];
00589     int nlines = 0;
00590     while (1) {
00591       in >> commentN;
00592       in.get(buf, sz);
00593       if (!in.good()) break;
00594       //cout<< " CommentN = "<< commentN << " String = "<< buf <<endl;
00595       TObjString Comment(buf);
00596       //sprintf(TxtComment,"TxtComment_%i",commentN);
00597       TObject* pers_TxtCommentN = gDirectory->FindObjectAny(names->getTestTxtComment(commentN).c_str());
00598       if (!pers_TxtCommentN) {
00599     //cout<<" TxtComment Never Persisted...persisting" <<endl;
00600     Comment.Write(names->getTestTxtComment(commentN).c_str());
00601       }
00602       nlines++;   
00603     }
00604     //printf(" found %d points \n",nlines);
00605     
00606     
00607     in.close();
00608     file->Close();
00609 
00610 }
00611 
00612 
00613 void ArchScanResult::SaveVariableComment() {
00614 
00615   // Saving Txt Comments at the Fun level
00616   
00617   string filename = names->getfilename();
00618   string runID = names->getRunID();
00619   string moduleID = names->getModuleID();
00620   string testType = names->getTestType();
00621   string variable = names->getVariable();
00622 
00623   TFile *file = new TFile(filename.c_str(),"update");
00624   if (file->IsZombie() == true) {
00625     cout << "The ScanResult has NOT been saved in any file"<<endl; 
00626     return ;
00627   }
00628   /* Making RunNumber */
00629   TDirectory *this_run = (TDirectory*) gDirectory->Get(runID.c_str()); 
00630   if (!this_run) {
00631     //cout<<"This NEW run "<< runID <<" doesn't exist"<<endl;
00632     this_run = file->mkdir(runID.c_str());
00633     //cout<<"New RunNumber Dir made "<<endl;
00634   }
00635   this_run->cd();  //make this_run the current directory
00636 
00637   /* Making moduleNumber   */
00638   
00639   TDirectory* this_module = (TDirectory*) gDirectory->Get(moduleID.c_str()); //Can be made using FindAnyObject
00640   if (!this_module) {
00641     //cout<<"This NEW module "<< moduleID <<" doesn't exist"<<endl;
00642     this_module =gDirectory ->mkdir(moduleID.c_str());
00643   }
00644   this_module->cd();
00645 
00646 
00647   /* Making TestType   */
00648   TDirectory* this_testType = (TDirectory*) gDirectory->Get(testType.c_str());
00649   if (!this_testType) {
00650     //cout<<"This NEW test "<< testType <<" doesn't exist"<<endl;
00651     this_testType = gDirectory->mkdir(testType.c_str());
00652   }
00653   this_testType->cd();
00654 
00655   
00656   /* Making Variable   */
00657   TDirectory* this_variable = (TDirectory*) gDirectory->Get(variable.c_str());
00658   
00659   if (!this_variable) {
00660     //cout<<"This NEW test "<< variable <<" doesn't exist"<<endl;
00661     this_variable = gDirectory->mkdir(variable.c_str());
00662   }
00663   this_variable->cd();
00664 
00665 
00666 
00667   //...Opening TxtComment file 
00668   ifstream in;
00669   in.open(names->getTxtCommentVariableName().c_str());
00670 
00671   int commentN;
00672     int sz = 1000; // Buffer size;
00673     char buf[sz];
00674     
00675     //char TxtComment[40];
00676     int nlines = 0;
00677     while (1) {
00678       in >> commentN;
00679       in.get(buf, sz);
00680       if (!in.good()) break;
00681       //cout<< " CommentN = "<< commentN << " String = "<< buf <<endl;
00682       TObjString Comment(buf);
00683       //sprintf(TxtComment,"TxtComment_%i",commentN);
00684       TObject* pers_TxtCommentN = gDirectory->FindObjectAny(names->getVariableTxtComment(commentN).c_str());
00685       if (!pers_TxtCommentN) {
00686     //cout<<" TxtComment Never Persisted...persisting" <<endl;
00687     Comment.Write(names->getVariableTxtComment(commentN).c_str());
00688       }
00689       nlines++;   
00690     }
00691     //printf(" found %d points \n",nlines);
00692     
00693     
00694     in.close();
00695     file->Close();
00696 
00697 }
00698 
00699 
00700 
00701 void ArchScanResult::SaveScanNumberComment() {
00702 
00703   // Saving Txt Comments at the Fun level
00704   
00705   string filename = names->getfilename();
00706   string runID = names->getRunID();
00707   string moduleID = names->getModuleID();
00708   string testType = names->getTestType();
00709   string variable = names->getVariable();
00710   string scanID = names->getScanID();
00711 
00712   TFile *file = new TFile(filename.c_str(),"update");
00713   if (file->IsZombie() == true) {
00714     cout << "The ScanResult has NOT been saved in any file"<<endl; 
00715     return ;
00716   }
00717   /* Making RunNumber */
00718   TDirectory *this_run = (TDirectory*) gDirectory->Get(runID.c_str()); 
00719   if (!this_run) {
00720     //cout<<"This NEW run "<< runID <<" doesn't exist"<<endl;
00721     this_run = file->mkdir(runID.c_str());
00722     //cout<<"New RunNumber Dir made "<<endl;
00723   }
00724   this_run->cd();  //make this_run the current directory
00725 
00726   /* Making moduleNumber   */
00727   
00728   TDirectory* this_module = (TDirectory*) gDirectory->Get(moduleID.c_str()); //Can be made using FindAnyObject
00729   if (!this_module) {
00730     //cout<<"This NEW module "<< moduleID <<" doesn't exist"<<endl;
00731     this_module =gDirectory ->mkdir(moduleID.c_str());
00732   }
00733   this_module->cd();
00734 
00735 
00736   /* Making TestType   */
00737   TDirectory* this_testType = (TDirectory*) gDirectory->Get(testType.c_str());
00738   if (!this_testType) {
00739     //cout<<"This NEW test "<< testType <<" doesn't exist"<<endl;
00740     this_testType = gDirectory->mkdir(testType.c_str());
00741   }
00742   this_testType->cd();
00743 
00744   
00745   /* Making Variable   */
00746   TDirectory* this_variable = (TDirectory*) gDirectory->Get(variable.c_str());
00747   if (!this_variable) {
00748     //cout<<"This NEW test "<< variable <<" doesn't exist"<<endl;
00749     this_variable = gDirectory->mkdir(variable.c_str());
00750   }
00751   this_variable->cd();
00752 
00753   /* Making scanNumber   */
00754   TDirectory* this_scan = (TDirectory*) gDirectory->Get(scanID.c_str());
00755   if (!this_scan) {
00756     //cout<<"This NEW scan "<< scanID <<" doesn't exist"<<endl;
00757     this_scan =gDirectory ->mkdir(scanID.c_str());
00758   }
00759   this_scan->cd();   
00760 
00761 
00762 
00763   //...Opening TxtComment file 
00764   ifstream in;
00765   in.open(names->getTxtCommentScanNumberName().c_str());
00766 
00767   int commentN;
00768     int sz = 1000; // Buffer size;
00769     char buf[sz];
00770     
00771     //char TxtComment[40];
00772     int nlines = 0;
00773     while (1) {
00774       in >> commentN;
00775       in.get(buf, sz);
00776       if (!in.good()) break;
00777       //cout<< " CommentN = "<< commentN << " String = "<< buf <<endl;
00778       TObjString Comment(buf);
00779       //sprintf(TxtComment,"TxtComment_%i",commentN);
00780       TObject* pers_TxtCommentN = gDirectory->FindObjectAny(names->getScanNumberTxtComment(commentN).c_str());
00781       if (!pers_TxtCommentN) {
00782     //cout<<" TxtComment Never Persisted...persisting" <<endl;
00783     Comment.Write(names->getScanNumberTxtComment(commentN).c_str());
00784       }
00785       nlines++;   
00786     }
00787     //printf(" found %d points \n",nlines);
00788     
00789     
00790     in.close();
00791     file->Close();
00792 
00793 }
00794 
00795 
00796 void ArchScanResult::SaveRODComment() {
00797 
00798   // Saving Txt Comments at the Fun level
00799   
00800   string filename = names->getfilename();
00801   string runID = names->getRunID();
00802   string moduleID = names->getModuleID();
00803   string testType = names->getTestType();
00804   string variable = names->getVariable();
00805   string scanID = names->getScanID();
00806   string RODID = names->getRODID();
00807 
00808   TFile *file = new TFile(filename.c_str(),"update");
00809   if (file->IsZombie() == true) {
00810     cout << "The ScanResult has NOT been saved in any file"<<endl; 
00811     return ;
00812   }
00813   /* Making RunNumber */
00814   TDirectory *this_run = (TDirectory*) gDirectory->Get(runID.c_str()); 
00815   if (!this_run) {
00816     //cout<<"This NEW run "<< runID <<" doesn't exist"<<endl;
00817     this_run = file->mkdir(runID.c_str());
00818     //cout<<"New RunNumber Dir made "<<endl;
00819   }
00820   this_run->cd();  //make this_run the current directory
00821 
00822   /* Making moduleNumber   */
00823   
00824   TDirectory* this_module = (TDirectory*) gDirectory->Get(moduleID.c_str()); //Can be made using FindAnyObject
00825   if (!this_module) {
00826     //cout<<"This NEW module "<< moduleID <<" doesn't exist"<<endl;
00827     this_module =gDirectory ->mkdir(moduleID.c_str());
00828   }
00829   this_module->cd();
00830 
00831 
00832   /* Making TestType   */
00833   TDirectory* this_testType = (TDirectory*) gDirectory->Get(testType.c_str());
00834   if (!this_testType) {
00835     //cout<<"This NEW test "<< testType <<" doesn't exist"<<endl;
00836     this_testType = gDirectory->mkdir(testType.c_str());
00837   }
00838   this_testType->cd();
00839 
00840   
00841   /* Making Variable   */
00842   TDirectory* this_variable = (TDirectory*) gDirectory->Get(variable.c_str());
00843   if (!this_variable) {
00844     //cout<<"This NEW test "<< variable <<" doesn't exist"<<endl;
00845     this_variable = gDirectory->mkdir(variable.c_str());
00846   }
00847   this_variable->cd();
00848 
00849   /* Making scanNumber   */
00850   TDirectory* this_scan = (TDirectory*) gDirectory->Get(scanID.c_str());
00851   if (!this_scan) {
00852     //cout<<"This NEW scan "<< scanID <<" doesn't exist"<<endl;
00853     this_scan =gDirectory ->mkdir(scanID.c_str());
00854   }
00855   this_scan->cd();   
00856 
00857   /* Making ROD   */ 
00858   TDirectory* this_ROD = (TDirectory*) this_scan->Get(RODID.c_str());
00859   if (!this_ROD) {
00860     //cout<<"This NEW ROD  doesn't exist"<<endl;
00861     this_ROD = this_scan->mkdir(RODID.c_str());
00862   }
00863   this_ROD->cd();
00864  
00865 
00866   //...Opening TxtComment file 
00867   ifstream in;
00868   in.open(names->getTxtCommentRODName().c_str());
00869 
00870   int commentN;
00871     int sz = 1000; // Buffer size;
00872     char buf[sz];
00873     
00874     //char TxtComment[40];
00875     int nlines = 0;
00876     while (1) {
00877       in >> commentN;
00878       in.get(buf, sz);
00879       if (!in.good()) break;
00880       //cout<< " CommentN = "<< commentN << " String = "<< buf <<endl;
00881       TObjString Comment(buf);
00882       //sprintf(TxtComment,"TxtComment_%i",commentN);
00883       TObject* pers_TxtCommentN = gDirectory->FindObjectAny(names->getRODTxtComment(commentN).c_str());
00884       if (!pers_TxtCommentN) {
00885     //cout<<" TxtComment Never Persisted...persisting" <<endl;
00886     Comment.Write(names->getRODTxtComment(commentN).c_str());
00887       }
00888       nlines++;   
00889     }
00890     //printf(" found %d points \n",nlines);
00891     
00892     
00893     in.close();
00894     file->Close();
00895 
00896 }
00897 
00898 
00899 
00900 
00901 
00902 
00903 
00904 
00905 
00906 
00907 
00908 void ArchScanResult::Save() {
00909 
00910 
00911   //TO DO : Save time and date of first and last saving
00912  
00913   
00914   string ScanPointsID = names->getScanPointsID() ;
00915   string vpointsID = names->getvpointsID();
00916   string vNEventsID = names->getvNEventsID();
00917   string vNErrorEventsID = names->getvNErrorEventsID(); 
00918   string filename = names->getfilename();
00919   //string objName = ;  //To be deleted
00920   string variable = names->getVariable(); 
00921   string moduleID = names->getModuleID(); 
00922   string testType  = names->getTestType(); 
00923   string runID = names->getRunID();
00924   string scanID = names->getScanID();
00925   string RODID = names->getRODID();
00926   string DCSID = names->getDCSID();
00927   string ModuleConfigID = names->getModuleConfigID();
00928 
00929 
00930 
00931   /* OPENING TEST FILE  */
00932   cout << "Opening file..."<<endl; 
00933  
00934 
00935   /*
00936   TObject *storage_file = gROOT->FindObjectAny(filename) ;
00937   if (!storage_file) { 
00938     cout << "no such file " << endl;
00939     //TFile *storage_file = new TFile(filename,"update");
00940   }
00941   else {
00942     cout << "The file already exists " << endl;
00943     TFile *storage_file = new TFile(filename,"update");
00944   }
00945   */
00946 
00947   TFile *storage_file = new TFile(filename.c_str(),"update");
00948   //storage_file->ls();
00949   cout << "The file .root succesfully open"<<endl; 
00950 
00951   
00952 
00953 
00954   /* CREATING DIRECTORIES and SAVING DATA  */
00955   
00956     
00957     /* Making RunNumber   */
00958     //cout<<"I am making RunNumber Dir"<<endl;
00959     //storage_file->GetListOfKeys()->Print();
00960     TDirectory *this_run = (TDirectory*) gDirectory->Get(runID.c_str());
00961     //cout<<"The RUN is "<< runID <<endl;
00962     
00963     if (!this_run) {
00964       //cout<<"This NEW run "<< runID <<" doesn't exist"<<endl;
00965       this_run = storage_file->mkdir(runID.c_str());
00966       //cout<<"New RunNumber Dir made "<<endl;
00967     }
00968     //storage_file->GetListOfKeys()->Print();
00969     this_run->cd();  //make this_run the current directory
00970     
00971    
00972     /* Saving RunNumber as a TVector: it is saved only once, just the first time   */
00973     TObject* pers_runnumber = gDirectory->FindObjectAny(runID.c_str()); 
00974     if (!pers_runnumber) {
00975       double frunNumber = runNumber;
00976       TVector run(1,1,frunNumber, "END");
00977       run.Write(runID.c_str());
00978     }
00979     
00980     
00981     /* Making moduleNumber   */
00982     
00983     TDirectory* this_module = (TDirectory*) gDirectory->Get(moduleID.c_str()); //Can be made using FindAnyObject
00984     //cout<<"The MODULE is "<< moduleID <<endl;
00985     if (!this_module) {
00986       //cout<<"This NEW module "<< moduleID <<" doesn't exist"<<endl;
00987       this_module =gDirectory ->mkdir(moduleID.c_str());
00988     }
00989     
00990 
00991 
00992     
00993     /* Making TestType   */
00994     //cout<<"I am making TestType Dir "<<endl;
00995     this_module->cd();  //make this_module the current directory 
00996     TDirectory* this_testType = (TDirectory*) gDirectory->Get(testType.c_str());
00997     //cout<<"The test Type is "<< testType <<endl;
00998     
00999     if (!this_testType) {
01000       //cout<<"This NEW test "<< testType <<" doesn't exist"<<endl;
01001       this_testType = gDirectory->mkdir(testType.c_str());
01002     }
01003 
01004     
01005     /* Making ScanType   */
01006     //cout<<"I am making scanType Dir "<<endl;
01007     this_testType->cd();  //make this_testType the current directory 
01008     TDirectory* this_variable = (TDirectory*) gDirectory->Get(variable.c_str());
01009     //cout<<"The Scan Type is "<< variable <<endl;
01010     
01011     
01012     if (!this_variable) {
01013       //cout<<"This NEW test "<< variable <<" doesn't exist"<<endl;
01014       this_variable = gDirectory->mkdir(variable.c_str());
01015     }
01016      
01017 
01018     
01019 
01020     /* Making variable   */
01021     //cout<<"I am making variable Dir "<<endl;
01022     this_variable->cd();  //make this_test the current directory
01023     TDirectory* this_scan = (TDirectory*) gDirectory->Get(scanID.c_str());
01024     //cout<<"The SCAN is "<< scanID <<endl;
01025     
01026     if (!this_scan) {
01027       //cout<<"This NEW scan "<< scanID <<" doesn't exist"<<endl;
01028       this_scan =gDirectory ->mkdir(scanID.c_str());
01029     }
01030      
01031 
01032     /* Saving ScanNumber as a TVector: it is saved only once, just the first time   */
01033     this_scan->cd();
01034     TObject* pers_scannumber = gDirectory->FindObjectAny(scanID.c_str());
01035     if (!pers_scannumber) {
01036       double fscanNumber = scanNumber;
01037       TVector vscan(1,1,fscanNumber,"END");
01038       vscan.Write(scanID.c_str());
01039     }
01040 
01041 
01042     //Saving Module Configuration
01043     TObject* pers_ModuleConfig = gDirectory->FindObjectAny(ModuleConfigID.c_str());
01044     if (!pers_ModuleConfig) {
01045       cout<<"%%%%%%% Just about to save ABCDModule %%%%%%%"<<endl;
01046       TObjString ModuleConfigTObjString = getModuleConfigTObjString();
01047       //TString tmp_string = ModuleConfigTObjString.String();
01048       //cout<< "Module Configuration :" << endl << tmp_string.Data()<<endl;
01049       ModuleConfigTObjString.Write(ModuleConfigID.c_str()); 
01050       cout<<"%%%%%%% ABCDModule saved %%%%%%%"<<endl;
01051     }
01052     
01053 
01054     /* Threshold saved as a TVector: it is saved only once, just the first time */ 
01055 /*    TObject* pers_Threshold = gDirectory->FindObjectAny(thresholdID.c_str());  
01056     if (!pers_Threshold) {
01057       cout << "The Threshold never saved before...saving now"<<endl;
01058       double fthreshold = threshold;
01059       TVectorD vthreshold(1,1,fthreshold,"END");
01060       vthreshold.Write(thresholdID.c_str());
01061     }
01062 */
01063 
01064 
01065     /* Saving ScanPoints as a TGraph: it is saved only once, just the first time  */
01066     //cout << "I am Saving ScanPoints as a TGraph" << endl;
01067     //TObject* pers_gscanpoints = gDirectory->FindObjectAny(ScanPointsID.c_str()); 
01068     //if (!pers_gscanpoints) {
01069       //cout << "The ScanPoints never saved before...saving now"<<endl;
01070       gpoints->Write(ScanPointsID.c_str());
01071     //}
01072     
01073 
01074     
01076     //cout << "I am Saving ScanPoints as  TVector's" << endl;
01077     //TObject* pers_vscanpoints = gDirectory->FindObjectAny(vpointsID.c_str()); 
01078     //if (!pers_vscanpoints) {
01079       //cout << "The ScanPoints never saved before...saving now"<<endl;
01080       vpoints->Write(vpointsID.c_str());  
01081     //}
01082     //TObject* pers_vNEvents = gDirectory->FindObjectAny(vNEventsID.c_str()); 
01083     //if (!pers_vNEvents) {
01084       //cout<< "I am here " << endl;
01085       vNEvents->Write(vNEventsID.c_str());  
01086     //}
01087      //TObject* pers_vNErrorEvents = gDirectory->FindObjectAny(vNErrorEventsID.c_str()); 
01088     //if (!pers_vNErrorEvents) {
01089       vNErrorEvents->Write(vNErrorEventsID.c_str());  
01090     //}
01091       
01092 
01093 
01094     /* Making DCS   */
01095     //cout<<"I am making DCS Dir"<<endl;
01096       /*
01097     this_scan->cd();  //make this_scan the current directory
01098     TDirectory*  this_DCS = (TDirectory*) this_scan->Get(DCSID.c_str()); 
01099     //NB: DCS & ROD are at the same level. 
01100     if (!this_DCS) {
01101       //cout<<"This NEW DCS  doesn't exist"<<endl;
01102       this_DCS = this_scan->mkdir(DCSID.c_str());
01103     }
01104     
01105       */
01106    
01107 
01108     /* Saving DCS data members  */
01109       /*
01110     //cout << "I am Saving DCS RawScanResult Data Members" << endl;
01111     this_DCS->cd();  
01112       */
01113 
01114 
01115     /* Making ROD   */ 
01116     //cout<<"I am making ROD Dir"<<endl;
01117     this_scan->cd();  //make this_scan the current directory
01118     TDirectory* this_ROD = (TDirectory*) this_scan->Get(RODID.c_str());
01119     if (!this_ROD) {
01120       //cout<<"This NEW ROD  doesn't exist"<<endl;
01121       this_ROD = this_scan->mkdir(RODID.c_str());
01122     }
01123     
01124  
01125     
01126     
01127 
01128     /* CLOSING FILE  */
01129     cout << "I am Closing File " << endl;
01130     storage_file->Close();
01131     delete storage_file;
01132     cout << "File closed " << endl;
01133 
01134 
01135 
01136 
01137 
01138 }

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