GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RancLegnaroWatchers.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 "RancLegnaroWatchers.h"
22 
23 #ifndef _MetaWatchers
24 #include "MetaWatchers.h"
25 #endif
26 
27 #include "TMath.h"
28 
30 
31 RancLegnaroWatcher::RancLegnaroWatcher(const char *name, const char *title, TDirectory *sp_dir, TDirectory *tag_dir):
32  WatcherWithTag(name,title,sp_dir,tag_dir),
33  fWhichRanc(1u),
34  fFrame(0x0)
35 {
36 }
37 
39 {
40 }
41 
43 {
44  if ( Watcher::GetFromTrigger(trigger, "data:ranc0", fFrame) ) {
45  fWhichRanc = 0u;
46  return true;
47  }
48  else return Watcher::GetFromTrigger(trigger, "data:ranc1", fFrame);
49 }
50 
51 void RancLegnaroWatcher::Exec(Option_t */*option*/)
52 {
53  if ( gDebug > 3 )
54  fLog << info << "RancLegnaroWatcher::Exec is called 1 \n";
55 
56  // be sure the frame has been set properly
57  if ( fFrame == 0x0 || !fFrame->IsValid() )
58  { SetLastExecStatus(1); return; }
59 
60  // get the data part of the frame
61  UInt_t nbbytes = fFrame->GetFrame()->Read() / 4u;
62 
63  // extract the arrar from the frame
64  const BufferIO *buf = fFrame->GetFrame()->GetRealBuffer();
65  buf->SetOffset();
66 
67  switch ( fWhichRanc ) {
68  case 0u:
69  buf->Export((Char_t*)rawBufI, gMaxSlots*gMaxChannels*sizeof(UInt_t));
71  for (UInt_t i = 0u; i < gMaxSlots*gMaxChannels ; i++) {
72  rawBuf[i] = Float_t(rawBufI[i]);
73  }
74  break;
75  case 1u:
76  buf->Export((Char_t*)&lenrawBuf, sizeof(UInt_t));
77  if ( lenrawBuf < nbbytes && lenrawBuf < gMaxSlots*gMaxChannels+gExtraSize )
78  buf->Export((Char_t*)rawBuf, lenrawBuf*sizeof(Float_t));
79  else
80  lenrawBuf = 0; // wrong reading of the frame
81  break;
82  default:
83  break;
84  }
85 }
86 
87 // DisplayRancLegnaro Watcher //////////////////////////////////////////////////////////////
88 
90 
91 DisplayRancLegnaro::DisplayRancLegnaro(const char *name, const char *title,TDirectory *sp_dir, TDirectory *tag_dir):
92  RancLegnaroWatcher(name,title,sp_dir,tag_dir),
93  fLength(0x0),
94  fAllSlots(),
95  fListAdded()
96 {
97  fLength = MakeTH1<TH1F>("Length","Length Of the DisplayRancLegnaro buffer",100,0,200);
98  fAllSlots = MakeTH2<TH2F>("AllSlots","Distribution per slot",gMaxSlots*gMaxChannels+10,0,gMaxSlots*gMaxChannels+10,1024,0,4096);
99 }
100 
101 /*
102 DisplayRancLegnaro::~DisplayRancLegnaro()
103 {
104 }
105 */
106 
107 void DisplayRancLegnaro::DoCanvas(TCanvas * /*c*/, Option_t *o)
108 {
109 // static UShort_t nb_pad_x = 3, nb_pad_y = 3;
110 
111  TString option = o;
112  if ( option == "" ) {
113  fAllSlots->Draw();
114  }
115  if ( option == "mat" ) {
116  }
117 }
118 
119 void DisplayRancLegnaro::AddMatrix(UShort_t ch1, UShort_t ch2, UShort_t dch1, UShort_t dch2, Int_t binx, Double_t xmin, Double_t xmax, Int_t biny, Double_t ymin, Double_t ymax)
120 {
121  if ( !(ch1 < gMaxSlots*gMaxChannels+gExtraSize) )
122  return;
123  if ( !(ch2 < gMaxSlots*gMaxChannels+gExtraSize) )
124  return;
125 
126  Int_t ech1 = TMath::Min( ch1 + dch1, gMaxSlots*gMaxChannels+gExtraSize ) ;
127  Int_t ech2 = TMath::Min( ch2 + dch2, gMaxSlots*gMaxChannels+gExtraSize ) ;
128 
129  // check some consistencies
130 
131  for (Int_t ix = ch1; ix < ech1; ix++) {
132  for (Int_t jx = ch2; jx < ech2; jx++) {
133 
134  // check if already there
135  Bool_t to_add = true;
136 
137  for (size_t i = 0; i < fListAdded.size(); i++) {
138  if ( fListAdded[i].first.first == ix && fListAdded[i].first.second == jx )
139  { to_add = false; break;}
140  if ( fListAdded[i].first.first == jx && fListAdded[i].first.second == ix )
141  { to_add = false; break;}
142  }
143  if ( to_add ) {
144  std::pair < std::pair<UShort_t, UShort_t> , TH2F *> bidim;
145  bidim.first.first = ix;
146  bidim.first.second = jx;
147 
148  TString tmp = Form("DisplayRanc_%d_%d",ix,jx);
149  bidim.second = MakeTH2<TH2F>(tmp.Data(),tmp.Data(),binx,xmin,xmax,biny,ymin,ymax);
150 
151  fListAdded.push_back( bidim );
152  }
153  }
154  }
155 }
156 
157 
158 void DisplayRancLegnaro::Exec(Option_t *option)
159 {
160  if ( gDebug > 3 )
161  fLog << info << "DisplayRancLegnaro::Exec is called \n";
162 
163  // fill the array of floats, check if something goes wrong
165  RancLegnaroWatcher::Exec(option);
166  if ( GetLastExecStatus() != 0 )
167  return;
168 
169  // fill the specta
170  fLength->Fill(lenrawBuf);
171 
172  // lenrawBuf set to 0 in case it is not read properly in the ancillary Frame
173  if ( lenrawBuf == 0u )
174  return;
175 
176  for (UInt_t i = 0u; i < lenrawBuf; i++ )
177  fAllSlots->Fill(i,rawBuf[i]);
178 
179  for (size_t i = 0; i < fListAdded.size(); i++) {
180  if ( !(fListAdded[i].first.first < lenrawBuf) )
181  continue;
182  if ( !(fListAdded[i].first.second < lenrawBuf) )
183  continue;
184 
185  fListAdded[i].second->Fill(rawBuf[fListAdded[i].first.first],rawBuf[fListAdded[i].first.second]);
186  }
187 }
188 
189 // ReadAncVertex Watcher //////////////////////////////////////////////////////////////
190 
191 /*
192 ClassImp(ReadAncVertex);
193 
194 ReadAncVertex::ReadAncVertex(const char *name, const char *title, TDirectory *sp_dir, TDirectory *tag_dir) :
195  RancLegnaroWatcher(name,title,sp_dir,tag_dir),
196  VertexBuilder()
197 {
198  fVertexFrame = MainFrameFactory::theMainFactory().
199  NewSharedFrame( FactoryItem("Agata","meta:vertex",Version(0,0)), FactoryItem("Agata","meta:vertex",Version(1,1)) );
200 
201  fIsToBeDeleted = true;
202 }
203 
204 void ReadAncVertex::Exec(Option_t *option)
205 {
206  Double_t x, y, z, Dx, Dy, Dz, beta;
207 
208  SetLastExecStatus(0);
209  RancLegnaroWatcher::Exec(option);
210  if ( GetLastExecStatus() != 0 )
211  return;
212 
213  if ( lenrawBuf < 6 )
214  return;
215 
216  x = rawBuf[lenrawBuf-6 + 0];
217  y = rawBuf[lenrawBuf-6 + 1];
218  z = rawBuf[lenrawBuf-6 + 2];
219  x = y = z = 0;
220  Dx = rawBuf[lenrawBuf-3 + 0];
221  Dy = rawBuf[lenrawBuf-3 + 1];
222  Dz = rawBuf[lenrawBuf-3 + 2];
223 
224  beta = TMath::Sqrt(Dx*Dx + Dy*Dy + Dz*Dz);
225 
226 // if ( beta > 0.0 )
227 // cout << " -- " << Dx << " " << Dy << " " << Dz << endl;
228 
229  // fill the current vertex
230  VertexInterface *gdata = GetVertex();
231  gdata->SetPosition(x,y,z);
232  gdata->SetDirection(Dx,Dy,Dz);
233  gdata->SetBeta(beta);
234 }
235 
236 */
virtual Bool_t IsValid() const
true if it is a valid pointer
Definition: Frame.h:616
virtual Frame * GetFrame() const
Definition: Frame.h:625
virtual UInt_t Read()
It reads the content into dedicated structures from the Frame (data part)
Definition: Frame.h:199
static const UShort_t gMaxSlots
virtual const BufferIO * GetRealBuffer() const =0
give access to the underlying buffer of the data part
Base for a watcher on an ancillary (raw) frame.
virtual Bool_t SetTrigger(ADF::DFTrigger *=0x0)
Set the trigger attached to this watcher.
To Display the content of raw ancillary frames ranc0 and ranc1 as defined @ Legnaro.
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
DisplayRancLegnaro(const char *, const char *, TDirectory *sp_dir=0x0, TDirectory *tag_dir=0x0)
LogMessage & info(LogMessage &)
manipulator to modify the LogMessage
LogMessage fLog
Definition: Watchers.h:86
static const UShort_t gExtraSize
virtual UInt_t Export(Char_t *, UInt_t) const
Export this buffer to an array.
Definition: BufferIO.h:694
static const UShort_t gMaxChannels
UInt_t rawBufI[gMaxSlots *gMaxChannels+gExtraSize]
ADF::SharedFP * fFrame
Float_t rawBuf[gMaxSlots *gMaxChannels+gExtraSize]
Base class for a trigger on a data flow.
Definition: Trigger.h:155
virtual void Exec(Option_t *option="")
watch the current frame
virtual void Exec(Option_t *option="")
watch the current frame
virtual void DoCanvas(TCanvas *c, Option_t *)
To be overwritten by real implementation if a canvas is produced.
Short_t GetLastExecStatus() const
to get the last status
Definition: Watchers.h:300
RancLegnaroWatcher(const char *, const char *, TDirectory *sp_dir=0x0, TDirectory *tag_dir=0x0)
ClassImp(RancLegnaroWatcher)
void AddMatrix(UShort_t ch1, UShort_t ch2, UShort_t DeltaCh1=1, UShort_t DeltaCh2=1, Int_t binx=512, Double_t xmin=0, Double_t xmax=4096, Int_t biny=512, Double_t ymin=0, Double_t ymax=4096)
Add a matrix between two elements.
UInt_t SetOffset(UInt_t off=0u) const
change the current position.
Definition: BufferIO.cpp:122