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

/Go4Example2Step/TXXXUnpackProc.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 "TXXXUnpackProc.h"
00017 
00018 #include <iostream.h>
00019 #include <time.h>
00020 
00021 #include "TXXXUnpackEvent.h"
00022 #include "MbsAPI/s_filhe_swap.h"
00023 #include "MbsAPI/s_bufhe_swap.h"
00024 
00025 //***********************************************************
00026 TXXXUnpackProc::TXXXUnpackProc()
00027   : TGo4EventProcessor("XXXProc")
00028 {
00029 }
00030 //***********************************************************
00031 // this one is used in TXXXUnpackFact.cxx
00032 TXXXUnpackProc::TXXXUnpackProc(Text_t * name)
00033   : TGo4EventProcessor(name)
00034 {
00035   cout << "**** TXXXUnpackProc: Create" << endl;
00036 
00037   Text_t chis[16];
00038   Text_t chead[64];
00039   Int_t i;
00040 
00042 
00043   fParam1   = (TXXXParameter *)   GetParameter("XXXPar1");
00044   fParam2   = (TXXXParameter *)   GetParameter("XXXPar2");
00045   fParam1->PrintParameter(0,0);
00046   fParam2->PrintParameter(0,0);
00047 
00048   // Creation of histograms:
00049   if(GetHistogram("Crate1/Cr1Ch01")==0)
00050     {
00051       for(i =0;i<8;i++)
00052    {
00053      snprintf(chis,15,"Cr1Ch%02d",i+1);
00054      snprintf(chead,63,"Crate 1 channel %2d",i+1);
00055           fCr1Ch[i] = new TH1I (chis,chead,5000,1,5000);
00056           AddHistogram(fCr1Ch[i],"Crate1");
00057      snprintf(chis,15,"Cr2Ch%02d",i+1);
00058      snprintf(chead,63,"Crate 2 channel %2d",i+1);
00059           fCr2Ch[i] = new TH1I (chis,chead,5000,1,5000);
00060           AddHistogram(fCr2Ch[i],"Crate2");
00061    }
00062       fCr1Ch1x2 = new TH2I("Cr1Ch1x2","Crate 1 channel 1x2",200,1,5000,200,1,5000);
00063       AddHistogram(fCr1Ch1x2);
00064       fHis1 = new TH1I ("His1","Condition histogram",5000,1,5000);
00065       AddHistogram(fHis1);
00066       fHis2 = new TH1I ("His2","Condition histogram",5000,1,5000);
00067       AddHistogram(fHis2);
00068       fHis1gate = new TH1I ("His1g","Gated histogram",5000,1,5000);
00069       AddHistogram(fHis1gate);
00070       fHis2gate = new TH1I ("His2g","Gated histogram",5000,1,5000);
00071       AddHistogram(fHis2gate);
00072     }
00073   else // got them from autosave file
00074     {
00075       for(i =0;i<8;i++)
00076    {
00077      snprintf(chis,15,"Crate1/Cr1Ch%02d",i+1);
00078           fCr1Ch[i]=(TH1I*)GetHistogram(chis);
00079      snprintf(chis,15,"Crate2/Cr2Ch%02d",i+1);
00080           fCr2Ch[i]=(TH1I*)GetHistogram(chis);
00081    }
00082       fCr1Ch1x2=(TH2I*)GetHistogram("Cr1Ch1x2");
00083       fHis1=(TH1I*)GetHistogram("His1");
00084       fHis2=(TH1I*)GetHistogram("His2");
00085       fHis1gate=(TH1I*)GetHistogram("His1g");
00086       fHis2gate=(TH1I*)GetHistogram("His2g");
00087       cout << "Unpack: Restored histograms from autosave" << endl;
00088     }
00089   // Creation of conditions:
00090   if(GetAnalysisCondition("wincon1")==0)
00091     {
00092       fWinCon1= new TGo4WinCond("wincon1");
00093       fWinCon1->SetValues(50,2000);
00094       fWinCon1->Disable(true); // return always true
00095 
00096       fWinCon2= new TGo4WinCond("wincon2");
00097       fWinCon2->SetValues(50,70,90,120);
00098       fWinCon2->Disable(true);
00099       fWinCon2->Invert(kTRUE);
00100 
00101       fconHis1= new TGo4WinCond("cHis1");
00102       fconHis2= new TGo4WinCond("cHis2");
00103       fconHis1->SetValues(100,2000);
00104       fconHis2->SetValues(100,2000);
00105 
00106       fConArr1= new TGo4CondArray("winconar",30,"TGo4WinCond");
00107       fConArr1->SetValues(100,500);
00108       fConArr1->Disable(true);
00109       ((*fConArr1)[0])->SetValues(200,400);
00110       ((*fConArr1)[1])->SetValues(700,1000);
00111       ((*fConArr1)[2])->SetValues(1500,2000);
00112       fConArr1->SetHistogram("Sum3");
00113 
00114       Double_t xvalues[4]={400,700,600,400};
00115       Double_t yvalues[4]={800,900,1100,800};
00116       TCutG* mycut= new TCutG("initialcut",4,xvalues,yvalues);
00117       fPolyCon1= new TGo4PolyCond("polycon");
00118       fPolyCon1->SetValues(mycut); // copies mycat into fPolyCon1
00119       fPolyCon1->Disable(true);
00120       delete mycut; // mycat has been copied into the conditions
00121 
00122       xvalues[0]=1000;xvalues[1]=2000;xvalues[2]=1500;xvalues[3]=1000;
00123       yvalues[0]=1000;yvalues[1]=1000;yvalues[2]=3000;yvalues[3]=1000;
00124       mycut= new TCutG("initialcut",4,xvalues,yvalues);
00125       fConArr2= new TGo4CondArray("polyconar",5,"TGo4PolyCond");
00126       fConArr2->SetValues(mycut);
00127       fConArr2->Disable(true);
00128       delete mycut; // mycat has been copied into the conditions
00129 
00130       AddAnalysisCondition(fWinCon1);
00131       AddAnalysisCondition(fWinCon2);
00132       AddAnalysisCondition(fPolyCon1);
00133       AddAnalysisCondition(fConArr1);
00134       AddAnalysisCondition(fConArr2);
00135       AddAnalysisCondition(fconHis1);
00136       AddAnalysisCondition(fconHis2);
00137     }
00138   else // got them from autosave file
00139     {
00140       fWinCon1  = (TGo4WinCond*)  GetAnalysisCondition("wincon1");
00141       fWinCon2  = (TGo4WinCond*)  GetAnalysisCondition("wincon2");
00142       fPolyCon1 = (TGo4PolyCond*) GetAnalysisCondition("polycon");
00143       fConArr1  = (TGo4CondArray*)GetAnalysisCondition("winconar");
00144       fConArr2  = (TGo4CondArray*)GetAnalysisCondition("polyconar");
00145       fconHis1  = (TGo4WinCond*)  GetAnalysisCondition("cHis1");
00146       fconHis2  = (TGo4WinCond*)  GetAnalysisCondition("cHis2");
00147       fconHis1->ResetCounts();
00148       fconHis2->ResetCounts();
00149       fWinCon1->ResetCounts();
00150       fWinCon2->ResetCounts();
00151       fPolyCon1->ResetCounts();
00152       fConArr1->ResetCounts();
00153       fConArr2->ResetCounts();
00154 
00155       cout << "Unpack: Restored conditions from autosave" << endl;
00156     }
00157   // connect histograms to conditions. will be drawn when condition is edited.
00158   fconHis1->SetHistogram("His1");
00159   fconHis2->SetHistogram("His2");
00160   fconHis1->Enable();
00161   fconHis2->Enable();
00162   fconHis1->PrintCondition(true);
00163   fconHis2->PrintCondition(true);
00164 
00165   if (GetPicture("Picture1")==0)
00166     {
00167       fcondSet = new TGo4Picture("condSet","Set conditions");
00168       fcondSet->SetLinesDivision(2,2,2);
00169       fcondSet->LPic(0,0)->AddObject(fHis1);
00170       fcondSet->LPic(0,1)->AddObject(fHis2);
00171       fcondSet->LPic(0,0)->AddCondition(fconHis1);
00172       fcondSet->LPic(0,1)->AddCondition(fconHis2);
00173       fcondSet->LPic(1,0)->AddObject(fHis1gate);
00174       fcondSet->LPic(1,1)->AddObject(fHis2gate);
00175       fcondSet->LPic(1,0)->SetFillAtt(4, 1001); // solid
00176       fcondSet->LPic(1,0)->SetLineAtt(4,1,1);
00177       fcondSet->LPic(1,1)->SetFillAtt(9, 1001); // solid
00178       fcondSet->LPic(1,1)->SetLineAtt(9,1,1);
00179       AddPicture(fcondSet);
00180 
00181       Picture1 = new TGo4Picture("Picture1","Picture example");
00182       Picture1->SetLinesDivision(3, 2,3,1);
00183       Picture1->LPic(0,0)->AddObject(fCr1Ch[0]);
00184       Picture1->LPic(0,0)->SetFillAtt(5, 3001); // pattern
00185       Picture1->LPic(0,0)->SetLineAtt(5,1,1);
00186       Picture1->LPic(0,1)->AddObject(fCr1Ch[1]);
00187       Picture1->LPic(0,1)->SetFillAtt(4, 3001); // pattern
00188       Picture1->LPic(0,1)->SetLineAtt(4,1,1);
00189       Picture1->LPic(1,0)->AddObject(fCr1Ch[2]);
00190       Picture1->LPic(1,0)->SetFillAtt(6, 1001); // solid
00191       Picture1->LPic(1,0)->SetLineAtt(6,1,1);
00192       Picture1->LPic(1,1)->AddObject(fCr1Ch[3]);
00193       Picture1->LPic(1,1)->SetFillAtt(7, 1001); // solid
00194       Picture1->LPic(1,1)->SetLineAtt(7,1,1);
00195       Picture1->LPic(1,2)->AddObject(fCr1Ch[4]);
00196       Picture1->LPic(3,0)->AddObject(fCr1Ch1x2);
00197       Picture1->LPic(3,0)->SetDrawOption("CONT");
00198 
00199       AddPicture(Picture1);
00200 
00201     }
00202   else
00203     {
00204       Picture1 = GetPicture("Picture1");
00205       fcondSet = (TGo4Picture *)GetPicture("condSet");
00206     }
00207 
00208   fWinCon1->Enable();
00209   fWinCon1->PrintCondition(true);
00210   fPolyCon1->Enable();
00211   fPolyCon1->PrintCondition(true);
00212   ((*fConArr2)[0])->Enable();
00213   ((*fConArr2)[1])->Enable();
00214 }
00215 //***********************************************************
00216 TXXXUnpackProc::~TXXXUnpackProc()
00217 {
00218   fWinCon1->PrintCondition(true);
00219   fPolyCon1->PrintCondition(true);
00220 }
00221 //***********************************************************
00222 
00223 //-----------------------------------------------------------
00224 void TXXXUnpackProc::XXXUnpack(TXXXUnpackEvent* poutevt)
00225 {
00226   TGo4MbsSubEvent* psubevt;
00227   Int_t index=0;
00228   Int_t value=0;
00229   Int_t lwords;
00230   Int_t *pdata;
00231   fInput    = (TGo4MbsEvent* ) GetInputEvent(); // from this
00232   if(fInput)
00233     {
00236       //      s_filhe* head=fInput->GetMbsSourceHeader();
00237       //      if(head)
00238       //         {
00239       //            cout <<"found filhe structure:" << endl;
00240       //            cout <<"\tdatalen: "<<head->filhe_dlen << endl;
00241       //            cout <<"\tfilename_l: "<<head->filhe_file_l << endl;
00242       //            cout <<"\tfilename: "<<head->filhe_file << endl;
00243       //            cout <<"\ttype: "<<head->filhe_type << endl;
00244       //            cout <<"\tsubtype: "<<head->filhe_subtype << endl;
00245       //            cout <<"\t#commentlines: "<<head->filhe_lines << endl;
00246       //         }
00247       //      else
00248       //         {
00249       //            cout <<"zero file header" << endl;
00250       //         }
00252 
00255       //      s_bufhe* head=fInput->GetMbsBufferHeader();
00256       //      if(head)
00257       //         {
00258       //            cout <<"\nfound bufhe structure:" << endl;
00259       //            cout <<"\tbuffernumber: "<<head->l_buf << endl;
00260       //            cout <<"\tdatalen: "<<head->l_dlen << endl;
00261       //            cout <<"\ttime lo: "<<head->l_time[0] << endl; // seconds since epoch 1970
00262       //            cout <<"\ttime hi: "<<head->l_time[1] << endl; // microseconds since time lo
00263       //            cout <<"\ttimestring: "<<ctime((const time_t*) &(head->l_time[0]));
00264       //            cout << "\t\t + "<<head->l_time[1] << " µs"<<endl;
00265       //            cout <<"\ttype: "<<head->i_type << endl;
00266       //            cout <<"\tsubtype: "<<head->i_subtype << endl;
00267       //         }
00268       //      else
00269       //         {
00270       //            cout <<"zero buffer header" << endl;
00271       //         }
00273 
00274       fInput->ResetIterator();
00275       while ((psubevt = fInput->NextSubEvent()) != 0) // subevent loop
00276    {
00277      if( psubevt->GetSubcrate() == 1)
00278        {
00279          pdata=psubevt->GetDataField();
00280          lwords= (psubevt->GetDlen() -2) * sizeof(Short_t)/sizeof(Int_t);
00281          if(lwords >= 8) lwords=8; // take only first 8 lwords
00282          for(Int_t i = 0; i<lwords; ++i)
00283       {
00284         index =  *pdata&0xfff;      // in case low word is index
00285         //value = (*pdata>>16)&0xfff; // in case high word is data
00286         if(*pdata != 0)
00287           {
00288             fCr1Ch[i]->Fill((Float_t)(*pdata));
00289             poutevt->fiCrate1[i] = *pdata; // fill output event
00290             if(i == 0) // fill first channel
00291          {
00292                           if(fconHis1->Test(*pdata))fHis1gate->Fill((Float_t)(*pdata));
00293                           fHis1->Fill((Float_t)(*pdata));
00294          }
00295             if(i == 1)
00296          {
00297                           if(fconHis2->Test(*pdata))fHis2gate->Fill((Float_t)(*pdata));
00298                           fHis2->Fill((Float_t)(*pdata));
00299            // fill Cr1Ch1x2 for three polygons:
00300                 if(fPolyCon1->Test(*pdata,value))       fCr1Ch1x2->Fill((Float_t)(*pdata),(Float_t)value);
00301                 if(((*fConArr2)[0])->Test(*pdata,value))fCr1Ch1x2->Fill((Float_t)(*pdata),(Float_t)value);
00302                 if(((*fConArr2)[1])->Test(*pdata,value))fCr1Ch1x2->Fill((Float_t)(*pdata),(Float_t)value);
00303          }
00304           }
00305         value = *pdata; // save for 2d histogram
00306         pdata++;
00307       } // for SEW LW
00308        } // if (subcrate)
00309      if( psubevt->GetSubcrate() == 2)
00310        {
00311          pdata=psubevt->GetDataField();
00312          lwords= (psubevt->GetDlen() -2) * sizeof(Short_t)/sizeof(Int_t);
00313          if(lwords >= 8) lwords=8;
00314          for(Int_t i = 0; i<lwords; ++i)
00315       {
00316         index=*pdata&0xfff;
00317         value=(*pdata>>16)&0xfff;
00318         if(*pdata != 0)
00319           {
00320             poutevt->fiCrate2[i] = *pdata;
00321             fCr2Ch[i]->Fill((Float_t)(*pdata));
00322           }
00323         pdata++;
00324       } // for SEW LW
00325        } // if (subcrate)
00326    }  // while
00327       poutevt->SetValid(kTRUE); // to store
00328     } // if(fInput)
00329   else    cout << "XXXUnpackProc: no input event !"<< endl;
00330 }
00331 //-----------------------------------------------------------
00332 ClassImp(TXXXUnpackProc)
00333 
00334 
00335 
00336 
00337 //----------------------------END OF GO4 SOURCE FILE ---------------------

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