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 
00028 
00029 
00030 
00031 
00032 ArchScanResult::ArchScanResult()  {
00033 
00034   
00035   
00036 
00037   
00038   Archheader = NULL;
00039   ArchmoduleConfig = NULL;
00040   Archpoints = NULL;
00041   Archvariable = NULL;
00042   
00043 
00044   runNumber = 0;
00045   scanNumber = 0;
00046   
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   
00063   
00064   
00065 
00066   
00067     Archheader = &scan->getHeader();          
00068     ArchmoduleConfig = &scan->getConfiguration();
00069     Archpoints = &scan->getPoints();
00070     Archvariable = &Archheader->getVariable();
00071     
00072 
00073     
00074     const ABCDModule ABCDModuleConfig = ArchmoduleConfig->getABCDModule();
00075     
00076     
00077 
00078 
00079 
00080   
00081 
00082     runNumber = Archheader->getRunNumber() ;
00083     scanNumber = Archheader->getScanNumber() ;
00084     moduleName = Archheader->getModuleName();
00085 
00086 
00087 
00088     
00089     
00090 
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     
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 
00124 
00125 ArchScanResult::~ArchScanResult()  {
00126   
00127   
00128   
00129   
00130   
00131 
00132   
00133 }
00134 
00135 
00136 
00137 
00138 
00139 TObjString ArchScanResult::getModuleConfigTObjString() {
00140   
00141 
00142 
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   
00165 
00166 
00167 
00168     Archheader = &scan->getHeader();          
00169     ArchmoduleConfig = &scan->getConfiguration();
00170     Archpoints = &scan->getPoints();
00171     Archvariable = &Archheader->getVariable();
00172 
00173 
00174   
00175 
00176     runNumber = Archheader->getRunNumber() ;
00177     scanNumber = Archheader->getScanNumber() ;
00178 
00179 
00180     
00181     
00182 
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   
00218 }
00219 
00220 
00221 const vector <string>& ArchScanResult::getAllSavedScansList() {
00222 
00223  
00224    
00225 
00226  
00227   
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   
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   
00245   TList* runsList = gDirectory->GetListOfKeys();
00246   TListIter itruns(runsList);
00247   while (TObject *runsobj = itruns.Next()) { 
00248     
00249     
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 ) {    
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   
00342 
00343   
00344   string index = names->getIndexFileName(); 
00345   ofstream index_file;
00346   index_file.open(index.c_str(),ios::app);  
00347   
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   
00356     index_file << indexScanName <<endl;
00357     cout << "Scan appended to Index"<<endl;    
00358   
00359   
00360   
00361   
00362   index_file.close(); 
00363   
00364 }
00365 
00366 
00367 void ArchScanResult::SaveFileComment() {
00368 
00369   
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   
00381   ifstream in;
00382   in.open(names->getTxtCommentAllFilesName().c_str());
00383 
00384   int commentN;
00385     int sz = 1000; 
00386     char buf[sz];
00387     
00388     
00389     int nlines = 0;
00390     while (1) {
00391       in >> commentN;
00392       in.get(buf, sz);
00393       if (!in.good()) break;
00394       
00395       TObjString FileComment(buf);
00396       
00397       TObject* pers_FileTxtCommentN = gDirectory->FindObjectAny(names->getAllFilesTxtComment(commentN).c_str());
00398       if (!pers_FileTxtCommentN) {
00399     
00400     FileComment.Write(names->getAllFilesTxtComment(commentN).c_str());
00401       }
00402       nlines++;   
00403     }
00404     
00405     
00406     
00407     in.close();
00408     file->Close();
00409 
00410 }
00411 
00412 
00413 
00414 void ArchScanResult::SaveRunComment() {
00415 
00416   
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   
00426   TDirectory *this_run = (TDirectory*) gDirectory->Get(runID.c_str()); 
00427   if (!this_run) {
00428     
00429     this_run = file->mkdir(runID.c_str());
00430     
00431   }
00432   this_run->cd();  
00433 
00434 
00435   
00436   ifstream in;
00437   in.open(names->getTxtCommentRunName().c_str());
00438 
00439   int commentN;
00440     int sz = 1000; 
00441     char buf[sz];
00442     
00443     
00444     int nlines = 0;
00445     while (1) {
00446       in >> commentN;
00447       in.get(buf, sz);
00448       if (!in.good()) break;
00449       
00450       TObjString RunComment(buf);
00451       
00452       TObject* pers_RunTxtCommentN = gDirectory->FindObjectAny(names->getRunTxtComment(commentN).c_str());
00453       if (!pers_RunTxtCommentN) {
00454     
00455     RunComment.Write(names->getRunTxtComment(commentN).c_str());
00456       }
00457       nlines++;   
00458     }
00459     
00460     
00461     
00462     in.close();
00463     file->Close();
00464 
00465 }
00466 
00467 
00468 void ArchScanResult::SaveModuleComment() {
00469 
00470   
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   
00482   TDirectory *this_run = (TDirectory*) gDirectory->Get(runID.c_str()); 
00483   if (!this_run) {
00484     
00485     this_run = file->mkdir(runID.c_str());
00486     
00487   }
00488   this_run->cd();  
00489 
00490   
00491   
00492   TDirectory* this_module = (TDirectory*) gDirectory->Get(moduleID.c_str()); 
00493   if (!this_module) {
00494     
00495     this_module =gDirectory ->mkdir(moduleID.c_str());
00496   }
00497   this_module->cd();
00498 
00499   
00500   
00501   
00502   ifstream in;
00503   in.open(names->getTxtCommentModuleName().c_str());
00504   
00505 
00506   int commentN;
00507     int sz = 1000; 
00508     char buf[sz];
00509     
00510     
00511     
00512     int nlines = 0;
00513     while (1) {
00514       in >> commentN;
00515       in.get(buf, sz);
00516       if (!in.good()) break;
00517       
00518       TObjString Comment(buf);
00519       
00520       TObject* pers_ModuleTxtCommentN = gDirectory->FindObjectAny(names->getModuleTxtComment(commentN).c_str());
00521       if (!pers_ModuleTxtCommentN) {
00522     
00523       Comment.Write(names->getModuleTxtComment(commentN).c_str());
00524       }
00525       nlines++;   
00526     }
00527     
00528     
00529 
00530     in.close();
00531     file->Close();
00532     
00533 
00534 }
00535 
00536 
00537 
00538 void ArchScanResult::SaveTestComment() {
00539 
00540   
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   
00552   TDirectory *this_run = (TDirectory*) gDirectory->Get(runID.c_str()); 
00553   if (!this_run) {
00554     
00555     this_run = file->mkdir(runID.c_str());
00556     
00557   }
00558   this_run->cd();  
00559 
00560   
00561   
00562   TDirectory* this_module = (TDirectory*) gDirectory->Get(moduleID.c_str()); 
00563   if (!this_module) {
00564     
00565     this_module =gDirectory ->mkdir(moduleID.c_str());
00566   }
00567   this_module->cd();
00568 
00569 
00570   
00571   TDirectory* this_testType = (TDirectory*) gDirectory->Get(testType.c_str());
00572   if (!this_testType) {
00573     
00574     this_testType = gDirectory->mkdir(testType.c_str());
00575   }
00576   this_testType->cd();
00577 
00578 
00579 
00580   
00581   ifstream in;
00582   in.open(names->getTxtCommentTestName().c_str());
00583 
00584   int commentN;
00585     int sz = 1000; 
00586     char buf[sz];
00587     
00588     
00589     int nlines = 0;
00590     while (1) {
00591       in >> commentN;
00592       in.get(buf, sz);
00593       if (!in.good()) break;
00594       
00595       TObjString Comment(buf);
00596       
00597       TObject* pers_TxtCommentN = gDirectory->FindObjectAny(names->getTestTxtComment(commentN).c_str());
00598       if (!pers_TxtCommentN) {
00599     
00600     Comment.Write(names->getTestTxtComment(commentN).c_str());
00601       }
00602       nlines++;   
00603     }
00604     
00605     
00606     
00607     in.close();
00608     file->Close();
00609 
00610 }
00611 
00612 
00613 void ArchScanResult::SaveVariableComment() {
00614 
00615   
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   
00629   TDirectory *this_run = (TDirectory*) gDirectory->Get(runID.c_str()); 
00630   if (!this_run) {
00631     
00632     this_run = file->mkdir(runID.c_str());
00633     
00634   }
00635   this_run->cd();  
00636 
00637   
00638   
00639   TDirectory* this_module = (TDirectory*) gDirectory->Get(moduleID.c_str()); 
00640   if (!this_module) {
00641     
00642     this_module =gDirectory ->mkdir(moduleID.c_str());
00643   }
00644   this_module->cd();
00645 
00646 
00647   
00648   TDirectory* this_testType = (TDirectory*) gDirectory->Get(testType.c_str());
00649   if (!this_testType) {
00650     
00651     this_testType = gDirectory->mkdir(testType.c_str());
00652   }
00653   this_testType->cd();
00654 
00655   
00656   
00657   TDirectory* this_variable = (TDirectory*) gDirectory->Get(variable.c_str());
00658   
00659   if (!this_variable) {
00660     
00661     this_variable = gDirectory->mkdir(variable.c_str());
00662   }
00663   this_variable->cd();
00664 
00665 
00666 
00667   
00668   ifstream in;
00669   in.open(names->getTxtCommentVariableName().c_str());
00670 
00671   int commentN;
00672     int sz = 1000; 
00673     char buf[sz];
00674     
00675     
00676     int nlines = 0;
00677     while (1) {
00678       in >> commentN;
00679       in.get(buf, sz);
00680       if (!in.good()) break;
00681       
00682       TObjString Comment(buf);
00683       
00684       TObject* pers_TxtCommentN = gDirectory->FindObjectAny(names->getVariableTxtComment(commentN).c_str());
00685       if (!pers_TxtCommentN) {
00686     
00687     Comment.Write(names->getVariableTxtComment(commentN).c_str());
00688       }
00689       nlines++;   
00690     }
00691     
00692     
00693     
00694     in.close();
00695     file->Close();
00696 
00697 }
00698 
00699 
00700 
00701 void ArchScanResult::SaveScanNumberComment() {
00702 
00703   
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   
00718   TDirectory *this_run = (TDirectory*) gDirectory->Get(runID.c_str()); 
00719   if (!this_run) {
00720     
00721     this_run = file->mkdir(runID.c_str());
00722     
00723   }
00724   this_run->cd();  
00725 
00726   
00727   
00728   TDirectory* this_module = (TDirectory*) gDirectory->Get(moduleID.c_str()); 
00729   if (!this_module) {
00730     
00731     this_module =gDirectory ->mkdir(moduleID.c_str());
00732   }
00733   this_module->cd();
00734 
00735 
00736   
00737   TDirectory* this_testType = (TDirectory*) gDirectory->Get(testType.c_str());
00738   if (!this_testType) {
00739     
00740     this_testType = gDirectory->mkdir(testType.c_str());
00741   }
00742   this_testType->cd();
00743 
00744   
00745   
00746   TDirectory* this_variable = (TDirectory*) gDirectory->Get(variable.c_str());
00747   if (!this_variable) {
00748     
00749     this_variable = gDirectory->mkdir(variable.c_str());
00750   }
00751   this_variable->cd();
00752 
00753   
00754   TDirectory* this_scan = (TDirectory*) gDirectory->Get(scanID.c_str());
00755   if (!this_scan) {
00756     
00757     this_scan =gDirectory ->mkdir(scanID.c_str());
00758   }
00759   this_scan->cd();   
00760 
00761 
00762 
00763   
00764   ifstream in;
00765   in.open(names->getTxtCommentScanNumberName().c_str());
00766 
00767   int commentN;
00768     int sz = 1000; 
00769     char buf[sz];
00770     
00771     
00772     int nlines = 0;
00773     while (1) {
00774       in >> commentN;
00775       in.get(buf, sz);
00776       if (!in.good()) break;
00777       
00778       TObjString Comment(buf);
00779       
00780       TObject* pers_TxtCommentN = gDirectory->FindObjectAny(names->getScanNumberTxtComment(commentN).c_str());
00781       if (!pers_TxtCommentN) {
00782     
00783     Comment.Write(names->getScanNumberTxtComment(commentN).c_str());
00784       }
00785       nlines++;   
00786     }
00787     
00788     
00789     
00790     in.close();
00791     file->Close();
00792 
00793 }
00794 
00795 
00796 void ArchScanResult::SaveRODComment() {
00797 
00798   
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   
00814   TDirectory *this_run = (TDirectory*) gDirectory->Get(runID.c_str()); 
00815   if (!this_run) {
00816     
00817     this_run = file->mkdir(runID.c_str());
00818     
00819   }
00820   this_run->cd();  
00821 
00822   
00823   
00824   TDirectory* this_module = (TDirectory*) gDirectory->Get(moduleID.c_str()); 
00825   if (!this_module) {
00826     
00827     this_module =gDirectory ->mkdir(moduleID.c_str());
00828   }
00829   this_module->cd();
00830 
00831 
00832   
00833   TDirectory* this_testType = (TDirectory*) gDirectory->Get(testType.c_str());
00834   if (!this_testType) {
00835     
00836     this_testType = gDirectory->mkdir(testType.c_str());
00837   }
00838   this_testType->cd();
00839 
00840   
00841   
00842   TDirectory* this_variable = (TDirectory*) gDirectory->Get(variable.c_str());
00843   if (!this_variable) {
00844     
00845     this_variable = gDirectory->mkdir(variable.c_str());
00846   }
00847   this_variable->cd();
00848 
00849   
00850   TDirectory* this_scan = (TDirectory*) gDirectory->Get(scanID.c_str());
00851   if (!this_scan) {
00852     
00853     this_scan =gDirectory ->mkdir(scanID.c_str());
00854   }
00855   this_scan->cd();   
00856 
00857    
00858   TDirectory* this_ROD = (TDirectory*) this_scan->Get(RODID.c_str());
00859   if (!this_ROD) {
00860     
00861     this_ROD = this_scan->mkdir(RODID.c_str());
00862   }
00863   this_ROD->cd();
00864  
00865 
00866   
00867   ifstream in;
00868   in.open(names->getTxtCommentRODName().c_str());
00869 
00870   int commentN;
00871     int sz = 1000; 
00872     char buf[sz];
00873     
00874     
00875     int nlines = 0;
00876     while (1) {
00877       in >> commentN;
00878       in.get(buf, sz);
00879       if (!in.good()) break;
00880       
00881       TObjString Comment(buf);
00882       
00883       TObject* pers_TxtCommentN = gDirectory->FindObjectAny(names->getRODTxtComment(commentN).c_str());
00884       if (!pers_TxtCommentN) {
00885     
00886     Comment.Write(names->getRODTxtComment(commentN).c_str());
00887       }
00888       nlines++;   
00889     }
00890     
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   
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   
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   
00932   cout << "Opening file..."<<endl; 
00933  
00934 
00935   
00936 
00937 
00938 
00939 
00940 
00941 
00942 
00943 
00944 
00945 
00946 
00947   TFile *storage_file = new TFile(filename.c_str(),"update");
00948   
00949   cout << "The file .root succesfully open"<<endl; 
00950 
00951   
00952 
00953 
00954   
00955   
00956     
00957     
00958     
00959     
00960     TDirectory *this_run = (TDirectory*) gDirectory->Get(runID.c_str());
00961     
00962     
00963     if (!this_run) {
00964       
00965       this_run = storage_file->mkdir(runID.c_str());
00966       
00967     }
00968     
00969     this_run->cd();  
00970     
00971    
00972     
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     
00982     
00983     TDirectory* this_module = (TDirectory*) gDirectory->Get(moduleID.c_str()); 
00984     
00985     if (!this_module) {
00986       
00987       this_module =gDirectory ->mkdir(moduleID.c_str());
00988     }
00989     
00990 
00991 
00992     
00993     
00994     
00995     this_module->cd();  
00996     TDirectory* this_testType = (TDirectory*) gDirectory->Get(testType.c_str());
00997     
00998     
00999     if (!this_testType) {
01000       
01001       this_testType = gDirectory->mkdir(testType.c_str());
01002     }
01003 
01004     
01005     
01006     
01007     this_testType->cd();  
01008     TDirectory* this_variable = (TDirectory*) gDirectory->Get(variable.c_str());
01009     
01010     
01011     
01012     if (!this_variable) {
01013       
01014       this_variable = gDirectory->mkdir(variable.c_str());
01015     }
01016      
01017 
01018     
01019 
01020     
01021     
01022     this_variable->cd();  
01023     TDirectory* this_scan = (TDirectory*) gDirectory->Get(scanID.c_str());
01024     
01025     
01026     if (!this_scan) {
01027       
01028       this_scan =gDirectory ->mkdir(scanID.c_str());
01029     }
01030      
01031 
01032     
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     
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       
01048       
01049       ModuleConfigTObjString.Write(ModuleConfigID.c_str()); 
01050       cout<<"%%%%%%% ABCDModule saved %%%%%%%"<<endl;
01051     }
01052     
01053 
01054      
01055 
01056 
01057 
01058 
01059 
01060 
01061 
01062 
01063 
01064 
01065     
01066     
01067     
01068     
01069       
01070       gpoints->Write(ScanPointsID.c_str());
01071     
01072     
01073 
01074     
01076     
01077     
01078     
01079       
01080       vpoints->Write(vpointsID.c_str());  
01081     
01082     
01083     
01084       
01085       vNEvents->Write(vNEventsID.c_str());  
01086     
01087      
01088     
01089       vNErrorEvents->Write(vNErrorEventsID.c_str());  
01090     
01091       
01092 
01093 
01094     
01095     
01096       
01097 
01098 
01099 
01100 
01101 
01102 
01103 
01104 
01105 
01106    
01107 
01108     
01109       
01110 
01111 
01112 
01113 
01114 
01115      
01116     
01117     this_scan->cd();  
01118     TDirectory* this_ROD = (TDirectory*) this_scan->Get(RODID.c_str());
01119     if (!this_ROD) {
01120       
01121       this_ROD = this_scan->mkdir(RODID.c_str());
01122     }
01123     
01124  
01125     
01126     
01127 
01128     
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 }