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

Archiving.cpp

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

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