GSI Object Oriented Online Offline (Go4)  GO4-5.3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TXXXUnpackProc.cxx
Go to the documentation of this file.
1 // $Id: TXXXUnpackProc.cxx 478 2009-10-29 12:26:09Z linev $
2 //-----------------------------------------------------------------------
3 // The GSI Online Offline Object Oriented (Go4) Project
4 // Experiment Data Processing at EE department, GSI
5 //-----------------------------------------------------------------------
6 // Copyright (C) 2000- GSI Helmholtzzentrum für Schwerionenforschung GmbH
7 // Planckstr. 1, 64291 Darmstadt, Germany
8 // Contact: http://go4.gsi.de
9 //-----------------------------------------------------------------------
10 // This software can be used under the license agreements as stated
11 // in Go4License.txt file which is part of the distribution.
12 //-----------------------------------------------------------------------
13 
14 #include "TXXXUnpackProc.h"
15 #include "TGo4EventEndException.h"
16 
17 #include <time.h>
18 
19 #include "TH1.h"
20 #include "TH2.h"
21 #include "TCutG.h"
22 #include "TArrow.h"
23 #include "TLatex.h"
24 #include "TLine.h"
25 
26 #include "TGo4Log.h"
27 #include "TGo4MbsEvent.h"
28 #include "TGo4WinCond.h"
29 #include "TGo4PolyCond.h"
30 #include "TGo4CondArray.h"
31 #include "TGo4Picture.h"
32 
33 #include "TXXXParameter.h"
34 #include "TXXXUnpackEvent.h"
35 #include "TXXXCalibPar.h"
36 
37 extern "C" {
38  #include "s_filhe_swap.h"
39  #include "s_bufhe_swap.h"
40  #include "f_ut_utime.h"
41 }
42 
43 //***********************************************************
46 {
47 }
48 //***********************************************************
49 // this one is used in TXXXUnpackFact.cxx
50 TXXXUnpackProc::TXXXUnpackProc(const char* name) :
51  TGo4EventProcessor(name)
52 {
53  TGo4Log::Info("TXXXUnpackProc: Create %s", name);
54 
56  fParam1 = (TXXXParameter *) GetParameter("XXXPar1");
57  fParam2 = (TXXXParameter *) GetParameter("XXXPar2");
58  fParam1->PrintParameter(0,0);
59 
60  fParam2->PrintParameter(0,0);
61 
62  TGo4Log::Info("TXXXProc: Produce histograms");
63 
64  for(int i=0;i<8;i++) {
65  fCr1Ch[i] = 0;
66  fCr2Ch[i] = 0;
67  }
68 
69  CreateRawHistograms(5000, 1., 5001.);
70  fEvCount = 0;
71 
72  fCr1Ch1x2 = MakeTH2('I', "Cr1Ch1x2","Crate 1 channel 1x2", 200, 1., 5001., 200, 1., 5001.);
73  fHis1 = MakeTH1('I', "His1","Condition histogram", 5000, 1., 5001.);
74  fHis2 = MakeTH1('I', "His2","Condition histogram", 5000, 1., 5001.);
75  fHis1gate = MakeTH1('I', "His1g","Gated histogram", 5000, 1., 5001.);
76  fHis2gate = MakeTH1('I', "His2g","Gated histogram", 5000, 1., 5001.);
77 
78  TGo4Log::Info("TXXXProc: Produce conditions");
79  fWinCon1 = MakeWinCond("wincon1", 50, 2000);
80  fWinCon2 = MakeWinCond("wincon2", 50, 70, 90, 120);
81  fconHis1 = MakeWinCond("cHis1", 100, 2000, "His1");
82  fconHis2 = MakeWinCond("cHis2", 100, 2000, "His2");
83 
84  Double_t cutpnts[3][2] = { {400, 800}, {700, 900}, {600, 1100} };
85  fPolyCon1 = MakePolyCond("polycon", 3, cutpnts);
86 
88  if (fConArr1==0) {
89  fConArr1 = new TGo4CondArray("winconar",30,"TGo4WinCond");
90  fConArr1->SetValues(100,500);
91  fConArr1->Disable(true);
92  ((*fConArr1)[0])->SetValues(200,400);
93  ((*fConArr1)[1])->SetValues(700,1000);
94  ((*fConArr1)[2])->SetValues(1500,2000);
95  fConArr1->SetHistogram("Sum3");
97  } else {
99  }
100 
102  if(fConArr2==0) {
103  // This is example how to create condition array
104  TGo4Log::Info("TXXXProc: Create condition");
105  Double_t xvalues[4] = { 1000, 2000, 1500, 1000 };
106  Double_t yvalues[4] = { 1000, 1000, 3000, 1000 };
107  TCutG* mycut = new TCutG("cut2", 4, xvalues, yvalues);
108  fConArr2 = new TGo4CondArray("polyconar",4,"TGo4PolyCond");
109  fConArr2->SetValues(mycut);
110  fConArr2->Disable(true); // means: condition check always returns true
111  delete mycut; // mycat has been copied into the conditions
113  } else {
114  TGo4Log::Info("TXXXProc: Restore condition from autosave");
116  }
117 
118  // connect histograms to conditions. will be drawn when condition is edited.
119  fWinCon1->Enable();
120  fWinCon2->Disable(true); // return always true
121  fWinCon2->Invert(kTRUE);
122  fWinCon1->PrintCondition(true);
123  fconHis1->PrintCondition(true);
124  fconHis2->PrintCondition(true);
125  fPolyCon1->Enable();
126  fPolyCon1->PrintCondition(true);
127  ((*fConArr2)[0])->Enable();
128  ((*fConArr2)[1])->Enable(); // 2 and 3 remain disabled
129 
130  fcondSet = GetPicture("condSet");
131  if (fcondSet==0) {
132  // in the upper two pads, the condition limits can be set,
133  // in the lower two pads, the resulting histograms are shown
134  fcondSet = new TGo4Picture("condSet","Set conditions");
135  fcondSet->SetDivision(2,2);
136  fcondSet->Pic(0,0)->AddObject(fHis1);
137  fcondSet->Pic(0,1)->AddObject(fHis2);
142  fcondSet->Pic(1,0)->SetFillAtt(4, 1001); // solid
143  fcondSet->Pic(1,0)->SetLineAtt(4,1,1);
144  fcondSet->Pic(1,1)->SetFillAtt(9, 1001); // solid
145  fcondSet->Pic(1,1)->SetLineAtt(9,1,1);
146  fcondSet->Pic(0,0)->SetTitleAttr(0.05, 0.85, 0.8, 0.95);
148  }
149 
150  fPicture1 = GetPicture("Picture1");
151  if (fPicture1 == 0) {
152  fPicture1 = new TGo4Picture("Picture1","Picture example");
153  fPicture1->SetLinesDivision(3, 2,3,1);
154  fPicture1->LPic(0,0)->AddObject(fCr1Ch[0]);
155  fPicture1->LPic(0,0)->SetFillAtt(5, 3001); // pattern
156  fPicture1->LPic(0,0)->SetLineAtt(5,1,1);
157  fPicture1->LPic(0,1)->AddObject(fCr1Ch[1]);
158  fPicture1->LPic(0,1)->SetFillAtt(4, 3001); // pattern
159  fPicture1->LPic(0,1)->SetLineAtt(4,1,1);
160  fPicture1->LPic(1,0)->AddObject(fCr1Ch[2]);
161  fPicture1->LPic(1,0)->SetFillAtt(6, 1001); // solid
162  fPicture1->LPic(1,0)->SetLineAtt(6,1,1);
163  fPicture1->LPic(1,1)->AddObject(fCr1Ch[3]);
164  fPicture1->LPic(1,1)->SetFillAtt(7, 1001); // solid
165  fPicture1->LPic(1,1)->SetLineAtt(7,1,1);
166  fPicture1->LPic(1,2)->AddObject(fCr1Ch[4]);
168  fPicture1->LPic(3,0)->SetDrawOption("CONT");
169  fPicture1->LPic(3,0)->AddSpecialObject(new TArrow(3500., 3500, 2000., 1500., 0.02));
170  fPicture1->LPic(3,0)->AddSpecialObject(new TLatex(1500, 3500, "Example of text label in the picture"));
171 // fPicture1->LPic(3,0)->AddSpecialObject(new TLine(2500., 2500, 3500., 1500.));
173  }
174 }
175 //***********************************************************
177 {
178  fWinCon1->PrintCondition(true);
179  fPolyCon1->PrintCondition(true);
180 }
181 //***********************************************************
182 
183 //-----------------------------------------------------------
184 void TXXXUnpackProc::CreateRawHistograms(int nbins, double xmin, double xmax)
185 {
186  //std::cout <<"TXXXUnpackProc::CreateRawHistograms" << std::endl;
187  for(int i=0;i<8;i++) {
188 
189  if (fCr1Ch[i]!=0) {
190  RemoveHistogram(fCr1Ch[i]->GetName());
191  fCr1Ch[i] = 0;
192  }
193 
194  if (fCr2Ch[i]!=0) {
195  RemoveHistogram(fCr2Ch[i]->GetName());
196  fCr2Ch[i] = 0;
197  }
198 
199  fCr1Ch[i] = MakeTH1('I', Form("Crate1/Cr1Ch%02d",i+1), Form("Crate 1 channel %2d",i+1), nbins, xmin, xmax);
200  fCr2Ch[i] = MakeTH1('I', Form("Crate2/Cr2Ch%02d",i+1), Form("Crate 2 channel %2d",i+1), nbins, xmin, xmax);
201  }
202 
203  // change histogram pointer, used in parameter
204  TXXXCalibPar* par = (TXXXCalibPar*) GetParameter("CaliPar");
205  if (par!=0) par->SetCalibSpectrum(fCr1Ch[0]);
206 
207 
208 }
209 
210 //-----------------------------------------------------------
212 {
213  TGo4MbsEvent* inp_evt = (TGo4MbsEvent* ) GetInputEvent(); // from this
214  TXXXUnpackEvent* out_evt = (TXXXUnpackEvent*) dest;
215 
216  if (inp_evt==0) {
217  TGo4Log::Error("XXXUnpackProc: no input event !");
218  return kFALSE;
219  }
220 
221 
222  fEvCount++;
223  if (fEvCount % 1000000 == 0) {
224  // this is demonstration how one can time to time recreate histogram with other ranges
225 
226  Long_t loop = (fEvCount / 1000000) % 5;
227 
228  CreateRawHistograms(5000 + loop*200, 1. - loop*100, 5001 + loop*100);
229 
230  // TGo4Log::Info("Histograms recreated");
231  }
232 
235 // s_filhe* head=inp_evt->GetMbsSourceHeader();
236 // if(head)
237 // {
238 // std::cout <<"found filhe structure:" << std::endl;
239 // std::cout <<"\tdatalen: "<<head->filhe_dlen << std::endl;
240 // std::cout <<"\tfilename_l: "<<head->filhe_file_l << std::endl;
241 // std::cout <<"\tfilename: "<<head->filhe_file << std::endl;
242 // std::cout <<"\ttype: "<<head->filhe_type << std::endl;
243 // std::cout <<"\tsubtype: "<<head->filhe_subtype << std::endl;
244 // std::cout <<"\t#commentlines: "<<head->filhe_lines << std::endl;
245 // }
246 // else
247 // {
248 // std::cout <<"zero file header" << std::endl;
249 // }
251 
254 // s_bufhe* head=inp_evt->GetMbsBufferHeader();
255 // if(head) {
256 // std::cout <<"\nfound bufhe structure:" << std::endl;
257 // std::cout <<"\tbuffernumber: "<<head->l_buf << std::endl;
258 // std::cout <<"\tdatalen: "<<head->l_dlen << std::endl;
259 // std::cout <<"\ttime lo: "<<head->l_time[0] << std::endl; // seconds since epoch 1970
260 // std::cout <<"\ttime hi: "<<head->l_time[1] << std::endl; // microseconds since time lo
261 // char sbuf[1000]; f_ut_utime(head->l_time[0], head->l_time[1], sbuf);
262 // std::cout <<"\ttimestring: " << sbuf << std::endl;
263 // std::cout <<"\ttype: "<<head->i_type << std::endl;
264 // std::cout <<"\tsubtype: "<<head->i_subtype << std::endl;
265 // }
266 // else
267 // {
268 // std::cout <<"zero buffer header" << std::endl;
269 //
270 // }
272 
273 
274  inp_evt->ResetIterator();
275  TGo4MbsSubEvent* psubevt(0);
276  while ((psubevt = inp_evt->NextSubEvent()) != 0) // subevent loop
277  {
278  Int_t* pdata = psubevt->GetDataField();
279  Int_t lwords = psubevt->GetIntLen();
280  Int_t subcrate=psubevt->GetSubcrate();
281  if(subcrate<0 || subcrate> XXX_NUM_CRATES)
282  {
283  TGo4Log::Info("XXXUnpackProc: skip invalid subcrate %d", subcrate);
284  continue; // try next subevent if any
285  }
286 
287  if(lwords >= 8) lwords=8; // take only first 8 lwords
288  Int_t lastvalue = 0;
289  for(Int_t i = 0; i<lwords; ++i)
290  {
291  // Int_t index = *pdata&0xfff; // in case low word is index
292  // Int_t value = (*pdata>>16)&0xfff; // in case high word is data
293 
294 
295  // first copy data of crate and channel into corresponding module:
296  TXXXUnpackEvent& ev=*out_evt; // ref instead pointer for array syntax:
297  TXXXModule* mod=dynamic_cast<TXXXModule*>(&ev[subcrate][i]); // 2d array with composite event operator[]
298  if(mod)
299  {
300  if(*pdata != 0)
301  mod->SetData(*pdata); // zero suppressed data
302  else
303  mod->SetAux(i); // account count zero value data channel for each subevent
304 
305  mod->SetTest(*pdata); // record any data here
306  }
307  else
308  {
309  TGo4Log::Info("XXXUnpackProc: WARNING: no output event module for crate %d, channel %d", subcrate, i);
310 
311  }
312  if(*pdata != 0)
313  {
314  // process crate specific histograming here:
315  if( subcrate == 1)
316  {
317  fCr1Ch[i]->Fill((Float_t)(*pdata));
318 
319  if(i == 0) // fill first channel
320  {
321  if(fconHis1->Test(*pdata))fHis1gate->Fill((Float_t)(*pdata));
322  fHis1->Fill((Float_t)(*pdata));
323  }
324  if(i == 1)
325  {
326  if(fconHis2->Test(*pdata))fHis2gate->Fill((Float_t)(*pdata));
327  fHis2->Fill((Float_t)(*pdata));
328  // fill Cr1Ch1x2 for three polygons:
329  if(fPolyCon1->Test(*pdata,lastvalue)) fCr1Ch1x2->Fill((Float_t)(*pdata),(Float_t)lastvalue);
330  if(((*fConArr2)[0])->Test(*pdata,lastvalue))fCr1Ch1x2->Fill((Float_t)(*pdata),(Float_t)lastvalue);
331  if(((*fConArr2)[1])->Test(*pdata,lastvalue))fCr1Ch1x2->Fill((Float_t)(*pdata),(Float_t)lastvalue);
332  }
333  lastvalue = *pdata; // save for 2d histogram
334  }
335  else if ( subcrate == 2)
336  {
337  fCr2Ch[i]->Fill((Float_t)(*pdata));
338  }
339  }
340  pdata++;
341  }// for SEW LW
342  } // while
343  out_evt->SetValid(kTRUE); // to store
344  // throwing this exception stops the event loop
345  // Note that subsequent steps are not executed!
346  // throw TGo4EventEndException(this);
347 
348  return kTRUE;
349 }
virtual void PrintCondition(Bool_t points=kTRUE)
void SetData(Int_t dat)
void SetValid(Bool_t on)
TGo4Picture * GetPicture(const char *name)
virtual void PrintCondition(Bool_t full=kTRUE)
TXXXParameter * fParam2
TH2 * MakeTH2(char type, const char *fullname, const char *title, Int_t nbinsx, Double_t xlow, Double_t xup, Int_t nbinsy, Double_t ylow, Double_t yup, const char *xtitle=0, const char *ytitle=0, const char *ztitle=0)
virtual Bool_t Test(Double_t x, Double_t y)
TH1 * fCr2Ch[XXX_NUM_CHAN]
TH1 * fCr1Ch[XXX_NUM_CHAN]
TGo4WinCond * MakeWinCond(const char *fullname, Double_t xmin, Double_t xmax, const char *HistoName=0)
TGo4CondArray * fConArr2
TGo4CondArray * fConArr1
virtual Int_t PrintParameter(Text_t *buffer=0, Int_t buflen=0)
TGo4Condition * GetAnalysisCondition(const char *name, const char *cond_cl=0)
TGo4PolyCond * MakePolyCond(const char *fullname, Int_t npoints, Double_t(*points)[2], const char *HistoName=0)
virtual Bool_t BuildEvent(TGo4EventElement *dest)
virtual void SetValues(Double_t low1, Double_t up1)
TGo4Picture * Pic(Int_t posy, Int_t posx)
TGo4MbsSubEvent * NextSubEvent(Bool_t all=kFALSE)
virtual void Enable()
void CreateRawHistograms(int nbins, double xmin, double xmax)
void SetTest(Int_t dat)
void SetDivision(Int_t ndivy, Int_t ndivx)
void AddObject(TObject *obj, Option_t *DrawOption=0)
virtual void Disable(Bool_t result)
TGo4Picture * fcondSet
void SetCalibSpectrum(TH1 *h1)
void SetHistogram(const char *name)
TXXXParameter * fParam1
virtual void Disable(Bool_t result)
#define XXX_NUM_CRATES
void AddCondition(TNamed *cond=0)
TGo4WinCond * fconHis2
void SetLineAtt(Color_t color, Style_t style, Width_t width, Int_t index=UndefIndex)
TGo4Parameter * GetParameter(const char *name, const char *par_class=0)
void SetLinesDivision(Int_t numlines, const Int_t *numbers)
TGo4EventElement * GetInputEvent()
TGo4WinCond * fWinCon1
TGo4WinCond * fconHis1
Bool_t AddAnalysisCondition(TGo4Condition *con, const char *subfolder=0)
virtual Bool_t Test(Double_t v1)
Definition: TGo4WinCond.cxx:83
void SetFillAtt(Color_t color, Style_t style, Int_t index=UndefIndex)
TGo4WinCond * fWinCon2
Bool_t AddPicture(TGo4Picture *pic, const char *subfolder=0)
TH1 * MakeTH1(char type, const char *fullname, const char *title, Int_t nbinsx, Double_t xlow, Double_t xup, const char *xtitle=0, const char *ytitle=0)
GO4 ConditionPainter prototype Test
Definition: condition.js:691
TGo4PolyCond * fPolyCon1
void ResetIterator()
Definition: TGo4MbsEvent.h:98
TGo4Picture * fPicture1
void AddSpecialObject(TObject *obj, Option_t *drawopt=0)
virtual void SetDrawOption(Option_t *option="")
Definition: TGo4Picture.h:142
TGo4Picture * LPic(Int_t nline, Int_t ncol)
static void Error(const char *text,...)
Definition: TGo4Log.cxx:309
static void Info(const char *text,...)
Definition: TGo4Log.cxx:283
virtual ~TXXXUnpackProc()
virtual void ResetCounts()
void SetAux(Int_t dat)
void SetTitleAttr(Double_t x1, Double_t y1, Double_t x2, Double_t y2, Double_t textsize=0.)
virtual void Invert(Bool_t on)
Bool_t RemoveHistogram(const char *name)