GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GSIWatchers.C
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2010 by Olivier Stezowski *
3  * stezow(AT)ipnl.in2p3.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
20 
21 #include "GSIWatchers.h"
22 #include "Frame.h"
23 #include "AgataKeyFactory.h"
24 
25 #include "eventapiV50/s_filhe_swap.h"
26 #include "eventapiV50/s_ves10_1_swap.h"
27 #include "eventapiV50/s_vehe_swap.h"
28 #include "eventapiV50/s_evhe_swap.h"
29 #include "eventapiV50/s_ve10_1_swap.h"
30 #include "eventapiV50/s_bufhe_swap.h"
31 extern "C" {
32 #include "eventapiV50/f_evt.h"
33 }
34 
35 using namespace Gw;
36 
38 
40  TTreeWithConditions("BaseGSIWatcher", "BaseGSIWatcher",0x0),
41  fMBSFrame(0x0)
42 {
43 
44 }
45 
46 BaseGSIWatcher::BaseGSIWatcher(const char *name, const char *title, TTree *tree) :
47  TTreeWithConditions(name, title,tree),
48  fMBSFrame(0x0)
49 {
50 }
51 
52 BaseGSIWatcher::BaseGSIWatcher(const char *name, const char *title, TTree *tree, Short_t do_spectra, Short_t do_tree ) :
53  TTreeWithConditions(name, title,tree, do_spectra, do_tree),
54  fMBSFrame(0x0)
55 {
56 }
57 
59 {
60 }
61 
63 {
64  return Watcher::GetFromTrigger(trigger, "data:ranc0", fMBSFrame);
65 }
66 
67 /*
68 void BaseGSIWatcher::Exec(Option_t * option)
69 {
70  fDoSpectra = fDoTree = 2;
71 
72  // Clear everything
73  SetLastExecStatus(0); Clear();
74 
75  FillBranches();
76  fClone->Fill();
77 
78  // check conditions
79  Short_t nb_cond = CheckCond() ; SetLastExecStatus(nb_cond);
80 
81  switch ( fDoSpectra ) {
82  case 0:
83  break;
84  case 1:
85  if ( nb_cond )
86  FillSpectra();
87  break;
88  case 2:
89  default:
90  FillSpectra();
91  break;
92  }
93  switch ( fDoTree ) {
94  case 0:
95  break;
96  case 1:
97  if ( nb_cond )
98  FillTree(); // GetTree()->Fill();;
99 
100  break;
101  case 2:
102  default:
103  FillTree(); // GetTree()->Fill();
104  break;
105  }
106 }
107 */
108 
110 
111 MBSWatcher::MBSWatcher(const char *name, const char *title, TDirectory *sp_dir, TDirectory *tag_dir):
112  WatcherWithTag(name,title,sp_dir,tag_dir),
113  fMBSFrame(0x0),
114  fPrintOut(false)
115 {
116  fEvent_dlen = Watcher::MakeTH1 <TH1F> ("event_dlen","Data Length",500,0,2500);
117  fEvent_type = MakeTH1<TH1F>("event_type","Type number",100,0,200) ;
118  fEvent_subtype = MakeTH1<TH1F>("event_subtype","Subbtype",100,0,300) ;
119  fEvent_trigger = MakeTH1<TH1F>("event_trigger","Trigger Number",20,0,20) ;
120  fEvent_trigger->GetXaxis()->SetBinLabel(2, "Pulser");
121  fEvent_trigger->GetXaxis()->SetBinLabel(3, "LYC. Calib");
122  fEvent_trigger->GetXaxis()->SetBinLabel(4, "AGA. Calib");
123  fEvent_trigger->GetXaxis()->SetBinLabel(5, "HEC. Calib");
124  fEvent_trigger->GetXaxis()->SetBinLabel(6, "FRS");
125  fEvent_trigger->GetXaxis()->SetBinLabel(7, "Part.+#gamma(HEC.)");
126  fEvent_trigger->GetXaxis()->SetBinLabel(8, "Part.+#gamma(AGA.)");
127  fEvent_trigger->GetXaxis()->SetBinLabel(9, "Part.+#gamma(HEC.)+LYC.");
128  fEvent_trigger->GetXaxis()->SetBinLabel(10, "Part.+#gamma(AGA.+LYC.)");
129  fEvent_trigger->GetXaxis()->SetBinLabel(11, "Part.");
130  fEvent_trigger->GetXaxis()->SetBinLabel(12, "P");
131  fEvent_trigger->GetXaxis()->SetBinLabel(13, "Spill-on");
132  fEvent_trigger->GetXaxis()->SetBinLabel(14, "Spill-off");
133  TagOn(fEvent_trigger);
134  fEvent_count = MakeTH1<TH1F>("event_count","Current event number",1000,0,1000) ;
135  fSubEvent_dlen = MakeTH1<TH1F>("subevent_dlen","SubEvent Data Length",1000,0,1000) ;
136  fSubEvent_subtype = MakeTH1<TH1F>("subevent_subtype","SubEvent type",5,0,5) ;
137  fSubEvent_type = MakeTH1<TH1F>("subevent_type","SubEvent Type number",20,0,20) ;
138  fSubEvent_control = MakeTH1<TH1F>("subevent_control","Processor type control",50,0,50) ;
139  fSubEvent_subcrate= MakeTH1<TH1F>("subevent_subcrate","Subcrate number",2,0,2) ;
140  fSubEvent_procid = MakeTH1<TH1F>("subevent_procid","Processor ID",150,0,150) ;
141 
142 }
143 
144 void MBSWatcher::DoCanvas(TCanvas *c, Option_t *opt)
145 {
146  TString option = opt;
147  c->Divide(2,2,0.001,0.001);
148 
149  c->cd(1); fEvent_trigger->Draw();
150  c->cd(2); fEvent_dlen->Draw();
151  c->cd(3); fSubEvent_dlen->Draw();
152  c->cd(4); fSubEvent_procid->Draw();
153 }
154 
156 {
157  return Watcher::GetFromTrigger(trigger, "data:ranc0", fMBSFrame);
158 }
159 
160 void MBSWatcher::PrintOut(Bool_t ison)
161 {
162  fPrintOut = ison;
163 }
164 
165 void MBSWatcher::Exec(Option_t * /*option*/)
166 {
167  ADF::RawFrame *rframe = 0x0; ADF::AgataKey *key; Int_t *pMBSData = 0x0; Int_t event_type, event_subtype, event_number;
168 
169  // be sure the frame has been set properly
170  if ( fMBSFrame == 0x0 || !fMBSFrame->IsValid() ) {
171  SetLastExecStatus(1);
172  return;
173  }
174  else {
175  // ADF part
176  rframe =
178  key = dynamic_cast<ADF::AgataKey *> (rframe->GetKey()); event_number = key->GetEventNumber();
179 
180  // MBS part
181  pMBSData = (Int_t *)(rframe->RawBuffer().Address());
182  }
183  // read pseudo ADF key in the MBS part
184  ADF_MBS *ADF_MBS_Key = (ADF_MBS *)pMBSData;
185 
186  if ( ADF_MBS_Key->idmbs == 0x100 || ADF_MBS_Key->idmbs == 0x200 ) { // well formed 'event'
187  event_type = 10 ; event_subtype = 1;
188  }
189  else {
190  event_type = ADF_MBS_Key->type; event_subtype = ADF_MBS_Key->subtype;
191  }
192 
193  //
194  //if( ! fUnpacker->CheckEventHeader(ADF_MBS_Key->dlen, event_type, event_subtype, 0,
195  // ADF_MBS_Key->trigger, event_number,
196  // fUnpackData) ) { cout << " WRONG Event header" << endl; return; }
197 
198  fEvent_dlen->Fill(ADF_MBS_Key->dlen);
199  fEvent_subtype->Fill(event_subtype);
200  fEvent_type->Fill(event_type);
201  fEvent_trigger->Fill(ADF_MBS_Key->trigger);
202  fEvent_count->Fill(event_number);
203 
204  if ( fPrintOut ) {
205  cout << " ADF_MBS_Key->dlen " << ADF_MBS_Key->dlen << " ADF_MBS_Key->idmbs 0x" << hex << ADF_MBS_Key->idmbs << endl;
206  cout << dec;
207  }
208 
209  // now read all sub_event using eventAPI facilities ... cannot be done, no event header !
210 
211  // -3 is because apparently the coded value doest not take into account additional TS,ev# in the ADF_MBS_Key structure
212  Int_t i_nrest = (ADF_MBS_Key->dlen+4)/2 - 4 - 3;
213  // or
214  // Int_t i_nrest = rframe->GetKey()->GetDataLength()/4 - sizeof(ADF_MBS_Key)/4;
215 
216  Int_t i_offset = 7; // first sub event starts at 7*4 bytes in the Data part of the Raw Frame
217 
218  // fOffset.clear();
219  while (i_nrest >= 3) {
220  // while (i_nrest > 3) {
221 
222  const s_ves10_1* p_subhead = (const s_ves10_1*)(pMBSData+i_offset);
223  Int_t i_size = (p_subhead->l_dlen-2)/2;
224  Int_t i_styp = p_subhead->i_subtype;
225  Int_t i_typ = p_subhead->i_type;
226  Int_t i_cont = p_subhead->h_control;
227  Int_t i_crate = p_subhead->h_subcrate;
228  Int_t i_proc = p_subhead->i_procid;
229 
230  fSubEvent_dlen->Fill(i_size);
231  fSubEvent_subtype->Fill(i_styp);
232  fSubEvent_type->Fill(i_typ);
233  fSubEvent_control->Fill(i_cont);
234  fSubEvent_subcrate->Fill(i_crate);
235  fSubEvent_procid->Fill(i_proc);
236 
237  if (fPrintOut) {
238  cout << endl << " **** Subevent, i_nrest " << i_nrest << " should be >= 3 " << endl;
239  cout << "i_size " << i_size << " i_styp " << i_styp << " i_typ " << i_typ
240  << " i_control " << i_cont << " i_subcrate " << i_crate << " i_proc " << i_proc << endl ;
241  }
242  // now apply unpacker ... just for test
243  // fUnpacker->UnpackSubevent(i_typ, i_styp, i_size, i_proc, i_cont, ADF_MBS_Key->trigger,
244  // pMBSData + i_offset + 3,
245  // fUnpackData) ;
246  i_nrest -= i_size + 3;
247  i_offset += i_size + 3;
248 
249  }
250 
251  /*
252  // now read all sub_event using eventAPI facilities ... cannot be done, no event header !
253  Int_t *event_data = pMBSData + 7;
254  int result = 1;
255  for (int sub = 0; result != GETEVT__NOMORE; ++sub)
256  {
257  cout << " --> SUB " << sub << " " << hex << event_data[0] << " " << event_data[1] << endl;
258 
259  s_ves10_1 *p_subhead = 0; INTS4 *data = 0; INTS4 length = 0;
260  //
261  result = f_evt_get_subevent((s_ve10_1*)(event_data), sub, (INTS4**)&p_subhead, (INTS4**)&data, &length);
262  if (result == GETEVT__SUCCESS && p_subhead)
263  {
264  Int_t i_size = (p_subhead->l_dlen-2)/2;
265  Int_t i_typ = p_subhead->i_type;
266  Int_t i_styp = p_subhead->i_subtype;
267  Int_t i_pid = p_subhead->i_procid;
268  Int_t i_ptyp = p_subhead->h_control;
269  Int_t i_crate = p_subhead->h_subcrate;
270 
271  cout << "i_size " << i_size << " i_typ " << i_typ << " i_styp "
272  << i_styp << " i_pid " << i_pid << " i_ptyp " << i_ptyp << " i_crate " << i_crate << endl ;
273 
274  fSubEvent_dlen->Fill(i_size);
275  fSubEvent_type->Fill(i_typ);
276  fSubEvent_subtype->Fill(i_styp);
277  fSubEvent_control->Fill(i_pid);
278  fSubEvent_subcrate->Fill(i_ptyp);
279  fSubEvent_procid->Fill(i_crate);
280 
281  }
282  }
283  */
284 }
285 
286 
287 /*
288 TH1I* TSPEBasicProc::MakeH1I(const char* fname,
289  const char* hname,
290  Int_t nbinsx,
291  Float_t xmin, Float_t xmax,
292  const char* xtitle,
293  Color_t linecolor,
294  Color_t fillcolor,
295  const char* ytitle) {
296  TNamed* res = TestObject((getfunc)&TGo4EventProcessor::GetHistogram, fname, hname);
297  if (res!=0) return dynamic_cast<TH1I*>(res);
298 
299  TH1I* histo = new TH1I(hname, hname, nbinsx, xmin, xmax);
300  histo->SetXTitle(xtitle);
301  if (ytitle) histo->SetYTitle(ytitle);
302  histo->SetLineColor(linecolor);
303  histo->SetFillColor(fillcolor);
304  AddHistogram(histo, fname);
305  return histo;
306 }
307 
308 TH1I* TSPEBasicProc::MakeH1IArray(const char* foldername,
309  const char* name, const char* name_ext,
310  Int_t nbinsx,
311  Float_t xmin, Float_t xmax,
312  const char* xtitle,
313  Color_t linecolor,
314  Color_t fillcolor)
315 {
316  char fullname[150];
317  sprintf(fullname,"%s%s",name_ext, name);
318 
319  return MakeH1I(foldername, fullname, nbinsx, xmin, xmax, xtitle, linecolor, fillcolor);
320 }
321 
322 
323 TH2I* TSPEBasicProc::MakeH2I(const char* fname,
324  const char* hname,
325  Int_t nbinsx, Float_t xmin, Float_t xmax,
326  Int_t nbinsy, Float_t ymin, Float_t ymax,
327  const char* xtitle, const char* ytitle,
328  Color_t markercolor) {
329  TNamed* res = TestObject((getfunc)&TGo4EventProcessor::GetHistogram, fname, hname);
330  if (res!=0) return dynamic_cast<TH2I*>(res);
331 
332  TH2I* histo = new TH2I(hname, hname, nbinsx, xmin, xmax, nbinsy, ymin, ymax);
333  histo->SetMarkerColor(markercolor);
334  histo->SetXTitle(xtitle);
335  histo->SetYTitle(ytitle);
336  AddHistogram(histo, fname);
337  return histo;
338 }
339 
340 TH1I* TSPEBasicProc::MakeH1ISeries(const char* foldername,
341  Int_t seriesnumber,
342  Int_t crate,
343  Int_t number,
344  Int_t nbins,
345  Float_t xmin, Float_t xmax,
346  Bool_t remove)
347 {
348  char fullfoldername[100];
349  sprintf(fullfoldername,"%s/%02d", foldername, seriesnumber);
350  char histoname[50];
351  sprintf(histoname,"newVME%02d_%02d_%02d", crate, seriesnumber, number);
352  if (remove) {
353  char fullname[200];
354  sprintf(fullname,"%s/%s",fullfoldername,histoname);
355  RemoveHistogram(fullname);
356  return 0;
357  }
358  return MakeH1I(fullfoldername, histoname, nbins, xmin, xmax);
359 }
360 
361 */
362 
virtual Bool_t IsValid() const
true if it is a valid pointer
Definition: Frame.h:616
TH1F * fEvent_count
Definition: GSIWatchers.h:126
virtual Frame * GetFrame() const
Definition: Frame.h:625
ClassImp(BaseGSIWatcher)
TH1F * fSubEvent_subcrate
Definition: GSIWatchers.h:132
void PrintOut(Bool_t ison=true)
Switch on/off PrintOut.
Definition: GSIWatchers.C:160
Interface to AgataKey.
Int_t idmbs
Definition: GSIWatchers.h:38
virtual void DoCanvas(TCanvas *c, Option_t *)
To be overwritten by real implementation if a canvas is produced.
Definition: GSIWatchers.C:144
virtual Key * GetKey()
To get the Key associated to this frame.
Definition: Frame.h:344
TH1F * fSubEvent_dlen
Definition: GSIWatchers.h:128
virtual void Exec(Option_t *option="")
watch the current frame
Definition: GSIWatchers.C:165
ADF::SharedFP * fMBSFrame
Pointer to the Ancillary Frame as delivered by the ADF Trigger.
Definition: GSIWatchers.h:116
TH1F * fEvent_dlen
Definition: GSIWatchers.h:122
void SetLastExecStatus(Short_t s=0)
reset last status. 0 means no error, 0 < means error, > 0 means ok with conditions ...
Definition: Watchers.h:294
header file for Frame.cpp
virtual UInt_t GetEventNumber() const =0
To get the event number encoded.
MBSWatcher(const char *, const char *, TDirectory *sp_dir=0x0, TDirectory *tag_dir=0x0)
Definition: GSIWatchers.C:111
Short_t trigger
Definition: GSIWatchers.h:36
helper structure to decode the data content of the additional key following the ADF key ...
Definition: GSIWatchers.h:31
A RawFrame gives direct access to the underlying buffer.
Definition: Frame.h:557
virtual Bool_t SetTrigger(ADF::DFTrigger *=0x0)
Set the trigger attached to this watcher.
Definition: GSIWatchers.C:62
header file for AgataKeyFactory.cpp
virtual ~BaseGSIWatcher()
Definition: GSIWatchers.C:58
virtual Bool_t SetTrigger(ADF::DFTrigger *=0x0)
To set the Frames (through a trigger) associated to this watcher.
Definition: GSIWatchers.C:155
BaseGSIWatcher()
Make1D a la GO4.
Definition: GSIWatchers.C:39
TH1F * fSubEvent_control
Definition: GSIWatchers.h:131
TH1F * fSubEvent_type
Definition: GSIWatchers.h:129
virtual BufferIO & RawBuffer()
This method gives access in reading/writing mode to the underlying data buffer.
Definition: Frame.h:580
Short_t subtype
Definition: GSIWatchers.h:34
TH1F * fEvent_trigger
Definition: GSIWatchers.h:125
void TagOn(TObject *)
Add this histogram to the list of tagged histograms.
Definition: Watchers.cpp:901
TH1F * fEvent_subtype
Definition: GSIWatchers.h:124
ADF::SharedFP * fMBSFrame
MBS data are encapsulated in an ADF Frame.
Definition: GSIWatchers.h:51
Base class for a trigger on a data flow.
Definition: Trigger.h:155
ADF::LogMessage & endl(ADF::LogMessage &log)
Base for a watcher on an ancillary (raw) frame @ GSI.
Definition: GSIWatchers.h:47
A watcher filling TTree, Spectra under conditions.
Int_t dlen
Definition: GSIWatchers.h:33
TH1F * fEvent_type
Definition: GSIWatchers.h:123
Char_t * Address()
for classes that needs it to write directly data into it.
Definition: BufferIO.h:98
Bool_t fPrintOut
if true, print out information, otherwise just do spectra
Definition: GSIWatchers.h:119
Short_t type
Definition: GSIWatchers.h:35
TH1F * fSubEvent_subtype
Definition: GSIWatchers.h:130
MBSWatcher, to check the structure of the MBS Frame.
Definition: GSIWatchers.h:112
TH1F * fSubEvent_procid
Definition: GSIWatchers.h:133