GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ReadDaqAlone.C
Go to the documentation of this file.
1 // Macro to read trc files
2 // and put in one single trc file
3 // Ch. Finck, June 09.
4 
5 
6 #if !defined(__CINT__) || defined(__MAKECINT__)
7 
8 #include <Riostream.h>
9 #include "TString.h"
10 #include "TH1F.h"
11 #include "TH2F.h"
12 #include "TFile.h"
13 #include "TTree.h"
14 
15 #include "BufferGANIL.h"
16 
17 #endif
18 
26 const Int_t MaxValue = 96;
27 const Int_t dim = 16384;
28 
29 UInt_t value[MaxValue];
30 TTree *oak = new TTree("TreeValues","Parameters tree");
31 TH1F* histo[MaxValue];
32 
33 void MakeHisto(UShort_t* event, UShort_t size )
34 {
35  for (Int_t i = 0; i < size/2; ++i) {
36 
37  UShort_t id = event[i*2];
38  value[id] = event[i*2+1];
39  const Char_t* name = BufferGANIL::GetModuleName(id);
40 
41  if (histo[id] == 0x0) {
42  histo[id] = new TH1F(Form("h%s",name), name, dim/4, 0, dim/4);
43  }
44  histo[id]->Fill(value[id]);
45 
46  if (!oak->GetBranch(name))
47  oak -> Branch(name, &value[id], Form("%s/i", name));
48  }
49 
50  oak->Fill();
51 }
52 
53 void ReadDaqAlone(TString file = "run_0002.dat")
54 {
55 
56  TString rootFileName = file + ".root";
57 
58  TFile* fileRoot = new TFile(rootFileName,"recreate");
59  TString fileNameIn;
60  UShort_t* event;
61  UShort_t size;
62 
63  BufferGANIL* bufferGANIL = new BufferGANIL();
64 
65  fileNameIn = file;
66 
67  FILE* in;
68 
69  Char_t buf[dim];
70 
71  if ( !(in = fopen (fileNameIn.Data(),"r") ) ) {
72  printf("file %s not found\n", fileNameIn.Data());
73  return;
74  }
75 
76  Bool_t ok = false;
77  // read header
78  while (fread(buf,sizeof(char),dim,in)) {
79  memcpy(bufferGANIL->GetBuffer(),buf, dim);
80  ok = bufferGANIL->InitReading();
81  if (!ok) continue;
82  do {
83  event = bufferGANIL->NextEvent(size);
84  if (event)
85  MakeHisto(event, size);
86  } while (event != 0x0);
87 
88  }
89 
90  fclose(in );
91 
92  oak->Write();
93 
94  for (Int_t i = 0; i < MaxValue; ++i) {
95  if (histo[i])
96  histo[i]->Write();
97  }
98 
99  fileRoot->Close();
100 }
printf("******************************************************************** \n")
bool InitReading()
Definition: BufferGANIL.C:91
UInt_t value[MaxValue]
Definition: ReadDaqAlone.C:29
TH1F * histo[MaxValue]
Definition: ReadDaqAlone.C:31
void ReadDaqAlone(TString file="run_0002.dat")
Definition: ReadDaqAlone.C:53
void MakeHisto(UShort_t *event, UShort_t size)
Definition: ReadDaqAlone.C:33
unsigned short * NextEvent(unsigned short &)
Definition: BufferGANIL.C:137
const Int_t dim
Definition: ReadDaqAlone.C:27
Char_t * GetBuffer()
Definition: BufferGANIL.h:74
TTree * oak
Definition: ReadDaqAlone.C:30
const Int_t size
Definition: BenchIO.C:24
const Int_t MaxValue
Macro that reads block wise (16kB) and decodes it with the help of BufferGanil class.
Definition: ReadDaqAlone.C:26
Simple Class thats decode Ganil DAQ format for simple VME module as QDC, ADC, TDC, etc...
Definition: BufferGANIL.h:21
static const Char_t * GetModuleName(UShort_t add)
Definition: BufferGANIL.C:84