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