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

ArchNPtGainTestResult.cpp

00001 #include "ArchNPtGainTestResult.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 "SctData/ResponseCurve.h"
00025 
00026 using namespace SctData;
00027 
00028 
00029 bool ArchNPtGainTestResult::inMap = ArchivingManager::instance().addTestArchiver("SctData::NPtGainTestResult", shared_ptr<ArchTestResult>(new ArchNPtGainTestResult()));  
00030 
00031 
00032 /***********************  Constructor  *************** */
00033 
00034 ArchNPtGainTestResult::ArchNPtGainTestResult(): ArchTestResult()  {
00035 
00036   //cout<< "I am in the ArchNPtGainTestResult Default Constructor"<< endl;
00037   
00038   
00039   
00040 }
00041   
00042   
00043 ArchNPtGainTestResult::ArchNPtGainTestResult(shared_ptr<NPtGainTestResult> NPtGtest): ArchTestResult(NPtGtest)  {
00044 
00045   //cout<< "I am in the ArchNPtGainTestResult Constructor"<< endl;
00046   
00047   /*--- Initialisation ---*/
00048   NChipData = NPtGtest->getNChipData();
00049   NChannelData = NPtGtest->getNChannelData();
00050 
00051   
00052   for (unsigned int i = 0; i<NChipData;i++) {
00053    chipData.push_back(&NPtGtest->getChipData(i));
00054    //cout<<"I chip = " <<i <<endl;
00055   }
00056 
00057   for (unsigned int i = 0; i<NChannelData;i++) { 
00058    channelData.push_back(&NPtGtest->getChannelData(i));
00059    // cout<<"I channel = " <<endl;
00060   }
00061 
00062   
00063   /* Initialisattion of Chip Data */
00064   vector<const NPtGainTestResultData*>::iterator icf = chipData.begin();
00065   while( icf != chipData.end() ) {
00066     Chipfit.push_back((*icf)->rc->getFunction());
00067     ++icf;
00068   } 
00069   
00070 
00071   vector<const NPtGainTestResultData*>::iterator icg = chipData.begin();
00072   while( icg != chipData.end() ) {
00073     ChipGraph.push_back((*icg)->graph);
00074     ++icg;
00075   } 
00076 
00077   
00078   //Storing Chip TVectorD's  
00079   double g[NChipData];
00080   unsigned int Ig=0;
00081   vector<const NPtGainTestResultData*>::iterator icgain = chipData.begin();
00082   while( icgain != chipData.end() ) {
00083     g[Ig] = (*icgain)->gain ;
00084     ++Ig;
00085     ++icgain;
00086   }
00087   vChipGain = new TVectorD(NChipData,g);
00088 
00089   
00090   double n[NChipData];
00091   unsigned int In=0;
00092   vector<const NPtGainTestResultData*>::iterator icnoise = chipData.begin();
00093   while( icnoise != chipData.end() ) {
00094     n[In] = (*icnoise)->noise ;
00095     ++In;
00096     ++icnoise;
00097   }
00098   vChipNoise = new TVectorD(NChipData,n);
00099 
00100   
00101   double o[NChipData];
00102   unsigned int Io=0;
00103   vector<const NPtGainTestResultData*>::iterator icoffset = chipData.begin();
00104   while( icnoise != chipData.end() ) {
00105     o[Io] = (*icoffset)->noise ;
00106     ++Io;
00107     ++icoffset;
00108   }
00109   vChipOffset = new TVectorD(NChipData,o);
00110 
00111 
00112 
00113   /* Initialisation of Channel Data */
00114   vector<const NPtGainTestResultData*>::iterator ichnf = channelData.begin();
00115   while( ichnf != channelData.end() ) {
00116     Channelfit.push_back((*ichnf)->rc->getFunction());
00117     ++ichnf;
00118   } 
00119   
00120 
00121   vector<const NPtGainTestResultData*>::iterator ichng = channelData.begin();
00122   while( ichng != channelData.end() ) {
00123     ChannelGraph.push_back((*ichng)->graph);
00124     ++ichng;
00125   } 
00126 
00127   
00128  
00129   /*Storing Channel TVectorD's  */
00130   double chng[NChannelData];
00131   unsigned int Ichng=0;
00132   vector<const NPtGainTestResultData*>::iterator ichngain = channelData.begin();
00133   while( ichngain != channelData.end() ) {
00134     chng[Ichng] = (*ichngain)->gain ;
00135     ++Ichng;
00136     ++ichngain;
00137   }
00138   vChannelGain = new TVectorD(NChannelData,chng);
00139 
00140   double chnn[NChannelData];
00141   unsigned int Ichnn=0;
00142   vector<const NPtGainTestResultData*>::iterator ichnnoise = channelData.begin();
00143   while( ichnnoise != channelData.end() ) {
00144     chnn[Ichnn] = (*ichnnoise)->noise ;
00145     ++Ichnn;
00146     ++ichnnoise;
00147   }
00148   vChannelNoise = new TVectorD(NChannelData,chnn);
00149 
00150   double chno[NChannelData];
00151   unsigned int Ichno=0;
00152   vector<const NPtGainTestResultData*>::iterator ichnoffset = channelData.begin();
00153   while( ichnnoise != channelData.end() ) {
00154     chno[Ichno] = (*ichnoffset)->noise ;
00155     ++Ichno;
00156     ++ichnoffset;
00157   }
00158   vChannelOffset = new TVectorD(NChannelData,chno);
00159 
00160 
00161 
00162   //Retrieve Test Summary from IS
00163   //cout <<" About to retrieve Test Summary " << endl;
00164   try{
00165     TestSummary(NPtGtest);
00166   } catch(...) {
00167     cout<<" ERROR in retrieving Test Summary from IS" <<endl;
00168   }
00169   
00170 
00171 
00172 
00173 }
00174 
00175 
00176 
00177 
00178 
00179 
00180 
00181 /**********************  Other Member Functions  *********************/
00182 
00183 ArchNPtGainTestResult::~ArchNPtGainTestResult()  {
00184   
00185   //cout << "I am in the  ArchNPtGainTestResult destructor" << endl;
00186   
00187 
00188   
00189 }
00190 
00191 
00192 
00193 
00194 
00195 void ArchNPtGainTestResult::SaveNPtGainTestDataOnly() {
00196 
00197   cout<<"Saving NPtGainTestData "<<endl;
00198   //TO DO : Save time and date of first and last saving  
00199   
00200   string filename = names->getfilename();
00201   string moduleID = names->getModuleID(); 
00202   string testType  = names->getTestType(); 
00203   string runID = names->getRunID();
00204   string ChipDataID = names->getChipDataID();
00205   string vChipGainID = names->getChipGainID();
00206   string vChipNoiseID = names->getChipNoiseID();
00207   string vChipOffsetID = names->getChipOffsetID();
00208   string ChannelDataID = names->getChannelDataID();
00209   string vChannelGainID = names->getChannelGainID();
00210   string vChannelNoiseID = names->getChannelNoiseID();
00211   string vChannelOffsetID = names->getChannelOffsetID();
00212 
00213 
00214   /* OPENING TEST FILE  */
00215   //cout << "Opening file..."<<endl; 
00216  
00217 
00218   TFile *storage_file = new TFile(filename.c_str(),"update");
00219   //storage_file->ls();
00220   //cout << "The file .root succesfully open"<<endl; 
00221 
00222   
00223 
00224 
00225   /* CREATING DIRECTORIES and SAVING DATA  */
00226   
00227     
00228     /* Making RunNumber   */
00229     //cout<<"I am making RunNumber Dir"<<endl;
00230     //storage_file->GetListOfKeys()->Print();
00231     TDirectory *this_run = (TDirectory*) gDirectory->Get(runID.c_str());
00232     //cout<<"The RUN is "<< runID <<endl;
00233     
00234     if (!this_run) {
00235       //cout<<"This NEW run "<< runID <<" doesn't exist"<<endl;
00236       this_run = storage_file->mkdir(runID.c_str());
00237       //cout<<"New RunNumber Dir made "<<endl;
00238     }
00239     storage_file->GetListOfKeys()->Print();
00240     this_run->cd();  //make this_run the current directory
00241     
00242    
00243     /* Saving RunNumber as a TVector: it is saved only once, just the first time   */
00244     TObject* pers_runnumber = gDirectory->FindObjectAny(runID.c_str()); 
00245     if (!pers_runnumber) {
00246       double frunNumber = runNumber;
00247       TVector run(1,1,frunNumber, "END");
00248       run.Write(runID.c_str());
00249     }
00250     
00251     
00252     /* Making moduleNumber   */
00253     
00254     TDirectory* this_module = (TDirectory*) gDirectory->Get(moduleID.c_str()); //Can be made using FindAnyObject
00255     //cout<<"The MODULE is "<< moduleID <<endl;
00256     if (!this_module) {
00257       //cout<<"This NEW module "<< moduleID <<" doesn't exist"<<endl;
00258       this_module =gDirectory ->mkdir(moduleID.c_str());
00259     }
00260     
00261     
00262     /* Making TestType   */
00263     //cout<<"I am making TestType Dir "<<endl;
00264     this_module->cd();  //make this_module the current directory 
00265     TDirectory* this_testType = (TDirectory*) gDirectory->Get(testType.c_str());
00266     //cout<<"The test Type is "<< testType <<endl;
00267     
00268     if (!this_testType) {
00269       //cout<<"This NEW test "<< testType <<" doesn't exist"<<endl;
00270       this_testType = gDirectory->mkdir(testType.c_str());
00271     }
00272     this_testType->cd();
00273 
00274     
00275     /* making ChipData dir */
00276     TDirectory* this_ChipData = (TDirectory*) this_testType->Get(ChipDataID.c_str());
00277     if (!this_ChipData) {
00278       //cout<<"This NEW ChipData dir  doesn't exist"<<endl;
00279       this_ChipData = this_testType->mkdir(ChipDataID.c_str());
00280     }
00281     this_ChipData->cd();
00282 
00283     /* Saving ChipData */
00284     int chipN=0;
00285     for (vector<shared_ptr<TF1> >::iterator i = Chipfit.begin(); i!=Chipfit.end(); i++) {
00286       (*i)->Write(names->getChipFitID(chipN).c_str());
00287       ++chipN;
00288     } 
00289     chipN=0;
00290     for (vector<shared_ptr<TGraph> >::iterator i = ChipGraph.begin(); i!=ChipGraph.end(); i++) {
00291       (*i)->Write(names->getChipGraphID(chipN).c_str());
00292       ++chipN;
00293     }
00294 
00295     vChipGain->Write(vChipGainID.c_str());
00296     vChipNoise->Write(vChipNoiseID.c_str());
00297     vChipOffset->Write(vChipOffsetID.c_str()); 
00298    
00299     
00300     /* making ChannelData dir */
00301     TDirectory* this_ChannelData = (TDirectory*) this_testType->Get(ChannelDataID.c_str());
00302     if (!this_ChannelData) {
00303       //cout<<"This NEW ChannelData dir  doesn't exist"<<endl;
00304       this_ChannelData = this_testType->mkdir(ChannelDataID.c_str());
00305     }
00306     this_ChannelData->cd();
00307 
00308     /* Saving ChannelData */
00309     int channelN=0;
00310     for (vector<shared_ptr<TF1> >::iterator i = Channelfit.begin(); i!=Channelfit.end(); i++) {
00311       (*i)->Write(names->getChannelFitID(channelN).c_str());
00312       ++channelN;
00313     }
00314     channelN=0;
00315     for (vector<shared_ptr<TGraph> >::iterator i = ChannelGraph.begin(); i!=ChannelGraph.end(); i++) {
00316       (*i)->Write(names->getChannelGraphID(channelN).c_str());
00317        ++channelN;
00318     }
00319     //cout<<" I am here "<<endl;
00320     vChannelGain->Write(vChannelGainID.c_str());
00321     //cout<<" I am here "<<endl;
00322     vChannelNoise->Write(vChannelNoiseID.c_str());
00323     //cout<<" I am here "<<endl;
00324     vChannelOffset->Write(vChannelOffsetID.c_str()); 
00325     //cout<<" I am here "<<endl;
00326 
00327     //Save TestSummery (if it has been retrieved)
00328     if(testSummary != NULL) { 
00329       this_testType->cd();
00330       //cout<<"testSummary != NULL...";
00331       TObject* pers_testSummary = gDirectory->FindObjectAny(names->getTestSummaryID().c_str());
00332       if (!pers_testSummary) {
00333     testSummary->Write(names->getTestSummaryID().c_str());
00334     //cout<<"testSummary SAVED"<<endl;
00335       }
00336     }
00337    
00338 
00339 
00340     
00341     /* CLOSING FILE  */
00342     //cout << "I am Closing File " << endl;
00343     storage_file->Close();
00344     delete storage_file;
00345     //cout << "File closed " << endl;
00346 
00347 
00348    
00349 
00350 
00351 }
00352 
00353 
00354 
00355 void ArchNPtGainTestResult::Save() {
00356 
00357   ArchTestResult::Save();
00358   SaveNPtGainTestDataOnly();
00359   //SaveRawScans();
00360   //SaveFitScans();
00361   AddTestToIndex();
00362 
00363 }
00364 
00365 
00366 
00367 
00368 
00369 void ArchNPtGainTestResult::TestSummary(shared_ptr<NPtGainTestResult> NPtGtest) {
00370   
00371   ostringstream datastream;
00372   shared_ptr<const SctData::TestSummary::SummaryWriter> writer = 
00373     SctData::TestSummary::SummaryManager::instance().getWriter(NPtGtest->getClassName());
00374   writer->writeHeader(*(NPtGtest.get()), datastream);
00375   writer->write(*(NPtGtest.get()), datastream);
00376   string myString = datastream.str();
00377   //cout<< "TestSummary = " << myString;
00378 
00379   testSummary = new TObjString(myString.c_str());
00380 
00381   
00382 
00383 
00384   return;
00385 
00386 
00387 }

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