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(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 ModuleConfigurationIOHelper* ModuleConfigIOHelper;
00075 const ABCDModule ABCDModuleConfig = ModuleConfigIOHelper->getABCDModule(*ArchmoduleConfig);
00076
00077
00078
00079
00080
00081
00082
00083 runNumber = Archheader->getRunNumber() ;
00084 scanNumber = Archheader->getScanNumber() ;
00085 moduleName = Archheader->getModuleName();
00086
00087
00088
00089
00090
00091
00092
00093
00094 names = new ArchScanTxtNames(runNumber, Archheader->getModuleName(), scanNumber, *Archvariable );
00095 objName = scan.getUniqueID();
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119 float x[Archpoints->getNPoints()], y[Archpoints->getNPoints()],err[Archpoints->getNPoints()] ;
00120 for(unsigned int i=0;i<Archpoints->getNPoints();++i) {
00121 x[i] = Archpoints->getPoint(i);
00122 y[i] = Archpoints->getNEvents(i);
00123 err[i] = Archpoints->getNErrorEvents(i);
00124 }
00125 gpoints = new TGraph(Archpoints->getNPoints(),x,y);
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135 vpoints = new TVector(0, Archpoints->getNPoints(),x);
00136 vNEvents = new TVector(0, Archpoints->getNPoints(),y);
00137 vNErrorEvents = new TVector(0, Archpoints->getNPoints(),err);
00138
00139
00140
00141
00142
00143 }
00144
00145
00146
00147
00148
00149
00150
00151 ArchScanResult::~ArchScanResult() {
00152
00153
00154
00155
00156
00157
00158
00159 }
00160
00161
00162
00163
00164
00165 TObjString ArchScanResult::getModuleConfigTObjString() {
00166
00167
00168
00169
00170 ConfigIPC config;
00171 string tmp_ModuleConfig = config.getModuleConfigurationString(moduleName, ABCDModuleConfig);
00172 const char* tmp_char = tmp_ModuleConfig.c_str();
00173 TObjString ABCDModuleTObjString(tmp_char);
00174
00175
00176
00177 return ABCDModuleTObjString;
00178
00179
00180
00181 }
00182
00183
00184
00185
00186
00187
00188 void ArchScanResult::SetScan(ScanResult & scan) {
00189
00190
00191
00192
00193
00194 Archheader = &scan.getHeader();
00195 ArchmoduleConfig = &scan.getConfiguration();
00196 Archpoints = &scan.getPoints();
00197 Archvariable = &Archheader->getVariable();
00198
00199
00200
00201
00202 runNumber = Archheader->getRunNumber() ;
00203 scanNumber = Archheader->getScanNumber() ;
00204
00205
00206
00207
00208
00209
00210
00211 names = new ArchScanTxtNames(runNumber, Archheader->getModuleName(), scanNumber, *Archvariable );
00212 objName = scan.getUniqueID();
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236 float x[Archpoints->getNPoints()], y[Archpoints->getNPoints()],err[Archpoints->getNPoints()];
00237 for(unsigned int i=0;i<Archpoints->getNPoints();++i) {
00238 x[i] = Archpoints->getPoint(i);
00239 y[i] = Archpoints->getNEvents(i);
00240 err[i] = Archpoints->getNErrorEvents(i);
00241 }
00242 gpoints = new TGraph(Archpoints->getNPoints(),x,y);
00243
00244
00245 vpoints = new TVector(0, Archpoints->getNPoints(),x);
00246 vNEvents = new TVector(0, Archpoints->getNPoints(),y);
00247 vNErrorEvents = new TVector(0, Archpoints->getNPoints(),err);
00248
00249
00250
00251
00252
00253
00254 }
00255
00256
00257
00258
00259
00260 void ArchScanResult::SetTestType(string tType) {
00261
00262 names->setTestType( tType );
00263
00264 }
00265
00266
00267 const vector <string>& ArchScanResult::getAllSavedScansList() {
00268
00269
00270
00271
00272
00273
00274 string filename = names->getfilename();
00275 TFile *inspect_file = new TFile(filename.c_str(),"read");
00276 if (inspect_file->IsZombie() == true) {
00277 cout << "Problem in opening file"<<endl;
00278 return SavedScansList;
00279
00280 }
00281
00282
00283 TDirectory *gModuleDir = new TDirectory();
00284 TDirectory *gRODDir = new TDirectory();
00285 TDirectory *gtestTypeDir = new TDirectory();
00286 TDirectory *gvariableDir = new TDirectory();
00287 TDirectory *gscanDir = new TDirectory();
00288
00289
00290
00291 TList* runsList = gDirectory->GetListOfKeys();
00292 TListIter itruns(runsList);
00293 while (TObject *runsobj = itruns.Next()) {
00294
00295
00296 string runID = runsobj->GetName();
00297 if (runsobj->GetTitle() == runID ) {
00298 if (gDirectory->cd(runID.c_str())==1) {
00299
00300 gModuleDir = gDirectory;
00301 TList* modulesList = gDirectory->GetListOfKeys();
00302 TListIter itmodules(modulesList);
00303 while (TObject *modulesobj = itmodules.Next()) {
00304 string moduleID = modulesobj->GetName();
00305 string modulesobjID = modulesobj->GetTitle();
00307 if (modulesobj->GetTitle() == moduleID ) {
00308 gModuleDir->cd();
00309 if (gDirectory->cd(moduleID.c_str())== 1) {
00310
00311 gtestTypeDir = gDirectory;
00312 TList* testTypeList = gDirectory->GetListOfKeys();
00313 TListIter ittestType(testTypeList);
00314 while (TObject *testTypeobj = ittestType.Next()) {
00315 string testTypeID = testTypeobj->GetName();
00316 if (testTypeobj->GetTitle() == testTypeID ) {
00317 gtestTypeDir->cd();
00318 if (gDirectory->cd(testTypeID.c_str())==1 ) {
00319
00320 gvariableDir = gDirectory;
00321 TList* variableList = gDirectory->GetListOfKeys();
00322 TListIter itvariable(variableList);
00323 while (TObject *variableobj = itvariable.Next()) {
00324 string variableID = variableobj->GetName();
00325 if (variableobj->GetTitle() == variableID ) {
00326 gvariableDir->cd();
00327 if (gDirectory->cd(variableID.c_str())==1 ) {
00328 gDirectory->Print();
00329
00330 gscanDir = gDirectory;
00331 TList* scanList = gDirectory->GetListOfKeys();
00332 TListIter itscan(scanList);
00333 while (TObject *scanobj = itscan.Next()) {
00334 string scanID = scanobj->GetName();
00335 if (scanobj->GetTitle() == scanID ) {
00336 gscanDir->cd();
00337 if (gDirectory->cd(scanID.c_str())==1 ) {
00338
00339 if (gDirectory->cd(names->getDCSID().c_str())==1 ) {
00340
00341 gDirectory->cd("../");
00342 if (gDirectory->cd(names->getRODID().c_str())==1 ) {
00343
00344
00345 gRODDir = gDirectory;
00346 if (gDirectory->cd(names->getRawID().c_str())==1 ) {
00347 string tmp_SavedScan = gDirectory->GetPath();
00348 SavedScansList.push_back(tmp_SavedScan);
00349
00350 }
00351
00352 gRODDir->cd();
00353 if (gDirectory->cd(names->getFitID().c_str())==1 ) {
00354 string tmp_SavedScan = gDirectory->GetPath();
00355 SavedScansList.push_back(tmp_SavedScan);
00356
00357 }
00358 }
00359 }
00360 }
00361 }
00362 }
00363 }
00364 }
00365 }
00366 }
00367 }
00368 }
00369 }
00370 }
00371 }
00372 }
00373 }
00374 }
00375
00376
00377
00378 return SavedScansList;
00379
00380 }
00381
00382
00383
00384
00385 void ArchScanResult::AddScanToIndex() {
00386
00387
00388
00389
00390 string index = names->getIndexFileName();
00391 ofstream index_file;
00392 index_file.open(index.c_str(),ios::app);
00393
00394
00395 string indexScanName = names->getRunID() + ".";
00396 indexScanName = indexScanName + names->getModuleID();
00397 indexScanName = indexScanName + ".";
00398 indexScanName = indexScanName + names->getTestType() + ".";
00399 indexScanName = indexScanName + names->getScanID();
00400 cout << indexScanName <<endl;
00401
00402 index_file << indexScanName <<endl;
00403 cout << "Scan appended to Index"<<endl;
00404
00405
00406
00407
00408 index_file.close();
00409
00410 }
00411
00412
00413 void ArchScanResult::SaveFileComment() {
00414
00415
00416
00417 string filename = names->getfilename();
00418
00419 TFile *file = new TFile(filename.c_str(),"update");
00420 if (file->IsZombie() == true) {
00421 cout << "The ScanResult has NOT been saved in any file"<<endl;
00422 return ;
00423 }
00424
00425
00426
00427 ifstream in;
00428 in.open(names->getTxtCommentAllFilesName().c_str());
00429
00430 int commentN;
00431 int sz = 1000;
00432 char buf[sz];
00433
00434
00435 int nlines = 0;
00436 while (1) {
00437 in >> commentN;
00438 in.get(buf, sz);
00439 if (!in.good()) break;
00440
00441 TObjString FileComment(buf);
00442
00443 TObject* pers_FileTxtCommentN = gDirectory->FindObjectAny(names->getAllFilesTxtComment(commentN).c_str());
00444 if (!pers_FileTxtCommentN) {
00445
00446 FileComment.Write(names->getAllFilesTxtComment(commentN).c_str());
00447 }
00448 nlines++;
00449 }
00450
00451
00452
00453 in.close();
00454 file->Close();
00455
00456 }
00457
00458
00459
00460 void ArchScanResult::SaveRunComment() {
00461
00462
00463
00464 string filename = names->getfilename();
00465 string runID = names->getRunID();
00466 TFile *file = new TFile(filename.c_str(),"update");
00467 if (file->IsZombie() == true) {
00468 cout << "The ScanResult has NOT been saved in any file"<<endl;
00469 return ;
00470 }
00471
00472 TDirectory *this_run = (TDirectory*) gDirectory->Get(runID.c_str());
00473 if (!this_run) {
00474
00475 this_run = file->mkdir(runID.c_str());
00476
00477 }
00478 this_run->cd();
00479
00480
00481
00482 ifstream in;
00483 in.open(names->getTxtCommentRunName().c_str());
00484
00485 int commentN;
00486 int sz = 1000;
00487 char buf[sz];
00488
00489
00490 int nlines = 0;
00491 while (1) {
00492 in >> commentN;
00493 in.get(buf, sz);
00494 if (!in.good()) break;
00495
00496 TObjString RunComment(buf);
00497
00498 TObject* pers_RunTxtCommentN = gDirectory->FindObjectAny(names->getRunTxtComment(commentN).c_str());
00499 if (!pers_RunTxtCommentN) {
00500
00501 RunComment.Write(names->getRunTxtComment(commentN).c_str());
00502 }
00503 nlines++;
00504 }
00505
00506
00507
00508 in.close();
00509 file->Close();
00510
00511 }
00512
00513
00514 void ArchScanResult::SaveModuleComment() {
00515
00516
00517
00518 string filename = names->getfilename();
00519 string runID = names->getRunID();
00520 string moduleID = names->getModuleID();
00521
00522 TFile *file = new TFile(filename.c_str(),"update");
00523 if (file->IsZombie() == true) {
00524 cout << "The ScanResult has NOT been saved in any file"<<endl;
00525 return ;
00526 }
00527
00528 TDirectory *this_run = (TDirectory*) gDirectory->Get(runID.c_str());
00529 if (!this_run) {
00530
00531 this_run = file->mkdir(runID.c_str());
00532
00533 }
00534 this_run->cd();
00535
00536
00537
00538 TDirectory* this_module = (TDirectory*) gDirectory->Get(moduleID.c_str());
00539 if (!this_module) {
00540
00541 this_module =gDirectory ->mkdir(moduleID.c_str());
00542 }
00543 this_module->cd();
00544
00545
00546
00547
00548 ifstream in;
00549 in.open(names->getTxtCommentModuleName().c_str());
00550
00551
00552 int commentN;
00553 int sz = 1000;
00554 char buf[sz];
00555
00556
00557
00558 int nlines = 0;
00559 while (1) {
00560 in >> commentN;
00561 in.get(buf, sz);
00562 if (!in.good()) break;
00563
00564 TObjString Comment(buf);
00565
00566 TObject* pers_ModuleTxtCommentN = gDirectory->FindObjectAny(names->getModuleTxtComment(commentN).c_str());
00567 if (!pers_ModuleTxtCommentN) {
00568
00569 Comment.Write(names->getModuleTxtComment(commentN).c_str());
00570 }
00571 nlines++;
00572 }
00573
00574
00575
00576 in.close();
00577 file->Close();
00578
00579
00580 }
00581
00582
00583
00584 void ArchScanResult::SaveTestComment() {
00585
00586
00587
00588 string filename = names->getfilename();
00589 string runID = names->getRunID();
00590 string moduleID = names->getModuleID();
00591 string testType = names->getTestType();
00592 TFile *file = new TFile(filename.c_str(),"update");
00593 if (file->IsZombie() == true) {
00594 cout << "The ScanResult has NOT been saved in any file"<<endl;
00595 return ;
00596 }
00597
00598 TDirectory *this_run = (TDirectory*) gDirectory->Get(runID.c_str());
00599 if (!this_run) {
00600
00601 this_run = file->mkdir(runID.c_str());
00602
00603 }
00604 this_run->cd();
00605
00606
00607
00608 TDirectory* this_module = (TDirectory*) gDirectory->Get(moduleID.c_str());
00609 if (!this_module) {
00610
00611 this_module =gDirectory ->mkdir(moduleID.c_str());
00612 }
00613 this_module->cd();
00614
00615
00616
00617 TDirectory* this_testType = (TDirectory*) gDirectory->Get(testType.c_str());
00618 if (!this_testType) {
00619
00620 this_testType = gDirectory->mkdir(testType.c_str());
00621 }
00622 this_testType->cd();
00623
00624
00625
00626
00627 ifstream in;
00628 in.open(names->getTxtCommentTestName().c_str());
00629
00630 int commentN;
00631 int sz = 1000;
00632 char buf[sz];
00633
00634
00635 int nlines = 0;
00636 while (1) {
00637 in >> commentN;
00638 in.get(buf, sz);
00639 if (!in.good()) break;
00640
00641 TObjString Comment(buf);
00642
00643 TObject* pers_TxtCommentN = gDirectory->FindObjectAny(names->getTestTxtComment(commentN).c_str());
00644 if (!pers_TxtCommentN) {
00645
00646 Comment.Write(names->getTestTxtComment(commentN).c_str());
00647 }
00648 nlines++;
00649 }
00650
00651
00652
00653 in.close();
00654 file->Close();
00655
00656 }
00657
00658
00659 void ArchScanResult::SaveVariableComment() {
00660
00661
00662
00663 string filename = names->getfilename();
00664 string runID = names->getRunID();
00665 string moduleID = names->getModuleID();
00666 string testType = names->getTestType();
00667 string variable = names->getVariable();
00668
00669 TFile *file = new TFile(filename.c_str(),"update");
00670 if (file->IsZombie() == true) {
00671 cout << "The ScanResult has NOT been saved in any file"<<endl;
00672 return ;
00673 }
00674
00675 TDirectory *this_run = (TDirectory*) gDirectory->Get(runID.c_str());
00676 if (!this_run) {
00677
00678 this_run = file->mkdir(runID.c_str());
00679
00680 }
00681 this_run->cd();
00682
00683
00684
00685 TDirectory* this_module = (TDirectory*) gDirectory->Get(moduleID.c_str());
00686 if (!this_module) {
00687
00688 this_module =gDirectory ->mkdir(moduleID.c_str());
00689 }
00690 this_module->cd();
00691
00692
00693
00694 TDirectory* this_testType = (TDirectory*) gDirectory->Get(testType.c_str());
00695 if (!this_testType) {
00696
00697 this_testType = gDirectory->mkdir(testType.c_str());
00698 }
00699 this_testType->cd();
00700
00701
00702
00703 TDirectory* this_variable = (TDirectory*) gDirectory->Get(variable.c_str());
00704
00705 if (!this_variable) {
00706
00707 this_variable = gDirectory->mkdir(variable.c_str());
00708 }
00709 this_variable->cd();
00710
00711
00712
00713
00714 ifstream in;
00715 in.open(names->getTxtCommentVariableName().c_str());
00716
00717 int commentN;
00718 int sz = 1000;
00719 char buf[sz];
00720
00721
00722 int nlines = 0;
00723 while (1) {
00724 in >> commentN;
00725 in.get(buf, sz);
00726 if (!in.good()) break;
00727
00728 TObjString Comment(buf);
00729
00730 TObject* pers_TxtCommentN = gDirectory->FindObjectAny(names->getVariableTxtComment(commentN).c_str());
00731 if (!pers_TxtCommentN) {
00732
00733 Comment.Write(names->getVariableTxtComment(commentN).c_str());
00734 }
00735 nlines++;
00736 }
00737
00738
00739
00740 in.close();
00741 file->Close();
00742
00743 }
00744
00745
00746
00747 void ArchScanResult::SaveScanNumberComment() {
00748
00749
00750
00751 string filename = names->getfilename();
00752 string runID = names->getRunID();
00753 string moduleID = names->getModuleID();
00754 string testType = names->getTestType();
00755 string variable = names->getVariable();
00756 string scanID = names->getScanID();
00757
00758 TFile *file = new TFile(filename.c_str(),"update");
00759 if (file->IsZombie() == true) {
00760 cout << "The ScanResult has NOT been saved in any file"<<endl;
00761 return ;
00762 }
00763
00764 TDirectory *this_run = (TDirectory*) gDirectory->Get(runID.c_str());
00765 if (!this_run) {
00766
00767 this_run = file->mkdir(runID.c_str());
00768
00769 }
00770 this_run->cd();
00771
00772
00773
00774 TDirectory* this_module = (TDirectory*) gDirectory->Get(moduleID.c_str());
00775 if (!this_module) {
00776
00777 this_module =gDirectory ->mkdir(moduleID.c_str());
00778 }
00779 this_module->cd();
00780
00781
00782
00783 TDirectory* this_testType = (TDirectory*) gDirectory->Get(testType.c_str());
00784 if (!this_testType) {
00785
00786 this_testType = gDirectory->mkdir(testType.c_str());
00787 }
00788 this_testType->cd();
00789
00790
00791
00792 TDirectory* this_variable = (TDirectory*) gDirectory->Get(variable.c_str());
00793 if (!this_variable) {
00794
00795 this_variable = gDirectory->mkdir(variable.c_str());
00796 }
00797 this_variable->cd();
00798
00799
00800 TDirectory* this_scan = (TDirectory*) gDirectory->Get(scanID.c_str());
00801 if (!this_scan) {
00802
00803 this_scan =gDirectory ->mkdir(scanID.c_str());
00804 }
00805 this_scan->cd();
00806
00807
00808
00809
00810 ifstream in;
00811 in.open(names->getTxtCommentScanNumberName().c_str());
00812
00813 int commentN;
00814 int sz = 1000;
00815 char buf[sz];
00816
00817
00818 int nlines = 0;
00819 while (1) {
00820 in >> commentN;
00821 in.get(buf, sz);
00822 if (!in.good()) break;
00823
00824 TObjString Comment(buf);
00825
00826 TObject* pers_TxtCommentN = gDirectory->FindObjectAny(names->getScanNumberTxtComment(commentN).c_str());
00827 if (!pers_TxtCommentN) {
00828
00829 Comment.Write(names->getScanNumberTxtComment(commentN).c_str());
00830 }
00831 nlines++;
00832 }
00833
00834
00835
00836 in.close();
00837 file->Close();
00838
00839 }
00840
00841
00842 void ArchScanResult::SaveRODComment() {
00843
00844
00845
00846 string filename = names->getfilename();
00847 string runID = names->getRunID();
00848 string moduleID = names->getModuleID();
00849 string testType = names->getTestType();
00850 string variable = names->getVariable();
00851 string scanID = names->getScanID();
00852 string RODID = names->getRODID();
00853
00854 TFile *file = new TFile(filename.c_str(),"update");
00855 if (file->IsZombie() == true) {
00856 cout << "The ScanResult has NOT been saved in any file"<<endl;
00857 return ;
00858 }
00859
00860 TDirectory *this_run = (TDirectory*) gDirectory->Get(runID.c_str());
00861 if (!this_run) {
00862
00863 this_run = file->mkdir(runID.c_str());
00864
00865 }
00866 this_run->cd();
00867
00868
00869
00870 TDirectory* this_module = (TDirectory*) gDirectory->Get(moduleID.c_str());
00871 if (!this_module) {
00872
00873 this_module =gDirectory ->mkdir(moduleID.c_str());
00874 }
00875 this_module->cd();
00876
00877
00878
00879 TDirectory* this_testType = (TDirectory*) gDirectory->Get(testType.c_str());
00880 if (!this_testType) {
00881
00882 this_testType = gDirectory->mkdir(testType.c_str());
00883 }
00884 this_testType->cd();
00885
00886
00887
00888 TDirectory* this_variable = (TDirectory*) gDirectory->Get(variable.c_str());
00889 if (!this_variable) {
00890
00891 this_variable = gDirectory->mkdir(variable.c_str());
00892 }
00893 this_variable->cd();
00894
00895
00896 TDirectory* this_scan = (TDirectory*) gDirectory->Get(scanID.c_str());
00897 if (!this_scan) {
00898
00899 this_scan =gDirectory ->mkdir(scanID.c_str());
00900 }
00901 this_scan->cd();
00902
00903
00904 TDirectory* this_ROD = (TDirectory*) this_scan->Get(RODID.c_str());
00905 if (!this_ROD) {
00906
00907 this_ROD = this_scan->mkdir(RODID.c_str());
00908 }
00909 this_ROD->cd();
00910
00911
00912
00913 ifstream in;
00914 in.open(names->getTxtCommentRODName().c_str());
00915
00916 int commentN;
00917 int sz = 1000;
00918 char buf[sz];
00919
00920
00921 int nlines = 0;
00922 while (1) {
00923 in >> commentN;
00924 in.get(buf, sz);
00925 if (!in.good()) break;
00926
00927 TObjString Comment(buf);
00928
00929 TObject* pers_TxtCommentN = gDirectory->FindObjectAny(names->getRODTxtComment(commentN).c_str());
00930 if (!pers_TxtCommentN) {
00931
00932 Comment.Write(names->getRODTxtComment(commentN).c_str());
00933 }
00934 nlines++;
00935 }
00936
00937
00938
00939 in.close();
00940 file->Close();
00941
00942 }