Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

/Go4Example2Step/TXXXAnalysis.cxx

Go to the documentation of this file.
00001 //---------------------------------------------------------------
00002 //        Go4 Release Package v2.10-5 (build 21005) 
00003 //                      03-Nov-2005
00004 //---------------------------------------------------------------
00005 //       The GSI Online Offline Object Oriented (Go4) Project
00006 //       Experiment Data Processing at DVEE department, GSI
00007 //---------------------------------------------------------------
00008 //
00009 //Copyright (C) 2000- Gesellschaft f. Schwerionenforschung, GSI
00010 //                    Planckstr. 1, 64291 Darmstadt, Germany
00011 //Contact:            http://go4.gsi.de
00012 //----------------------------------------------------------------
00013 //This software can be used under the license agreements as stated
00014 //in Go4License.txt file which is part of the distribution.
00015 //----------------------------------------------------------------
00016 #include "TXXXAnalysis.h"
00017 
00018 #include <iostream.h>
00019 #include <time.h>
00020 
00021 #include "Go4Fit/TGo4Fitter.h"
00022 #include "MbsAPI/s_filhe_swap.h"
00023 #include "MbsAPI/s_bufhe_swap.h"
00024 
00025 //***********************************************************
00026 TXXXAnalysis::TXXXAnalysis()
00027 : fUserFile(0),fMbsEvent(0),fRawEvent(0),fCalEvent(0)
00028 {
00029   cout << "Wrong constructor TXXXAnalysis()!" << endl;
00030 }
00031 //***********************************************************
00032 // this constructor is used
00033 TXXXAnalysis::TXXXAnalysis(Text_t * input, Int_t type, Int_t port, Text_t * out1, Text_t * out2, Bool_t enable1, Bool_t enable2)
00034   : fUserFile(0),
00035     fMbsEvent(0),
00036     fRawEvent(0),
00037     fCalEvent(0),
00038     fSize(0),
00039     fEvents(0),
00040     fLastEvent(0)
00041 {
00042 // input: input file name (*.lmd)
00043 // out1:  output file name of first analysis step  (*.root)
00044 // out2:  output file name of second analysis step (*.root)
00045   cout << "**** TXXXAnalysis: Create" << endl;
00046 
00047 // the step definitions can be changed in the GUI
00048 // first step definitions:
00049 // the name of the step can be used later to get event objects
00050 // all these parameter objects will be used for the different MBS inputs
00051   TGo4MbsFileParameter*        mbsfile;
00052   TGo4MbsTransportParameter*   mbstrans;
00053   TGo4MbsStreamParameter*      mbsstream;
00054   TGo4RevServParameter*        mbsrev;
00055   TGo4MbsEventServerParameter* mbsevent;
00056   TGo4MbsRandomParameter*      mbsrandom;
00057   TGo4FileStoreParameter*      store1;
00058   TXXXUnpackFact*              factory1;
00059   TGo4AnalysisStep*            step1;
00060   TGo4FileSourceParameter*     source2;
00061   TGo4FileStoreParameter*      store2;
00062   TXXXAnlFact*                 factory2;
00063   TGo4AnalysisStep*            step2;
00064 
00065   factory1 = new TXXXUnpackFact("UnpackFactory");
00066   store1   = new TGo4FileStoreParameter(out1);
00067   switch (type){
00068     case GO4EV_MBS_FILE:
00069        mbsfile   = new TGo4MbsFileParameter(input);
00070        step1     = new TGo4AnalysisStep("Unpack",factory1,mbsfile,store1,0);
00071        cout << "**** Unpack: Create file input " << input << endl;
00072        break;
00073     case GO4EV_MBS_STREAM:
00074        mbsstream = new TGo4MbsStreamParameter(input);
00075        step1     = new TGo4AnalysisStep("Unpack",factory1,mbsstream,store1,0);
00076        cout << "**** Unpack: Create stream input "  << input << endl;
00077        break;
00078     case GO4EV_MBS_TRANSPORT:
00079        mbstrans  = new TGo4MbsTransportParameter(input);
00080        step1     = new TGo4AnalysisStep("Unpack",factory1,mbstrans,store1,0);
00081        cout << "**** Unpack: Create transport input " << input  << endl;
00082        break;
00083     case GO4EV_MBS_REVSERV:
00084        mbsrev    = new TGo4RevServParameter(input);
00085        mbsrev->SetPort(port);
00086        step1     = new TGo4AnalysisStep("Unpack",factory1,mbsrev,store1,0);
00087        cout << "**** Unpack: Create remote event server input " << input << " port " << port <<endl;
00088        break;
00089     case GO4EV_MBS_EVENTSERVER:
00090        mbsevent  = new TGo4MbsEventServerParameter(input);
00091        step1     = new TGo4AnalysisStep("Unpack",factory1,mbsevent,store1,0);
00092        cout << "**** Unpack: Create mbs event server input "  << input << endl;
00093        break;
00094     case GO4EV_MBS_RANDOM:
00095        mbsrandom = new TGo4MbsRandomParameter(input);
00096        step1     = new TGo4AnalysisStep("Unpack",factory1,mbsrandom,store1,0);
00097        cout << "**** Unpack: Create mbs random input "  << input << endl;
00098        break;
00099     default:
00100        step1     = 0;
00101        break;
00102   }
00103   AddAnalysisStep(step1);
00104 
00105   store1->SetOverwriteMode(kTRUE); // overwrite file
00106   step1->SetSourceEnabled(kTRUE);
00107   step1->SetStoreEnabled(enable1);
00108   step1->SetProcessEnabled(kTRUE);
00109   step1->SetErrorStopEnabled(kTRUE);
00110 
00111 // second step definitions:
00112 // If source is enabled, take output file from step 1 as input.
00113 // otherwise we use output event from step 1 (set in factory)
00114   factory2 = new TXXXAnlFact("AnalysisFactory");
00115   source2  = new TGo4FileSourceParameter(out1);
00116   store2   = new TGo4FileStoreParameter(out2);
00117   step2    = new TGo4AnalysisStep("Analysis",factory2,source2,store2,0);
00118   store2->SetOverwriteMode(kTRUE);
00119   step2->SetSourceEnabled(kFALSE);  // disable file input (output file of step 1)
00120   step2->SetStoreEnabled(enable2);
00121   step2->SetProcessEnabled(kTRUE);
00122   step2->SetErrorStopEnabled(kTRUE);
00123   AddAnalysisStep(step2);
00124 
00125 
00127   // At this point, autosave file has not yet been read!
00128   // Therefore parameter values set here will be overwritten
00129   // if an autosave file is there.
00130       fPar = new TXXXParameter("XXXPar1");
00131       fPar->frP1 = 100;
00132       fPar->frP2 = 200;
00133       AddParameter(fPar);
00134       fPar = new TXXXParameter("XXXPar2");
00135       fPar->frP1 = 1000;
00136       fPar->frP2 = 2000;
00137       AddParameter(fPar);
00138 
00139 
00140 }
00141 
00142 //***********************************************************
00143 TXXXAnalysis::~TXXXAnalysis()
00144 {
00145   cout << "**** TXXXAnalysis: Delete" << endl;
00146 }
00147 //***********************************************************
00148 
00149 //-----------------------------------------------------------
00150 Int_t TXXXAnalysis::UserPreLoop()
00151 {
00152   cout << "**** TXXXAnalysis: PreLoop" << endl;
00153    // we update the pointers to the current event structures here:
00154    fMbsEvent = dynamic_cast<TGo4MbsEvent*>    (GetInputEvent("Unpack"));   // of step "Unpack"
00155    fRawEvent = dynamic_cast<TXXXUnpackEvent*> (GetOutputEvent("Unpack"));
00156    fCalEvent = dynamic_cast<TXXXAnlEvent*>    (GetOutputEvent("Analysis"));
00157    fEvents=0;
00158    fLastEvent=0;
00159 
00160 
00161 
00162    // create histogram for UserEventFunc
00163    // At this point, the histogram has been restored from autosave file if any.
00164   fSize=(TH1D*)GetHistogram("Eventsize");
00165   if(fSize==0)
00166     { // no autosave read, create new and register
00167       fSize = new TH1D ("Eventsize", "Event size [b]",160,1,160);
00168       AddHistogram(fSize);
00169     }
00170   // we use a fitter envelope parameters to exchange fit results:
00171   fFitEnvSize=(TGo4FitterEnvelope*) GetParameter("sizefitter");
00172   if(fFitEnvSize==0)
00173    {
00174      TGo4Fitter* fitter=new TGo4Fitter("Gaussfit", TGo4Fitter::ff_ML_Poisson, kTRUE);;
00175       // add histogram to fitter, which should be fitted
00176       fitter->AddH1("data1", fSize, kFALSE);
00177       // create polynom of first order
00178       //fitter->AddPolynomX("data1", "Pol", 1);
00179       // create gaussian
00180       fitter->AddGauss1("data1", "Gauss1",15,5,1000);
00181       fFitEnvSize=new TGo4FitterEnvelope("sizefitter",fitter);
00182       AddParameter(fFitEnvSize);
00183    }
00184    fFitEnvSpectrum=(TGo4FitterEnvelope*) GetParameter("specfitter");
00185    if(fFitEnvSpectrum==0)
00186    {
00187      TGo4Fitter* fitter=new TGo4Fitter("Multilines", TGo4Fitter::ff_ML_Poisson, kTRUE);;
00188       // add histogram to fitter, which should be fitted
00189       fitter->AddH1("spectrum", fSize, kFALSE);
00190       // create polynom of first order
00191       fitter->AddPolynomX("spectrum", "Pol", 1);
00192       // create gaussian
00193       fitter->AddGauss1("spectrum", "Gauss1",500,20,1000);
00194       fFitEnvSpectrum=new TGo4FitterEnvelope("specfitter",fitter);
00195       AddParameter(fFitEnvSpectrum);
00196    }
00197 
00198    return 0;
00199 }
00200 //-----------------------------------------------------------
00201 Int_t TXXXAnalysis::UserPostLoop()
00202 {
00203   cout << "**** TXXXAnalysis: PostLoop" << endl;
00204   cout << "Last event: " << fLastEvent << " Total events: " << fEvents << endl;
00205   if(fMbsEvent)
00206     {
00207       // we can check some properties of last event here:
00208       //fMbsEvent->PrintEvent(); // header and data content
00209 
00210       // fileheader structure:
00211       s_filhe* fileheader=fMbsEvent->GetMbsSourceHeader();
00212       if(fileheader)
00213          {
00214            cout <<"\nInput file was: "<<fileheader->filhe_file << endl;
00215            cout <<"Tapelabel:\t" << fileheader->filhe_label<<endl;
00216            cout <<"UserName:\t" << fileheader->filhe_user<<endl;
00217            cout <<"RunID:\t" << fileheader->filhe_run<<endl;
00218            cout <<"\tExplanation: "<<fileheader->filhe_exp <<endl;
00219            cout <<"\tComments: "<<endl;
00220            Int_t numlines=fileheader->filhe_lines;
00221            for(Int_t i=0; i<numlines;++i)
00222             {
00223                cout<<"\t\t"<<fileheader->s_strings[i].string << endl;
00224             }
00225          }
00226 
00227       // mbs buffer header structure:
00228       s_bufhe* bufheader=fMbsEvent->GetMbsBufferHeader();
00229       if(bufheader)
00230          {
00231             cout <<"Last Buffer:"<<endl;
00232             cout <<"\tNumber: "<<bufheader->l_buf << endl;
00233             cout <<"\tTime: "<<ctime((const time_t*) &(bufheader->l_time[0]));
00234             cout << "\t\t\t + "<<bufheader->l_time[1] << " µs"<<endl;
00235          }
00236 
00237 
00238     }
00239 
00241 // Uncomment this if you want to perform a fit
00242 // each time analysis stops:
00244 //  if(fFitEnvSize)
00245 //     {
00246 //         cout <<"Fitting event size..." << endl;
00247 //         TGo4Fitter* fitter=fFitEnvSize->GetFitter();
00248 //         if(fitter)
00249 //         {
00250 //            //cout <<"Fitter setting histogram and fitting..." << endl;
00251 //            fitter->SetObject("data1", fSize, kFALSE);
00252 //            fitter->DoActions();
00253 //            fitter->PrintLines();
00254 //         }
00255 //     }
00257 // second fitter:
00258 //   if(fFitEnvSpectrum)
00259 //     {
00260 //         cout <<"Fitting sum spectrum..." << endl;
00261 //         TGo4Fitter* fitter=fFitEnvSpectrum->GetFitter();
00262 //         if(fitter)
00263 //         {
00264 //            //cout <<"Fitter setting histogram and fitting..." << endl;
00265 //            TH1* his=GetHistogram("Sum2");
00266 //            fitter->SetObject("spectrum", his, kFALSE);
00267 //            fitter->DoActions();
00268 //            fitter->PrintLines();
00269 //         }
00270 //     }
00272 
00273 
00276 //   cout <<"Storing parameter fPar to Unpack:" << endl;
00277 //   StoreParameter("Unpack",fPar);
00278 //   cout <<"Storing parameter fPar to Analysis:" << endl;
00279 //   StoreParameter("Analysis",fPar);
00280 //   if(fFitEnvSpectrum)
00281 //     {
00282 //         cout <<"Storing fitter"<<fFitEnvSpectrum->GetName() <<" to analysis" << endl;
00283 //         TGo4Fitter* fitter=fFitEnvSpectrum->GetFitter();
00284 //         StoreFitter("Analysis",fitter);
00285 //     }
00286 //
00287 //   TGo4Condition* winar=GetAnalysisCondition("winconar");
00288 //   if(winar)
00289 //      {
00290 //         cout <<"Storing condition"<< winar->GetName()<<"to analysis" << endl;
00291 //         StoreCondition("Analysis",winar);
00292 //      }
00293 //   cout <<"Storing all conditions to unpack." << endl;
00294 //   StoreFolder("Unpack","Conditions");
00296 
00297    fMbsEvent = 0; // reset to avoid invalid pointer if analysis is changed in between
00298    fRawEvent = 0;
00299    fCalEvent = 0;
00300    fEvents=0;
00301    return 0;
00302 }
00303 
00304 //-----------------------------------------------------------
00305 Int_t TXXXAnalysis::UserEventFunc()
00306 {
00308    Int_t value = 0;
00309    Int_t count = 0;
00310    if(fMbsEvent) value = fMbsEvent->GetDlen()/2+2; // total longwords
00311    fSize->Fill(value); // fill histogram
00312    fEvents++;
00313    if(fEvents == 1 || IsNewInputFile()) {
00314       if(fMbsEvent) {
00315          count=fMbsEvent->GetCount();
00316          cout << "\nFirst event #: " << count  << endl;
00317          s_bufhe* bufheader=fMbsEvent->GetMbsBufferHeader();
00318          if(bufheader) {
00319             cout <<"First Buffer:"<<endl;
00320             cout <<"\tNumber: "<<bufheader->l_buf << endl;
00321             cout <<"\tTime: "<<ctime((const time_t*) &(bufheader->l_time[0]));
00322             cout << "\t\t\t + "<<bufheader->l_time[1] << " µs"<<endl;
00323          }
00324       }
00325       SetNewInputFile(kFALSE); // we have to reset the newfile flag
00326    }
00327    fLastEvent = count;
00328    return 0;
00329 }
00330 //-----------------------------------------------------------
00331 
00332 ClassImp(TXXXAnalysis)
00333 
00334 
00335 
00336 
00337 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Tue Nov 8 10:55:54 2005 for Go4-v2.10-5 by doxygen1.2.15