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

ArchNoiseOccupancyTestResult.cpp

00001 #include "ArchNoiseOccupancyTestResult.h"
00002 #include "ArchivingManager.h"
00003 #include <TFile.h>
00004 #include <TKey.h>
00005 #include <TDirectory.h>
00006 #include <TSystem.h>
00007 #include <TNamed.h>
00008 #include <TObject.h>
00009 #include <TObjArray.h>
00010 #include <TString.h>
00011 #include <TObjString.h>
00012 #include <TVector.h>
00013 #include <TVectorD.h>
00014 #include <TH1.h>
00015 #include <TH2.h>
00016 #include <TCanvas.h>
00017 #include <TROOT.h>
00018 #include <is/isinfo.h>
00019 #include <iostream>
00020 #include <vector>
00021 #include "SummaryWriter/SummaryWriter.h"
00022 #include "SummaryWriter/SummaryManager.h"
00023 
00024 #include "Sct/SctParameters.h"
00025 
00026 using namespace Sct;
00027 using namespace SctData;
00028 
00029 
00030 /********************************** ArchScan Methods Definitions ************************/
00031 bool ArchNoiseOccupancyTestResult::inMap = ArchivingManager::instance().addTestArchiver("SctData::NoiseOccupancyTestResult", shared_ptr<ArchTestResult>(new ArchNoiseOccupancyTestResult()));  
00032 
00033 
00034 /***********************  Constructor  *************** */
00035 
00036 ArchNoiseOccupancyTestResult::ArchNoiseOccupancyTestResult(): ArchTestResult()  {
00037 
00038   //cout<< "I am in the ArchNoiseOccupancyTestResult Default Constructor"<< endl;
00039   
00040   
00041   
00042 }
00043   
00044   
00045 ArchNoiseOccupancyTestResult::ArchNoiseOccupancyTestResult(shared_ptr<NoiseOccupancyTestResult> NOtest): ArchTestResult(NOtest)  {
00046 
00047   //cout<< "I am in the ArchNoiseOccupancyTestResult Constructor"<< endl;
00048   
00049   //Save chipNoise as TVectorD's  
00050   double x[nChipModule];
00051 
00052   /*--- Initialisation ---*/
00053   for (unsigned int i = 0; i<nChipModule;i++) { 
00054     ChipNOResult& result = NOtest->getChipResult(i);
00055     chipNOGraph.push_back(result.graph.get());
00056     chipNOFit.push_back(result.fit.get());    
00057     x[i] = result.getNoise() ;
00058   }
00059 
00060   vchipNoise = new TVectorD(12 ,x);
00061 
00062   
00063   //Retrieve Test Summary from IS
00064   try{
00065     TestSummary(NOtest);
00066   } catch(...) {
00067     cout<<" ERROR in retrieving Test Summary from IS" <<endl;
00068   }
00069 
00070 
00071 }
00072 
00073 
00074 
00075 /**********************  Other Member Functions  *********************/
00076 
00077 ArchNoiseOccupancyTestResult::~ArchNoiseOccupancyTestResult()  {
00078   
00079   //cout << "I am in the destructor" << endl;
00080   
00081 
00082   
00083 }
00084 
00085 
00086 
00087 
00088 
00089 void ArchNoiseOccupancyTestResult::SaveNOTestDataOnly() {
00090 
00091   cout<<"Saving NoiseOccupancyTestData "<<endl;
00092      
00093 //TO DO : Save time and date of first and last saving  
00094   
00095   string filename = names->getfilename();
00096   string moduleID = names->getModuleID(); 
00097   string testType  = names->getTestType(); 
00098   string runID = names->getRunID();
00099   string vchipNoiseID = names->getChipNONoiseID();
00100   string chipNOFitID = names->getChipNOFitID();
00101   string chipNOGraphID = names->getChipNOGraphID();
00102 
00103   /* OPENING TEST FILE  */
00104   //cout << "Opening file..."<<endl; 
00105  
00106 
00107   TFile *storage_file = new TFile(filename.c_str(),"update");
00108   //storage_file->ls();
00109   //cout << "The file .root succesfully open"<<endl; 
00110 
00111   
00112 
00113 
00114   /* CREATING DIRECTORIES and SAVING DATA  */
00115   
00116     
00117     /* Making RunNumber   */
00118     //cout<<"I am making RunNumber Dir"<<endl;
00119     //storage_file->GetListOfKeys()->Print();
00120     TDirectory *this_run = (TDirectory*) gDirectory->Get(runID.c_str());
00121     //cout<<"The RUN is "<< runID <<endl;
00122     
00123     if (!this_run) {
00124       //cout<<"This NEW run "<< runID <<" doesn't exist"<<endl;
00125       this_run = storage_file->mkdir(runID.c_str());
00126       //cout<<"New RunNumber Dir made "<<endl;
00127     }
00128     storage_file->GetListOfKeys()->Print();
00129     this_run->cd();  //make this_run the current directory
00130     
00131    
00132     /* Saving RunNumber as a TVector: it is saved only once, just the first time   */
00133     TObject* pers_runnumber = gDirectory->FindObjectAny(runID.c_str()); 
00134     if (!pers_runnumber) {
00135       double frunNumber = runNumber;
00136       TVector run(1,1,frunNumber, "END");
00137       run.Write(runID.c_str());
00138     }
00139     
00140     
00141     /* Making moduleNumber   */
00142     
00143     TDirectory* this_module = (TDirectory*) gDirectory->Get(moduleID.c_str()); //Can be made using FindAnyObject
00144     //cout<<"The MODULE is "<< moduleID <<endl;
00145     if (!this_module) {
00146       //cout<<"This NEW module "<< moduleID <<" doesn't exist"<<endl;
00147       this_module =gDirectory ->mkdir(moduleID.c_str());
00148     }
00149     
00150 
00151     
00152     /* Making TestType   */
00153     //cout<<"I am making TestType Dir "<<endl;
00154     this_module->cd();  //make this_module the current directory 
00155     TDirectory* this_testType = (TDirectory*) gDirectory->Get(testType.c_str());
00156     //cout<<"The test Type is "<< testType <<endl;
00157     
00158     if (!this_testType) {
00159       //cout<<"This NEW test "<< testType <<" doesn't exist"<<endl;
00160       this_testType = gDirectory->mkdir(testType.c_str());
00161     }
00162     this_testType->cd();
00163 
00164 
00165     /* Saving chipNOFit */
00166     TDirectory* pers_ChipNOFit = (TDirectory*) gDirectory->Get(chipNOFitID.c_str());
00167     if (!pers_ChipNOFit) {
00168       //cout << "The ChipNOFit never saved before...saving now"<<endl;
00169       pers_ChipNOFit = this_testType->mkdir(chipNOFitID.c_str());
00170       
00171     }
00172     pers_ChipNOFit->cd();
00173 
00174     unsigned int chipN=0;
00175     for (vector<TF1*>::iterator i = chipNOFit.begin(); i!=chipNOFit.end(); i++) {
00176       (*i)->Write(names->getChipNOFitID(chipN).c_str());
00177       ++chipN;
00178     } 
00179     this_testType->cd();
00180 
00181 
00182     /* Saving chipNOGraph */
00183     TDirectory* pers_ChipNOGraph = (TDirectory*) gDirectory->Get(chipNOGraphID.c_str());
00184     if (!pers_ChipNOGraph) {
00185       //cout << "The ChipNOGraph never saved before...saving now"<<endl;
00186       pers_ChipNOGraph = this_testType->mkdir(chipNOGraphID.c_str());
00187       
00188     }
00189     pers_ChipNOGraph->cd();
00190     chipN=0;
00191     for (vector<TGraph*>::iterator i = chipNOGraph.begin(); i!=chipNOGraph.end(); i++) {
00192       (*i)->Write(names->getChipNOGraphID(chipN).c_str());
00193        ++chipN;
00194     }   
00195     this_testType->cd();
00196     
00197     /* Saving ChipNoise as a TVector: always saved!!  */
00198     //cout << "I am Saving ChipNoise as  TVectorD's" << endl;
00199     //TObject* pers_vchipNoise = gDirectory->FindObjectAny(vchipNoiseID.c_str()); 
00200     //if (!pers_vchipNoise) {
00201       //cout << "The ChipNoise never saved before...saving now"<<endl;
00202       vchipNoise->Write(vchipNoiseID.c_str());
00203       //}
00204     
00205 
00206     
00207     //Save TestSummery (if it has been retrieved)
00208     if(testSummary != NULL) {
00209       //cout<<"testSummary != NULL...";
00210       TObject* pers_testSummary = gDirectory->FindObjectAny(names->getTestSummaryID().c_str());
00211       if (!pers_testSummary) {
00212     testSummary->Write(names->getTestSummaryID().c_str());
00213     //cout<<"testSummary SAVED"<<endl;
00214       }
00215     }
00216 
00217     
00218     /* CLOSING FILE  */
00219     //cout << "I am Closing File " << endl;
00220     storage_file->Close();
00221     delete storage_file;
00222     //cout << "File closed " << endl;
00223 
00224 
00225 
00226 
00227 }
00228 
00229 
00230 
00231 void ArchNoiseOccupancyTestResult::Save() {
00232 
00233   //cout << "I am in SaveNoiseOccupancy() " <<endl;
00234   ArchTestResult::Save();
00235   SaveNOTestDataOnly();
00236   //SaveRawScans();
00237   //SaveFitScans();
00238   AddTestToIndex();
00239   
00240 
00241 
00242 
00243 
00244 
00245 }
00246 
00247 
00248 
00249 void ArchNoiseOccupancyTestResult::TestSummary(shared_ptr<NoiseOccupancyTestResult> NOtest) {
00250   
00251   ostringstream datastream;
00252   shared_ptr<const SctData::TestSummary::SummaryWriter> writer = 
00253     SctData::TestSummary::SummaryManager::instance().getWriter(NOtest->getClassName());
00254   writer->writeHeader(*(NOtest.get()), datastream);
00255   writer->write(*(NOtest.get()), datastream);
00256   string myString = datastream.str();
00257   //cout<< "TestSummary = " << myString;
00258 
00259   testSummary = new TObjString(myString.c_str());
00260 
00261   
00262 
00263 
00264   return;
00265 
00266 
00267 }
00268 

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