00001 #include "Archiving.h"
00002 #include "SctData/RawScanResult.h"
00003 #include <vector>
00004 #include <string>
00005 #include <is/isinfo.h>
00006 #include <fstream>
00007 #include <iostream>
00008 #include <TSystem.h>
00009 #include <TH1.h>
00010 #include <TH2.h>
00011 #include <TObjString.h>
00012 #include <TDirectory.h>
00013 #include <TList.h>
00014 #include <TFile.h>
00015 #include "SctData/ModuleConfiguration.h"
00016 #include "Sct/IS/IOManagerIS.h"
00017 #include "Sct/SctNames.h"
00018
00019
00020 #include "ArchScanNames.h"
00021 #include <sys/types.h>
00022 #include <sys/dir.h>
00023 #include <stdio.h>
00024 #include <sys/param.h>
00025 #include <unistd.h>
00026
00027
00028 using namespace SctData;
00029 using namespace Sct;
00030 using namespace Sct::IS;
00031 using namespace boost;
00032 using namespace std;
00033
00034
00035
00036
00037
00038
00039
00040 Archiving::Archiving() {
00041
00042
00043
00044
00045 }
00046
00047
00048 Archiving::~Archiving() {
00049
00050
00051
00052 }
00053
00054
00055 void Archiving::SetUNIXDir() {
00056
00057
00058 cout <<"Making DataArchive UNIX dir" <<endl;
00059 char *path = "DataArchive";
00060
00061
00062 string archivingDirName = getenv("SCT_DAQ_ROOT");
00063 archivingDirName = archivingDirName + "/archiving";
00064 gSystem->cd(archivingDirName.c_str());
00065
00066 const char *ArchDir =gSystem->pwd();
00067
00068 char* DirTest = strstr(ArchDir,path);
00069 if(DirTest != NULL) { return; }
00070
00071 int okdir;
00072 bool okcd;
00073 okcd = gSystem->cd(path);
00074
00075 if (okcd == 0) {
00076 cout<< " Dir "<< *path << " doesn't exists" << endl;
00077 okdir = gSystem->mkdir(path);
00078 okcd = gSystem->cd(path);
00079 }
00080
00081
00082
00083 }
00084
00085
00086
00087 void Archiving::DeleteISObj(char* objName) {
00088
00089
00090 IPCPartition& p = SctNames::getPartition();
00091 ISInfoDictionary id(p);
00092 ISInfo::Status result;
00093
00094 cout << "About to DELETE obj " << objName <<endl;
00095
00096
00097 bool myresult=id.contains(objName);
00098
00099 if (myresult != true) {
00100 cout << "!!!!Obj Not Found in Dictionary" << endl;
00101 return;
00102 }
00103 if (myresult == true) {
00104 cout << "))))))Obj Found in Dictionary" << endl;
00105 result = id.remove(objName);
00106 if (result != ISInfo::Success) {
00107 cout << "!!!!ERROR deleting object:" << endl;
00108 if (result == ISInfo::NotFound) {
00109 cout << "!!!!Obj Not Found in Dictionary" << endl;
00110 }else{
00111 cout << "!!!!Unrecognised error" << endl;
00112 }
00113 }
00114 if (result == ISInfo::Success) cout << "))))))OBJ DELETED" << endl;
00115
00116 }
00117
00118
00119
00120 }
00121
00122
00123
00124 void Archiving::ListISObj() {
00125
00126
00127 IPCPartition& p = SctNames::getPartition();
00128
00129
00130
00131 ISInfoIterator iter1(p, SctNames::getEventDataName().c_str(), "SctData::RawScanResult.*");
00132 int count=0;
00133
00134 while ( iter1++ ) {
00135 cout << "IS RawScanResult Object in EventData server " << iter1.name( ) << " created at" <<
00136 iter1.time( ).c_str( ) << "... " << endl;
00137 count++;
00138 }
00139 cout<<count<<" RawScanResult Objects in IS server"<<endl;
00140
00141
00142 ISInfoIterator iter3(p, SctNames::getFittedDataName().c_str(), "SctData::FitScanResult.*");
00143 count=0;
00144
00145 while ( iter3++ ) {
00146 cout << "IS FitScanResult Object in FittedData server " << iter3.name( ) << " created at" <<
00147 iter3.time( ).c_str( ) << "... " << endl;
00148 count++;
00149 }
00150 cout<<count<<" FitScanResult Objects in IS FittedData server"<<endl;
00151
00152
00153
00154
00155 ISInfoIterator iter4(p, SctNames::getTestDataName().c_str(), "SctData::NoiseOccupancyTestResult.*");
00156 count=0;
00157 while ( iter4++ ) {
00158 cout << "IS NoiseOccupancyTestResult Object in TestData server " << iter4.name( ) << " created at" <<
00159 iter4.time( ).c_str( ) << "... " << endl;
00160 count++;
00161 }
00162 cout<<count<<" NoiseOccupancyTestResult Objects in IS TestData server"<<endl;
00163
00164
00165
00166
00167 ISInfoIterator iter5(p, SctNames::getTestDataName().c_str(), "SctData::NPtGainTestResult.*");
00168 count=0;
00169
00170 while ( iter5++ ) {
00171 cout << "IS NPtGainTestResult Object in TestData server " << iter5.name( ) << " created at" <<
00172 iter5.time( ).c_str( ) << "... " << endl;
00173 count++;
00174 }
00175 cout<<count<<" NPtGainTestResult Objects in IS TestData server"<<endl;
00176
00177
00178
00179
00180 ISInfoIterator iter6(p, SctNames::getTestDataName().c_str(), "SctData::TrimRangeTestResult.*");
00181 count=0;
00182
00183 while ( iter6++ ) {
00184 cout << "IS TrimRangeTestResult Object in TestData server " << iter6.name( ) << " created at" <<
00185 iter6.time( ).c_str( ) << "... " << endl;
00186 count++;
00187 }
00188 cout<<count<<" TrimRangeTestResult Objects in IS TestData server"<<endl;
00189
00190
00191
00192
00193 ISInfoIterator iter7(p, SctNames::getTestDataName().c_str() , "SctData::PipelineTestResult.*");
00194 count=0;
00195
00196 while ( iter7++ ) {
00197 cout << "IS PipelineTestResult Object in TestData server " << iter7.name( ) << " created at" <<
00198 iter7.time( ).c_str( ) << "... " << endl;
00199 count++;
00200 }
00201 cout<<count<<" PipelineTestResult Objects in IS TestData server"<<endl;
00202
00203
00204
00205 ISInfoIterator iter8(p, SctNames::getTestDataName().c_str() , "SctData::TimeWalkTestResult.*");
00206 count=0;
00207
00208 while ( iter8++ ) {
00209 cout << "IS TimeWalkTestResult Object in TestData server " << iter8.name( ) << " created at" <<
00210 iter8.time( ).c_str( ) << "... " << endl;
00211 count++;
00212 }
00213 cout<<count<<" TimeWalkTestResult Objects in IS TestData server"<<endl;
00214
00215
00216
00217 ISInfoIterator iter9(p, SctNames::getTestDataName().c_str(), "SctData::FullBypassTestResult.*");
00218 count=0;
00219
00220 while ( iter9++ ) {
00221 cout << "IS FullBypassTestResult Object in TestData server " << iter9.name( ) << " created at" <<
00222 iter9.time( ).c_str( ) << "... " << endl;
00223 count++;
00224 }
00225 cout<<count<<" FullBypassTestResult Objects in IS TestData server"<<endl;
00226
00227
00228
00229 ISInfoIterator iter10(p, SctNames::getTestDataName().c_str(), "SctData::NMaskTestResult.*");
00230 count=0;
00231
00232 while ( iter10++ ) {
00233 cout << "IS NMaskTestResult Object in TestData server " << iter10.name( ) << " created at" <<
00234 iter10.time( ).c_str( ) << "... " << endl;
00235 count++;
00236 }
00237 cout<<count<<" NMaskTestResult Objects in IS TestData server"<<endl;
00238
00239
00240
00241 }
00242
00243
00244
00245 ISInfoIterator* Archiving::SetupRawIS() {
00246
00247 cout << " I am SETtingUP Raw IS "<<endl;
00248 IPCPartition& p = SctNames::getPartition();
00249
00250 ISInfoIterator iter(p, SctNames::getEventDataName().c_str(),"SctData::RawScanResult.*" ) ;
00251 cout << iter.entries() << " entries in SetupIS() for "<<"SctData::RawScanResult.*" << endl;
00252
00253 ISInfoIterator *it;
00254 it=&iter;
00255 return it ;
00256
00257 }
00258
00259 ISInfoIterator* Archiving::SetupFitIS() {
00260
00261 cout << " I am SETtingUP Fit IS "<<endl;
00262 IPCPartition& p = SctNames::getPartition();
00263
00264 ISInfoIterator iter(p, SctNames::getFittedDataName().c_str(), "FitScanResult.*") ;
00265 cout << iter.entries() << " entries in SetupIS() for "<< "FitScanResult.*" << endl;
00266
00267 ISInfoIterator *it;
00268 it=&iter;
00269 return it ;
00270
00271 }
00272
00273
00274
00275 ISInfoIterator* Archiving::SetupNoiseOccupancyTestIS() {
00276
00277 cout << " I am SETtingUP NoiseOccupancyTest IS "<<endl;
00278 IPCPartition& p = SctNames::getPartition();
00279 ISInfoIterator iter(p, SctNames::getTestDataName().c_str(),"SctData::NoiseOccupancyTestResult.*" ) ;
00280 cout << iter.entries() << " entries in SetupIS() for "<< "SctData::NoiseOccupancyTestResult.*" << endl;
00281
00282 ISInfoIterator *it;
00283 it=&iter;
00284 return it ;
00285
00286 }
00287
00288
00289 ISInfoIterator* Archiving::SetupNPtGainTestIS() {
00290
00291 cout << " I am SETtingUP NPtGainTest IS "<<endl;
00292 IPCPartition& p = SctNames::getPartition();
00293 ISInfoIterator iter(p, SctNames::getTestDataName().c_str(),"SctData::NPtGainTestResult.*" ) ;
00294 cout << iter.entries() << " entries in SetupIS() for "<< "SctData::NPtGainTestResult.*" << endl;
00295
00296 ISInfoIterator *it;
00297 it=&iter;
00298 return it ;
00299
00300 }
00301
00302
00303 ISInfoIterator* Archiving::SetupStrobeDelayTestIS() {
00304
00305 cout << " I am SETtingUP StrobeDelayTest IS "<<endl;
00306 IPCPartition& p = SctNames::getPartition();
00307 ISInfoIterator iter(p, SctNames::getTestDataName().c_str(),"SctData::StrobeDelayTestResult.*" ) ;
00308 cout << iter.entries() << " entries in SetupIS() for "<< "SctData::StrobeDelayTestResult.*" << endl;
00309
00310 ISInfoIterator *it;
00311 it=&iter;
00312 return it ;
00313
00314 }
00315
00316
00317 ISInfoIterator* Archiving::SetupTrimRangeTestIS() {
00318
00319 cout << " I am SETtingUP TrimRangeTest IS "<<endl;
00320 IPCPartition& p = SctNames::getPartition();
00321 ISInfoIterator iter(p, SctNames::getTestDataName().c_str(),"SctData::TrimRangeTestResult.*" ) ;
00322 cout << iter.entries() << " entries in SetupIS() for "<< "SctData::TrimRangeTestResult.*" << endl;
00323
00324 ISInfoIterator *it;
00325 it=&iter;
00326 return it ;
00327
00328 }
00329
00330
00331 ISInfoIterator* Archiving::SetupPipelineTestIS() {
00332
00333 cout << " I am SETtingUP PipelineTest IS "<<endl;
00334 IPCPartition& p = SctNames::getPartition();
00335 ISInfoIterator iter(p, SctNames::getTestDataName().c_str(),"SctData::PipelineTestResult.*" ) ;
00336 cout << iter.entries() << " entries in SetupIS() for "<< "SctData::PipelineTestResult.*" << endl;
00337
00338 ISInfoIterator *it;
00339 it=&iter;
00340 return it ;
00341
00342 }
00343
00344
00345 ISInfoIterator* Archiving::SetupTimeWalkTestIS() {
00346
00347 cout << " I am SETtingUP TimeWalkTest IS "<<endl;
00348 IPCPartition& p = SctNames::getPartition();
00349 ISInfoIterator iter(p, SctNames::getTestDataName().c_str(),"SctData::TimeWalkTestResult.*" ) ;
00350 cout << iter.entries() << " entries in SetupIS() for "<< "SctData::TimeWalkTestResult.*" << endl;
00351
00352 ISInfoIterator *it;
00353 it=&iter;
00354 return it ;
00355
00356 }
00357
00358 ISInfoIterator* Archiving::SetupFullBypassTestIS() {
00359
00360 cout << " I am SETtingUP FullBypassTest IS "<<endl;
00361 IPCPartition& p = SctNames::getPartition();
00362 ISInfoIterator iter(p, SctNames::getTestDataName().c_str(),"SctData::FullBypassTestResult.*" ) ;
00363 cout << iter.entries() << " entries in SetupIS() for "<< "SctData::FullBypassTestResult.*" << endl;
00364
00365 ISInfoIterator *it;
00366 it=&iter;
00367 return it ;
00368
00369 }
00370
00371
00372 ISInfoIterator* Archiving::SetupNMaskTestIS() {
00373
00374 cout << " I am SETtingUP NMaskTest IS "<<endl;
00375 IPCPartition& p = SctNames::getPartition();
00376 ISInfoIterator iter(p, SctNames::getTestDataName().c_str(),"SctData::NMaskTestResult.*" ) ;
00377 cout << iter.entries() << " entries in SetupIS() for "<< "SctData::NMaskTestResult.*" << endl;
00378
00379 ISInfoIterator *it;
00380 it=&iter;
00381 return it ;
00382
00383 }
00384
00385
00386 IPCPartition* Archiving::GetPartition() {
00387
00388 IPCPartition& p = SctNames::getPartition();
00389 return &p;
00390
00391 }
00392
00393
00394
00395 string Archiving::GetRawISUniqueID(unsigned int runNumber, unsigned int scanNumber, const string& moduleName) {
00396
00397 ScanHeader s;
00398 string tmp_rawISname = s.getUniqueID(runNumber, scanNumber, moduleName);
00399 string rawISname = SctNames::getEventDataName();
00400 string str_rawdata = ".SctData::RawScanResult.";
00401 rawISname = rawISname + str_rawdata;
00402 rawISname = rawISname + tmp_rawISname;
00403
00404 return rawISname;
00405
00406 }
00407
00408
00409
00410 string Archiving::GetFitISUniqueID(unsigned int runNumber, unsigned int scanNumber, const string& moduleName) {
00411
00412 ScanHeader s;
00413 string tmp_fitISname = s.getUniqueID(runNumber, scanNumber, moduleName);
00414 string fitISname = SctNames::getFittedDataName();
00415 string str_fitdata = ".SctData::FitScanResult.";
00416 fitISname = fitISname + str_fitdata;
00417 fitISname = fitISname + tmp_fitISname;
00418 return fitISname;
00419
00420 }
00421
00422
00423
00424 shared_ptr<Serializable> Archiving::ISRetrieveObj(ISInfoIterator& it) {
00425
00426 cout << "IS obj name = " << it.name() <<endl;
00427 cout << "IS obj type = "<< it.type().name() << endl;
00428 cout << it.entries() << " objects in IS server" << endl;
00429
00430 cout <<"About to RETRIEVE Serializable obj From IS " <<endl;
00431 shared_ptr<Serializable> ob = IOManagerIS::instance().read(it);
00432 cout<<"I am here" <<endl;
00433
00434 cout<<"I am here" <<endl;
00435
00436 return ob;
00437 }
00438
00439
00440 shared_ptr<Serializable> Archiving::ISRetrieveObj(const string& SerISName) {
00441
00442 cout <<"About to RETRIEVE Serializable obj From IS : " << SerISName << endl;
00443 shared_ptr<Serializable> ob = IOManagerIS::instance().read(SerISName);
00444
00445 cout<<"Obj succesfully retrieved"<<endl;
00446 return ob;
00447 }
00448
00449
00450 shared_ptr<ScanResult> Archiving::ISRetrieveScanResult(const string& ScanISName) {
00451
00452 shared_ptr<Serializable> ob = ISRetrieveObj(ScanISName);
00453 shared_ptr<ScanResult> scan = boost::dynamic_pointer_cast<ScanResult>(ob);
00454
00455
00456 return scan;
00457 }
00458
00459 shared_ptr<ScanResult> Archiving::ISRetrieveScanResult(ISInfoIterator& it) {
00460 shared_ptr<Serializable> ob = ISRetrieveObj(it);
00461 shared_ptr<ScanResult> scan = boost::dynamic_pointer_cast<ScanResult>(ob);
00462 return scan;
00463 }
00464
00465
00466 shared_ptr<RawScanResult> Archiving::ISRetrieveRawScanResult(const string& RawISName) {
00467 shared_ptr<Serializable> ob = ISRetrieveObj(RawISName);
00468 shared_ptr<RawScanResult> raw = boost::dynamic_pointer_cast<RawScanResult>(ob);
00469 return raw;
00470 }
00471
00472 shared_ptr<RawScanResult> Archiving::ISRetrieveRawScanResult(ISInfoIterator& it) {
00473 shared_ptr<Serializable> ob = ISRetrieveObj(it);
00474 shared_ptr<RawScanResult> raw = boost::dynamic_pointer_cast<RawScanResult>(ob);
00475 return raw;
00476 }
00477
00478
00479 shared_ptr<FitScanResult> Archiving::ISRetrieveFitScanResult(const string& FitISName) {
00480 shared_ptr<Serializable> ob = ISRetrieveObj(FitISName);
00481 shared_ptr<FitScanResult> fit =boost::dynamic_pointer_cast<FitScanResult>(ob);
00482 return fit;
00483 }
00484
00485
00486 shared_ptr<FitScanResult> Archiving::ISRetrieveFitScanResult(ISInfoIterator& it) {
00487 shared_ptr<Serializable> ob = ISRetrieveObj(it);
00488 shared_ptr<FitScanResult> fit = boost::dynamic_pointer_cast<FitScanResult>(ob);
00489 return fit;
00490 }
00491
00492
00493 void Archiving::ISSendPersScanResult(RawScanResult & r) {
00494
00495
00496 if( &r == 0) {
00497 cout<<" Error in publishing RawScanResult obj " <<endl;
00498 return;
00499 }
00500
00501 cout << "About to PUBLISH obj "<<r.getClassName().c_str()<<"."<< r.getHeader().getUniqueID().c_str() << endl;
00502
00503 IPCPartition& p = SctNames::getPartition();
00504 ISInfoDictionary id(p);
00505 string tmp_thisobjName;
00506 tmp_thisobjName = SctNames::getEventDataName();
00507 tmp_thisobjName = tmp_thisobjName + ".";
00508
00509 const string thisobjName = tmp_thisobjName + r.getClassName() + "." + r.getHeader().getUniqueID();
00510 bool myresult=id.contains(thisobjName.c_str());
00511 cout<< "UniqueID = " << thisobjName.c_str() <<endl;
00512 cout<<" myresult = "<< myresult <<endl;
00513
00514 if (myresult == 1) {
00515 cout << "!!!!!Obj "<<r.getClassName().c_str()<<"."<<r.getHeader().getUniqueID().c_str() << " Not Published: already in Dictionary" << endl;
00516 return;
00517 }
00518 if (myresult == 0) {
00519 IOParamsIS params(SctNames::getEventDataName());
00520 IOManagerIS::instance().write(r, ¶ms);
00521 cout << ")))))) PUBLISHED Obj "<<r.getClassName().c_str()<<"."<<r.getHeader().getUniqueID().c_str() << endl;
00522 }
00523
00524
00525 }
00526
00527
00528 void Archiving::ISSendPersScanResult(FitScanResult& f) {
00529
00530
00531 if( &f == 0) {
00532 cout<<" Error in publishing FitScanResult obj " <<endl;
00533 return;
00534 }
00535
00536 cout << "About to PUBLISH obj "<<f.getClassName().c_str()<<"."<<f.getHeader().getUniqueID().c_str() << endl;
00537
00538 IPCPartition& p = SctNames::getPartition();
00539 ISInfoDictionary id(p);
00540 string tmp_thisobjName;
00541 tmp_thisobjName = SctNames::getFittedDataName();
00542 tmp_thisobjName = tmp_thisobjName + ".";
00543
00544 const string thisobjName = tmp_thisobjName + f.getClassName() + "." + f.getHeader().getUniqueID();
00545 cout<< "thisobjName = " <<thisobjName.c_str()<<endl;
00546 bool myresult=id.contains(thisobjName.c_str());
00547 cout<< "UniqueID = " << thisobjName.c_str() <<endl;
00548 cout<<" myresult = "<< myresult <<endl;
00549
00550 if (myresult == 1) {
00551 cout << "!!!!!Obj " <<f.getClassName().c_str()<<"."<<f.getHeader().getUniqueID().c_str()<< " Not Published: already in Dictionary" << endl;
00552 return;
00553 }
00554 if (myresult == 0 ) {
00555 IOParamsIS params(SctNames::getFittedDataName());
00556 IOManagerIS::instance().write(f, ¶ms);
00557 cout << ")))))) PUBLISHED Obj "<<f.getClassName().c_str()<<"."<<f.getHeader().getUniqueID().c_str() << endl;
00558 }
00559
00560
00561 }
00562
00563
00564 bool Archiving::IsTestInIndex(unsigned int runNumber, string moduleName, string testType) {
00565
00566
00567
00568
00569 cout << "I am in IsTestInIndex() " << endl;
00570 ArchTestNames names(runNumber,moduleName,testType);
00571 string index = names.getIndexFileName();
00572 ifstream index_file;
00573
00574
00575 index_file.open(index.c_str());
00576
00577 string indexTestName = names.getRunID() + ".";
00578 indexTestName = indexTestName + names.getModuleID();
00579 indexTestName = indexTestName + ".";
00580 indexTestName = indexTestName + names.getTestType();
00581
00582 int sz = 100;
00583 char buf[sz];
00584 string tmp_buf;
00585
00586 while(index_file.getline(buf, sz)) {
00587
00588 tmp_buf = buf;
00589
00590 int i = tmp_buf.find(indexTestName.c_str());
00591 if( i != tmp_buf.npos ) {
00592 cout << "Test " << indexTestName << " found in Index" <<endl;
00593 return true;
00594 }
00595
00596 }
00597 cout << "Test " << indexTestName << " NOT found in Index" <<endl;
00598 return false;
00599
00600
00601 }
00602
00603 bool Archiving::IsTestInIndex(string runID, string moduleID, string testType) {
00604
00605
00606
00607
00608 cout << "I am in IsTestInIndex() " << endl;
00609 ArchTestNames names;
00610 string index = names.getIndexFileName();
00611 ifstream index_file;
00612
00613
00614 index_file.open(index.c_str());
00615
00616
00617 string indexTestName = runID + ".";
00618 indexTestName = indexTestName + moduleID;
00619 indexTestName = indexTestName + ".";
00620 indexTestName = indexTestName + testType;
00621
00622 int sz = 100;
00623 char buf[sz];
00624 string tmp_buf;
00625
00626 while(index_file.getline(buf, sz)) {
00627
00628 tmp_buf = buf;
00629
00630 int i = tmp_buf.find(indexTestName.c_str());
00631 if( i != tmp_buf.npos ) {
00632 cout << "Test " << indexTestName << " found in Index" <<endl;
00633 return true;
00634 }
00635
00636 }
00637 cout << "Test " << indexTestName << " NOT found in Index" <<endl;
00638 return false;
00639
00640
00641 }
00642
00643
00644 bool Archiving::IsScanInIndex(unsigned int runNumber, string moduleName, string testType, unsigned int scanNumber) {
00645
00646
00647
00648
00649 cout << "I am in IsScanInIndex() " << endl;
00650 ArchTestNames names(runNumber,moduleName,testType);
00651 string index = names.getIndexFileName();
00652 ifstream index_file;
00653
00654
00655 index_file.open(index.c_str());
00656
00657
00658 string scanID;
00659 char tmp_scanID[40];
00660 sprintf(tmp_scanID,"Scan%i",scanNumber);
00661 scanID = tmp_scanID;
00662
00663 string indexScanName = names.getRunID() + ".";
00664 indexScanName = indexScanName + names.getModuleID();
00665 indexScanName = indexScanName + ".";
00666 indexScanName = indexScanName + names.getTestType();
00667 indexScanName = indexScanName + ".";
00668 indexScanName = indexScanName + scanID;
00669
00670 int sz = 100;
00671 char buf[sz];
00672 string tmp_buf;
00673
00674 while(index_file.getline(buf, sz)) {
00675
00676 tmp_buf = buf;
00677
00678 int i = tmp_buf.find(indexScanName.c_str());
00679 if( i != tmp_buf.npos ) {
00680 cout << "Scan " << indexScanName << " found in Index" <<endl;
00681 return true;
00682 }
00683
00684 }
00685 cout << "Scan " << indexScanName << " NOT found in Index" <<endl;
00686 return false;
00687
00688
00689 }
00690
00691
00692 bool Archiving::IsScanInIndex(string runID, string moduleID, string testType, string scanID) {
00693
00694
00695
00696
00697 cout << "I am in IsScanInIndex() " << endl;
00698
00699 ArchTestNames names;
00700 string index = names.getIndexFileName();
00701 ifstream index_file;
00702
00703
00704 index_file.open(index.c_str());
00705
00706
00707
00708
00709 string indexScanName = runID + ".";
00710 indexScanName = indexScanName + moduleID;
00711 indexScanName = indexScanName + ".";
00712 indexScanName = indexScanName + testType;
00713 indexScanName = indexScanName + ".";
00714 indexScanName = indexScanName + scanID;
00715
00716 int sz = 100;
00717 char buf[sz];
00718 string tmp_buf;
00719
00720 while(index_file.getline(buf, sz)) {
00721
00722 tmp_buf = buf;
00723
00724 int i = tmp_buf.find(indexScanName.c_str());
00725 if( i != tmp_buf.npos ) {
00726 cout << "Scan " << indexScanName << " found in Index" <<endl;
00727 return true;
00728 }
00729
00730 }
00731 cout << "Scan " << indexScanName << " NOT found in Index" <<endl;
00732 return false;
00733
00734
00735 }
00736
00737
00738 void Archiving::AddTestToIndex(string runID, string moduleID, string testTypeID) {
00739
00740
00741
00742 cout << "I am in AddTestToIndex() " << endl;
00743 ArchTestNames names;
00744 string index = names.getIndexFileName();
00745 ofstream index_file;
00746 index_file.open(index.c_str(),ios::app);
00747
00748
00749 string indexTestName = runID + ".";
00750 indexTestName = indexTestName + moduleID;
00751 indexTestName = indexTestName + ".";
00752 indexTestName = indexTestName + testTypeID + ".";
00753 cout << indexTestName <<endl;
00754
00755 index_file << indexTestName <<endl;
00756 cout << "Test appended to Index"<<endl;
00757
00758
00759
00760
00761 index_file.close();
00762
00763 }
00764
00765
00766
00767 void Archiving::AddScanToIndex(string runID, string moduleID, string testTypeID, string scanID ) {
00768
00769
00770
00771 cout << "I am in AddScanToIndex() " << endl;
00772 ArchTestNames names;
00773 string index = names.getIndexFileName();
00774 ofstream index_file;
00775 index_file.open(index.c_str(),ios::app);
00776
00777
00778 string indexScanName = runID + ".";
00779 indexScanName = indexScanName + moduleID;
00780 indexScanName = indexScanName + ".";
00781 indexScanName = indexScanName + testTypeID + ".";
00782 indexScanName = indexScanName + scanID;
00783 cout << indexScanName <<endl;
00784
00785 index_file << indexScanName <<endl;
00786 cout << "Scan appended to Index"<<endl;
00787
00788
00789
00790
00791 index_file.close();
00792
00793 }
00794
00795
00796
00797
00798
00799 void Archiving::UpdateScanIndex() {
00800
00801
00802
00803
00804 ArchScanNames names;
00805
00806
00807 const char* filename = NULL;
00808 const char *currentDir = gSystem->pwd();
00809 void* dirptr = gSystem->OpenDirectory(currentDir);
00810 bool alwaystrue = true;
00811 while(alwaystrue == true ){
00812 const char* tmp_filename = gSystem->GetDirEntry(dirptr);
00813
00814 if(tmp_filename == NULL) break;
00815 char* Runname = strstr(tmp_filename,"Run");
00816 char* Rootname = strstr(tmp_filename,".root");
00817 if(Runname != NULL && Rootname != NULL) {
00818 filename = tmp_filename;
00819
00820
00821
00822
00823 TFile *archive_file = new TFile(filename,"read");
00824 if (archive_file->IsZombie() == true) {
00825 cout << "Problem in opening file... "<<filename<<endl;
00826 exit(0);
00827 }
00828
00829
00830
00831 TDirectory *gModuleDir = new TDirectory();
00832 TDirectory *gtestTypeDir = new TDirectory();
00833 TDirectory *gvariableDir = new TDirectory();
00834 TDirectory *gscanDir = new TDirectory();
00835
00836
00837
00838 TList* runsList = gDirectory->GetListOfKeys();
00839 TListIter itruns(runsList);
00840 while (TObject *runsobj = itruns.Next()) {
00841 string runID = runsobj->GetName();
00842 if (runsobj->GetTitle() == runID ) {
00843 if (gDirectory->cd(runID.c_str())==1) {
00844
00845 gModuleDir = gDirectory;
00846 TList* modulesList = gDirectory->GetListOfKeys();
00847 TListIter itmodules(modulesList);
00848 while (TObject *modulesobj = itmodules.Next()) {
00849 string moduleID = modulesobj->GetName();
00850 string modulesobjID = modulesobj->GetTitle();
00852 if (modulesobj->GetTitle() == moduleID ) {
00853 gModuleDir->cd();
00854 if (gDirectory->cd(moduleID.c_str())== 1) {
00855
00856 gtestTypeDir = gDirectory;
00857 TList* testTypeList = gDirectory->GetListOfKeys();
00858 TListIter ittestType(testTypeList);
00859 while (TObject *testTypeobj = ittestType.Next()) {
00860 string testTypeID = testTypeobj->GetName();
00861 if (testTypeobj->GetTitle() == testTypeID ) {
00862 gtestTypeDir->cd();
00863 if (gDirectory->cd(testTypeID.c_str())==1 ) {
00864
00865
00866 gvariableDir = gDirectory;
00867 TList* variableList = gDirectory->GetListOfKeys();
00868 TListIter itvariable(variableList);
00869 while (TObject *variableobj = itvariable.Next()) {
00870 string variableID = variableobj->GetName();
00871 if (variableobj->GetTitle() == variableID ) {
00872 gvariableDir->cd();
00873 if (gDirectory->cd(variableID.c_str())==1 ) {
00874 gDirectory->Print();
00875
00876 gscanDir = gDirectory;
00877 TList* scanList = gDirectory->GetListOfKeys();
00878 TListIter itscan(scanList);
00879 while (TObject *scanobj = itscan.Next()) {
00880 string scanID = scanobj->GetName();
00881 if (scanobj->GetTitle() == scanID ) {
00882 gscanDir->cd();
00883 if (gDirectory->cd(scanID.c_str())==1 ) {
00884
00885
00886 if ( !IsScanInIndex(runID, moduleID, testTypeID, scanID) ) {
00887 AddScanToIndex(runID, moduleID, testTypeID, scanID );
00888 }
00889 }
00890 }
00891 }
00892 }
00893 }
00894 }
00895 }
00896 }
00897 }
00898 }
00899 }
00900 }
00901 }
00902 }
00903 }
00904
00905
00906
00907
00908 }
00909 }
00910
00911
00912 return;
00913
00914
00915
00916 }
00917
00918
00919
00920
00921
00922
00923 void Archiving::UpdateTestIndex() {
00924
00925
00926
00927
00928 const char* cfilename = NULL;
00929 const char *currentDir = gSystem->pwd();
00930 void* dirptr = gSystem->OpenDirectory(currentDir);
00931 bool alwaystrue = true;
00932 while(alwaystrue == true ){
00933 const char* tmp_cfilename = gSystem->GetDirEntry(dirptr);
00934
00935 if(tmp_cfilename == NULL) break;
00936 char* Runname = strstr(tmp_cfilename,"Run");
00937 char* Rootname = strstr(tmp_cfilename,".root");
00938 if(Runname != NULL && Rootname != NULL) {
00939 cfilename = tmp_cfilename;
00940
00941
00942
00943 string runNo = Runname;
00944
00945 string filename = tmp_cfilename;
00946
00947 ArchScanNames names;
00948
00949
00950
00951 TFile *archive_file = new TFile(filename.c_str(),"read");
00952 if (archive_file->IsZombie() == true) {
00953 cout << "Problem in opening file..."<<endl;
00954 exit(1);
00955 }
00956 cout<<" File found!!"<<endl;
00957
00958
00959 TDirectory *gModuleDir = new TDirectory();
00960 TDirectory *gtestTypeDir = new TDirectory();
00961
00962
00963
00964 TList* runsList = gDirectory->GetListOfKeys();
00965 TListIter itruns(runsList);
00966 while (TObject *runsobj = itruns.Next()) {
00967
00968
00969 string runID = runsobj->GetName();
00970 if (runsobj->GetTitle() == runID ) {
00971 if (gDirectory->cd(runID.c_str())==1) {
00972
00973 gModuleDir = gDirectory;
00974 TList* modulesList = gDirectory->GetListOfKeys();
00975 TListIter itmodules(modulesList);
00976 while (TObject *modulesobj = itmodules.Next()) {
00977 string moduleID = modulesobj->GetName();
00978 string modulesobjID = modulesobj->GetTitle();
00980 if (modulesobj->GetTitle() == moduleID ) {
00981 gModuleDir->cd();
00982 if (gDirectory->cd(moduleID.c_str())== 1) {
00983
00984 gtestTypeDir = gDirectory;
00985 TList* testTypeList = gDirectory->GetListOfKeys();
00986 TListIter ittestType(testTypeList);
00987 while (TObject *testTypeobj = ittestType.Next()) {
00988 string testTypeID = testTypeobj->GetName();
00989 if (testTypeobj->GetTitle() == testTypeID ) {
00990 gtestTypeDir->cd();
00991 if (gDirectory->cd(testTypeID.c_str())==1 ) {
00992
00993 if ( !IsTestInIndex(runID, moduleID, testTypeID) ) {
00994 AddTestToIndex(runID, moduleID, testTypeID);
00995 }
00996 }
00997 }
00998 }
00999 }
01000 }
01001 }
01002 }
01003 }
01004 }
01005
01006
01007
01008 }
01009 }
01010
01011
01012 return;
01013
01014
01015
01016 }
01017
01018
01019
01020
01021
01022
01023
01024
01025
01026
01027
01028
01029
01030
01031
01032
01033
01034
01035
01036
01037
01038
01039
01040
01041
01042
01043
01044
01045
01046
01047
01048
01049
01050
01051
01052
01053
01054
01055
01056
01057
01058
01059
01060
01061
01062
01063
01064
01065
01066
01067
01068
01069
01070
01071
01072
01073
01074
01075
01076
01077
01078
01079
01080
01081
01082
01083
01084
01085
01086
01087
01088
01089
01090
01091
01092
01093
01094
01095
01096
01097
01099
01100
01101
01102
01103
01104
01105
01106
01107
01108
01109
01110
01111
01112
01113
01114
01115
01116
01117
01118
01119
01120
01121
01122
01123
01124
01125
01126 string Archiving::getTestSummaryFromArchive(unsigned int runNumber, string moduleName, string testType) {
01127
01128
01129 ArchTestNames *names = new ArchTestNames(runNumber, moduleName, testType) ;
01130 string testSummary;
01131 string runID = names->getRunID();
01132 string moduleID = names->getModuleID();
01133 string filename = names->getfilename();
01134
01135
01136
01137
01138
01139
01140
01141 TFile *inspect_file = new TFile(filename.c_str(),"read");
01142 if (inspect_file->IsZombie() == true) {
01143 cout << "Problem in opening file..."<<endl;
01144 cout << "Such Run Number does NOT exist"<<endl;
01145 cout << "exiting getData..."<<endl;
01146 return 0;
01147 }
01148 cout<<" File found!!"<<endl;
01149
01150
01151
01152 TDirectory *this_run = (TDirectory*) gDirectory->Get(runID.c_str());
01153 cout<<"The RUN is "<< runID <<endl;
01154 if (!this_run) {
01155 cout<<"This Run " << runID << " deos NOT exist in file "<< filename <<endl;
01156 return 0;
01157 }
01158
01159 this_run->cd();
01160 cout<<" Run Number found!!"<<endl;
01161
01162
01163
01164 TDirectory* this_module = (TDirectory*) gDirectory->Get(moduleID.c_str());
01165 cout<<"The MODULE is "<< moduleID <<endl;
01166 if (!this_module) {
01167 cout<<"This Module "<< moduleID <<" does NOT exist with this Run Number"<<endl;
01168 return 0;
01169 }
01170 this_module->cd();
01171 cout<<" Module Name found!!"<<endl;
01172
01173
01174
01175 TDirectory* this_testType = (TDirectory*) gDirectory->Get(testType.c_str());
01176 cout<<"The Test is "<< testType <<endl;
01177 if (!this_testType) {
01178 cout<<"This Test "<< testType <<" does NOT exist with this Run Number and Module name"<<endl;
01179 return 0;
01180 }
01181 this_testType->cd();
01182 cout<<" Test Name found!!"<<endl;
01183
01184
01185
01186
01187 TObject* pers_testSummary = gDirectory->FindObjectAny(names->getTestSummaryID().c_str());
01188 if (!pers_testSummary) {
01189 cout<<"TestSummary NEVER SAVED!!!!"<<endl;
01190 return 0;
01191 }
01192 TObjString* tmp_testSummary = dynamic_cast<TObjString*>(pers_testSummary);
01193 testSummary = tmp_testSummary->GetString().Data();
01194
01195
01196 return testSummary;
01197
01198
01199 }
01200
01201
01202
01203
01204
01205 string Archiving::getTestSummaryFromArchive(string runID, string moduleID, string testType) {
01206
01207
01208 ArchTestNames* names;
01209
01210 string testSummary;
01211 string filename = runID + ".root";
01212
01213
01214
01215
01216
01217
01218
01219
01220 TFile *inspect_file = new TFile(filename.c_str(),"read");
01221 if (inspect_file->IsZombie() == true) {
01222 cout << "Problem in opening file..."<<endl;
01223 cout << "Such Run Number does NOT exist"<<endl;
01224 cout << "exiting getData..."<<endl;
01225 return 0;
01226 }
01227 cout<<" File found!!"<<endl;
01228
01229
01230
01231 TDirectory *this_run = (TDirectory*) gDirectory->Get(runID.c_str());
01232 cout<<"The RUN is "<< runID <<endl;
01233 if (!this_run) {
01234 cout<<"This Run " << runID << " deos NOT exist in file "<< filename <<endl;
01235 return 0;
01236 }
01237
01238 this_run->cd();
01239 cout<<" Run Number found!!"<<endl;
01240
01241
01242
01243 TDirectory* this_module = (TDirectory*) gDirectory->Get(moduleID.c_str());
01244 cout<<"The MODULE is "<< moduleID <<endl;
01245 if (!this_module) {
01246 cout<<"This Module "<< moduleID <<" does NOT exist with this Run Number"<<endl;
01247 return 0;
01248 }
01249 this_module->cd();
01250 cout<<" Module Name found!!"<<endl;
01251
01252
01253
01254 TDirectory* this_testType = (TDirectory*) gDirectory->Get(testType.c_str());
01255 cout<<"The Test is "<< testType <<endl;
01256 if (!this_testType) {
01257 cout<<"This Test "<< testType <<" does NOT exist with this Run Number and Module name"<<endl;
01258 return 0;
01259 }
01260 this_testType->cd();
01261 cout<<" Test Name found!!"<<endl;
01262
01263
01264
01265
01266 TObject* pers_testSummary = gDirectory->FindObjectAny(names->getTestSummaryID().c_str());
01267 if (!pers_testSummary) {
01268 cout<<"TestSummary NEVER SAVED!!!!"<<endl;
01269 return 0;
01270 }
01271
01272 TObjString* tmp_testSummary = dynamic_cast<TObjString*>(pers_testSummary);
01273 testSummary = tmp_testSummary->GetString().Data();
01274
01275
01276 return testSummary;
01277
01278
01279 }