Subversion Repositories f9daq

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
5 f9daq 1
// By ROOT version 5.17/02 on 2008-03-13 06:46:41
2
 
3
#ifndef ROOT_TGDockableFrame
4
#include "TGDockableFrame.h"
5
#endif
6
#ifndef ROOT_TGMenu
7
#include "TGMenu.h"
8
#endif
9
#ifndef ROOT_TGMdiDecorFrame
10
#include "TGMdiDecorFrame.h"
11
#endif
12
#ifndef ROOT_TG3DLine
13
#include "TG3DLine.h"
14
#endif
15
#ifndef ROOT_TGMdiFrame
16
#include "TGMdiFrame.h"
17
#endif
18
#ifndef ROOT_TGMdiMainFrame
19
#include "TGMdiMainFrame.h"
20
#endif
21
#ifndef ROOT_TGuiBldHintsButton
22
#include "TGuiBldHintsButton.h"
23
#endif
24
#ifndef ROOT_TGMdiMenu
25
#include "TGMdiMenu.h"
26
#endif
27
#ifndef ROOT_TGListBox
28
#include "TGListBox.h"
29
#endif
30
#ifndef ROOT_TGNumberEntry
31
#include "TGNumberEntry.h"
32
#endif
33
#ifndef ROOT_TGScrollBar
34
#include "TGScrollBar.h"
35
#endif
36
#ifndef ROOT_TGuiBldHintsEditor
37
#include "TGuiBldHintsEditor.h"
38
#endif
39
#ifndef ROOT_TRootBrowser
40
#include "TRootBrowser.h"
41
#endif
42
#ifndef ROOT_TGFrame
43
#include "TGFrame.h"
44
#endif
45
#ifndef ROOT_TGFileDialog
46
#include "TGFileDialog.h"
47
#endif
48
#ifndef ROOT_TGShutter
49
#include "TGShutter.h"
50
#endif
51
#ifndef ROOT_TGButtonGroup
52
#include "TGButtonGroup.h"
53
#endif
54
#ifndef ROOT_TGCanvas
55
#include "TGCanvas.h"
56
#endif
57
#ifndef ROOT_TGFSContainer
58
#include "TGFSContainer.h"
59
#endif
60
#ifndef ROOT_TGButton
61
#include "TGButton.h"
62
#endif
63
#ifndef ROOT_TGuiBldEditor
64
#include "TGuiBldEditor.h"
65
#endif
66
#ifndef ROOT_TGTextEdit
67
#include "TGTextEdit.h"
68
#endif
69
#ifndef ROOT_TGFSComboBox
70
#include "TGFSComboBox.h"
71
#endif
72
#ifndef ROOT_TGLabel
73
#include "TGLabel.h"
74
#endif
75
#ifndef ROOT_TGView
76
#include "TGView.h"
77
#endif
78
#ifndef ROOT_TRootGuiBuilder
79
#include "TRootGuiBuilder.h"
80
#endif
81
#ifndef ROOT_TGTab
82
#include "TGTab.h"
83
#endif
84
#ifndef ROOT_TGListView
85
#include "TGListView.h"
86
#endif
87
#ifndef ROOT_TGSplitter
88
#include "TGSplitter.h"
89
#endif
90
#ifndef ROOT_TGStatusBar
91
#include "TGStatusBar.h"
92
#endif
93
#ifndef ROOT_TGListTree
94
#include "TGListTree.h"
95
#endif
96
#ifndef ROOT_TGToolTip
97
#include "TGToolTip.h"
98
#endif
99
#ifndef ROOT_TGToolBar
100
#include "TGToolBar.h"
101
#endif
102
#ifndef ROOT_TRootEmbeddedCanvas
103
#include "TRootEmbeddedCanvas.h"
104
#endif
105
#ifndef ROOT_TCanvas
106
#include "TCanvas.h"
107
#endif
108
#ifndef ROOT_TGuiBldDragManager
109
#include "TGuiBldDragManager.h"
110
#endif
111
 
112
#include "Riostream.h"
113
#include "TApplication.h"
114
#include "TROOT.h"
115
#include "TSystem.h"
116
#include "TGraph.h"
117
#include "TH1F.h"
118
#include "daq.h"
119
 
120
TGTextButton   *gTextButton[10];
121
TCanvas        *fCanvas;
122
TGMainFrame    *fMain;
123
TGTextEntry    *gFilename;
124
TGNumberEntry  *gPedestal;
125
TGNumberEntry  *gCh;
126
TGNumberEntry  *gMaxEve;
127
TGNumberEntry  *gNeve;
128
TGTextEntry    *gTimeDisplay;
129
TGCheckButton  *gCheckButton;
130
 
131
 
132
TRootEmbeddedCanvas *gCanvas;
133
#define MAXCH 32
134
TH1F* gHisto[MAXCH];
135
daq * gDaq;
136
#define WINDOW_NAME "ADC CAEN V965"
137
//----------------------------------------------------
138
int UIRDimming(int state){
139
  switch (state) {
140
  case 0:
141
    gTextButton[0]->SetEnabled(0);
142
    gTextButton[1]->SetEnabled(1);
143
    gTextButton[2]->SetEnabled(0);
144
 
145
    break;
146
 
147
  case 1:
148
    gTextButton[0]->SetEnabled(0);
149
    gTextButton[1]->SetEnabled(0);
150
    gTextButton[2]->SetEnabled(1);
151
 
152
    break;
153
 
154
  case 2:
155
    gTextButton[0]->SetEnabled(1);
156
    gTextButton[1]->SetEnabled(1);
157
    gTextButton[2]->SetEnabled(0);
158
    break;
159
 
160
  default:
161
    break;
162
  }
163
  return 0;
164
}
165
 
166
int fDebug;
167
void GetDebug(){
168
  if ( gCheckButton->IsOn() ) fDebug=1;
169
  else fDebug=0;
170
}
171
 
172
int GetTime(char *x){
173
   int ret;
174
   time_t rawtime;
175
   static time_t oldtime=-1;
176
    struct tm * timeinfo;
177
    time ( &rawtime );
178
    ret =  (oldtime==rawtime);
179
    timeinfo = localtime ( &rawtime );
180
    sprintf(x,"%s",asctime (timeinfo));
181
    int len=strlen(x);
182
    if (len) x[len-1]=0;
183
    return ret;
184
}
185
void MyTimer(){
186
    char cmd[100];
187
    if (!GetTime(cmd)){
188
      if (gTimeDisplay) gTimeDisplay->SetText(cmd);
189
      if (gCanvas){
190
	gCanvas->GetCanvas()->Modified();
191
	gCanvas->GetCanvas()->Update();
192
      }
193
    }
194
}
195
 
196
//----------------------------------------------------
197
// thread function
198
int gStop=0;
199
#define BSIZE 10000
200
unsigned long gBuf[BSIZE];
201
void Run(){
202
  printf("Start of Run\n" );
203
 
204
  // odpremo datoteko za pisanje
205
  int counters[10]={0,0,0,0,0, 0,0,0,0,0};
206
  char names[20][20]={"CAENV 1290","CAEN V965","LC2277","LC2277","LC2277"};
207
 
208
  char fname[128];
209
  sprintf(fname,"%s.dat",gFilename->GetText());
210
  FILE *fp=fopen(fname,"w");
211
  int neve  = (int) gMaxEve->GetNumber();
212
  int hdr[4]={1};
213
 
214
  if (gDaq) gDaq->fStop=0;
215
  // zajem zeljenega kolicine podatkov
216
  for (int n=0;n<neve;n++){
217
    if (!gDaq) break;
218
    int nb = gDaq->event(gBuf,BSIZE,counters,1);
219
    if (gDaq->fStop) break;
220
    // zapis v datoteko
221
    hdr[1]=nb+4*sizeof(int);
222
    hdr[2]=time(NULL);
223
    hdr[3]=n;
224
 
225
    fwrite(hdr,   sizeof(int),4 , fp);
226
    if (nb) fwrite(gBuf,   1,nb, fp);
227
    // napolni histograme
228
   int nint= nb/4;
229
 
230
   int ii=0;
231
 
232
   while (ii<nint){
233
 
234
   int recid=gBuf[ii++];
235
   int len  =gBuf[ii++];
236
   unsigned int *dbuf=       (unsigned int *)&gBuf[ii];
237
   if (n%1000==0) printf("%d 0x%03x Len=%d\n",n,recid,len);
238
   unsigned short edge;
239
 
240
    if (recid==0x130){
241
        for (int i=0; i<len; i++) {
242
          int dtype=(dbuf[i]>>25)&0x3;
243
          if (dtype==0) {
244
            int ch=(dbuf[i]>>17)&0xf;
245
            if (2*ch<MAXCH) {
246
              int rg=(dbuf[i]>>16)&0x1;
247
              int adc=dbuf[i]&0xfff;
248
              gHisto[2*ch+rg]->Fill(adc);
249
              //  printf("V965 0x%08x nev=%4d %d. [ch=%2d] range=%d data=%d \n",dbuf[i],n,i,ch,rg,adc);
250
            }
251
          }
252
        }
253
     } // if (recid==0x130)
254
      ii+=len;
255
   }
256
    /*
257
    // decode
258
 
259
    int nint=nb/sizeof(int);
260
 
261
    for (int i=0;i<nint;i++){
262
       unsigned short tdc =   gBuf[i]&0xFFFF;
263
       unsigned short ch  =  (gBuf[i] >> 17 ) &0x1F;
264
       unsigned short edge = (gBuf[i] >> 16 ) &0x1;
265
       if (edge && ch < MAXCH) gHisto[ch]->Fill(tdc);
266
       if (fDebug) printf("nev=%4d %d. [ch=%2d] egde=%d data=%d",n,i,ch,edge,tdc);
267
    }
268
    */
269
   gSystem->ProcessEvents();
270
   MyTimer();
271
   gNeve->SetNumber(n);
272
  }
273
  fclose(fp);
274
  UIRDimming(2);
275
  printf("End of MyThread neve=%d\n",neve);
276
 
277
}
278
 
279
 
280
int save2ascii(){
281
         if (!gHisto[0]) return 0;
282
         char fname[128];
283
         sprintf(fname,"%s.txt",gFilename->GetText());
284
 	 FILE *fp= fopen(fname, "w");
285
 	 fprintf(fp, "%s\n",WINDOW_NAME);
286
         char cmd[128];
287
         GetTime(cmd);
288
 	 fprintf(fp, "Shranjeno: %s\n\n", cmd );
289
 	 fprintf(fp, "Kanal hid=")	;
290
 	 for (int j=0;j<MAXCH;j++)  fprintf(fp, "%d\t",j);
291
 	 fprintf(fp, "\n-------------------------------------------------\n");
292
 	 for (int i=0;i<gHisto[0]->GetNbinsX();i++){
293
 	   fprintf(fp, "%d\t",i);
294
 	   for (int j=0;j<MAXCH;j++) fprintf(fp, "%d\t",(int) gHisto[j]->GetBinContent(i+1));
295
 	   fprintf(fp, "\n");
296
 	 }
297
 	 fclose(fp);
298
 	 printf("Histogram content is dumped to the file %s\n",fname);
299
 	 return 0;
300
 }
301
 
302
void MyEventHandler(int i){
303
 
304
  UIRDimming(i);
305
 
306
  switch (i) {
307
  case 0: // Init
308
    gDaq->fPedestal = (int)(gPedestal->GetNumber());
309
    gDaq->init();
310
    break;
311
  case 1: // Start
312
    Run();
313
  case 2: // Stop
314
    gDaq->fStop=1;
315
  case 3: // ReDraw
316
    gCanvas->GetCanvas()->Modified();
317
    gCanvas->GetCanvas()->Update();
318
    break;
319
  case 4: // Clear
320
    for (int j=0;j<MAXCH;j++) if (gHisto[j]) gHisto[j]->Reset();
321
    break;
322
  case 5: // Save
323
    save2ascii();
324
    break;
325
  case 6: // Print
326
    gCanvas->GetCanvas()->SaveAs("zivljenjski_cas_mionov.pdf");
327
    break;
328
  case 7: // exit
329
    gApplication->Terminate(0);
330
    break;
331
  }
332
 
333
}
334
 
335
int Redraw(long val=0){
336
  unsigned int ch= (unsigned int)(gCh->GetNumber());
337
  if (ch<MAXCH && gHisto[ch]) {
338
        gCanvas->GetCanvas()->cd();
339
	      gHisto[ch]->Draw();
340
        gCanvas->GetCanvas()->Modified();
341
        gCanvas->GetCanvas()->Update();
342
  } else {
343
    if (gCh->GetNumber()>=MAXCH) gCh->SetNumber(MAXCH-1);
344
    if (gCh->GetNumber()< 0)     gCh->SetNumber(0);
345
  }
346
  return 0;
347
}
348
//----------------------------------------------------
349
 
350
int gui(){
351
 
352
  for (int i=0;i<MAXCH;i++){
353
    char hname[50];
354
    sprintf(hname,"Ch. %d Rg.%d;ADC;N",i/2,i%2);
355
    char hn[50];
356
    sprintf(hn,"ch%d",i);
357
    gHisto[i]   = new TH1F(hn,hname,4096,-0.5,4095.5);
358
  }
359
  gDaq= new daq();
360
  fMain = new TGMainFrame(0,800,800);
361
  TGHorizontalFrame *fH=new TGHorizontalFrame(fMain,800,400);
362
  //------------------------------------------------------------
363
  TGLayoutHints *f0= new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2);
364
  TGLayoutHints *layout2= new TGLayoutHints(kLHintsLeft | kLHintsTop,20,20,20,20);
365
  // gumbi
366
 
367
  int nbut=8;
368
  const char *names[10]={"Init","Start","Stop","Refresh","Clear","Save", "Print" , "Exit"};
369
  for (int i=0;i<nbut;i++){
370
 
371
    gTextButton[i]= new TGTextButton(fH, names[i]);
372
    gTextButton[i]->SetTextJustify(36);
373
    gTextButton[i]->SetMargins(0,0,0,0);
374
    gTextButton[i]->SetWrapLength(-1);
375
    gTextButton[i]->Resize(50,22);
376
    fH->AddFrame(gTextButton[i], layout2);
377
    char cmd[50];
378
    sprintf(cmd,"MyEventHandler(=%d)",i);
379
    TQObject::Connect(gTextButton[i],"Clicked()",0,0,cmd);
380
  }
381
 
382
  gCheckButton =  new TGCheckButton( fH,"Debug");
383
  gCheckButton->Resize(50,22);
384
  TQObject::Connect(gCheckButton,"Clicked()", 0, 0 , "GetDebug()");
385
  gCheckButton->SetState(kButtonDown);
386
  fH->AddFrame(gCheckButton, f0);
387
 
388
  fMain->AddFrame(fH    , f0);
389
  //---------------------------------------------------------
390
  // ura
391
  TGLabel *lab1;
392
  fH=new TGHorizontalFrame(fMain,800,200);
393
  lab1 = new TGLabel( fH ,"Time:");
394
  fH->AddFrame(lab1, f0);
395
  gTimeDisplay =  new TGTextEntry( fH,"");
396
  gTimeDisplay->Resize(200,22);
397
  fH->AddFrame(gTimeDisplay, f0);
398
  fMain->AddFrame(fH    , f0);
399
  //---------------------------------------------------------
400
  // inputi
401
  fH=new TGHorizontalFrame(fMain,800,200);
402
  lab1 = new TGLabel( fH ,"Filename:");
403
  fH->AddFrame(lab1, f0);
404
  gFilename =  new TGTextEntry( fH,"filename");
405
  gFilename->Resize(200,22);
406
  fH->AddFrame(gFilename, f0);
407
  fMain->AddFrame(fH    , f0);
408
  //---------------------------------------------------------
409
  fH=new TGHorizontalFrame(fMain,800,200);
410
  lab1 = new TGLabel( fH ,"ADC Pedestal:");
411
  fH->AddFrame(lab1, f0);
412
  gPedestal =  new TGNumberEntry( fH,100);
413
  gPedestal->Resize(100,22);
414
  fH->AddFrame(gPedestal, f0);
415
  fMain->AddFrame(fH    , f0);
416
  //---------------------------------------------------------
417
  fH=new TGHorizontalFrame(fMain,800,200);
418
  lab1 = new TGLabel( fH ,"N of events to acquire:");
419
  fH->AddFrame(lab1, f0);
420
  gMaxEve =  new TGNumberEntry( fH,10000);
421
  gMaxEve->Resize(100,22);
422
  fH->AddFrame(gMaxEve, f0);
423
  fMain->AddFrame(fH    , f0);
424
  //---------------------------------------------------------
425
  fH=new TGHorizontalFrame(fMain,800,200);
426
  lab1 = new TGLabel( fH ,"Number of events:");
427
  fH->AddFrame(lab1, f0);
428
  gNeve =  new TGNumberEntry( fH,0);
429
  gNeve->Resize(100,22);
430
  fH->AddFrame(gNeve, f0);
431
  fMain->AddFrame(fH    , f0);
432
  //---------------------------------------------------------
433
  // canvas
434
  fH=new TGHorizontalFrame(fMain,800,200);
435
  gCanvas = new TRootEmbeddedCanvas ("gCanvas",fH,800,400);
436
  fH->AddFrame(gCanvas, f0);
437
  fMain->AddFrame(fH   , f0);
438
  //------------------------------------------------------------
439
  fH=new TGHorizontalFrame(fMain,800,200);
440
  lab1 = new TGLabel( fH ,"Channel number (0..31):");
441
  fH->AddFrame(lab1, f0);
442
  gCh =  new TGNumberEntry( fH,0);
443
  fH->AddFrame(gCh, f0);
444
  TQObject::Connect(gCh,"ValueSet(Long_t)",0,0,"Redraw(Long_t )");
445
 
446
  fMain->AddFrame(fH    , f0);
447
  //------------------------------------------------------------
448
  fMain->SetWindowName(WINDOW_NAME);
449
  fMain->MapSubwindows();
450
  fMain->Resize(fMain->GetDefaultSize());
451
  fMain->MapWindow();
452
  Redraw();
453
  GetDebug();
454
  return 0;
455
}