AlcapDAQ  1
Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes
TOctalFADCBankReader Class Reference

#include <TOctalFADCBankReader.h>

Public Member Functions

 TOctalFADCBankReader (std::string bankname)
 
std::string GetBankName () const
 
int GetNIslands () const
 
const std::vector
< TOctalFADCIsland * > & 
GetIslandVectorCopy ()
 
void ProcessEvent (EVENT_HEADER *pheader, void *pevent)
 
void ClearEvent ()
 
 TOctalFADCBankReader (std::string bankname)
 
std::string GetBankName () const
 
int GetNIslands () const
 
TOctalFADCIslandat (int index)
 
std::vector< TOctalFADCIsland > & GetIslandVector ()
 
void ProcessEvent (EVENT_HEADER *pheader, void *pevent)
 
void ClearEvent ()
 

Static Public Attributes

static const int kDataBlockSize = 10
 
static const int kSamplesArrayInitialSize = 32
 

Protected Member Functions

 TOctalFADCBankReader ()
 
void StitchIslands ()
 Don't use the unnamed constructor. More...
 
 TOctalFADCBankReader ()
 
void StitchIslands ()
 Don't use the unnamed constructor. More...
 

Protected Attributes

std::string fBankName
 
std::vector< TOctalFADCIsland * > fData
 
std::vector< TOctalFADCIslandfData
 

Detailed Description

Definition at line 10 of file TOctalFADCBankReader.h.

Constructor & Destructor Documentation

TOctalFADCBankReader::TOctalFADCBankReader ( std::string  bankname)
explicit

Definition at line 10 of file TOctalFADCBankReader.cpp.

11  : fBankName(bankname)
12 {
13 }
TOctalFADCBankReader::TOctalFADCBankReader ( )
inlineprotected

Definition at line 26 of file TOctalFADCBankReader.h.

26 {}
TOctalFADCBankReader::TOctalFADCBankReader ( std::string  bankname)
explicit
TOctalFADCBankReader::TOctalFADCBankReader ( )
inlineprotected

Definition at line 28 of file TOctalFADCBankReader.h.

28 {}

Member Function Documentation

TOctalFADCIsland& TOctalFADCBankReader::at ( int  index)
inline

Definition at line 17 of file TOctalFADCBankReader.h.

References fData.

17 { return fData.at(index); }
void TOctalFADCBankReader::ClearEvent ( )

Definition at line 169 of file TOctalFADCBankReader.cpp.

References fData, and i.

Referenced by ProcessEvent().

170 {
171  for(int i=0; i<fData.size(); i++) {
172  if(fData[i]) { delete fData[i]; fData[i] = NULL; }
173  }
174  fData.clear();
175 }
void TOctalFADCBankReader::ClearEvent ( )
inline

Definition at line 21 of file TOctalFADCBankReader.h.

References fData.

21 { fData.clear(); }
std::string TOctalFADCBankReader::GetBankName ( ) const
inline

Definition at line 14 of file TOctalFADCBankReader.h.

References fBankName.

14 { return fBankName; }
std::string TOctalFADCBankReader::GetBankName ( ) const
inline

Definition at line 14 of file TOctalFADCBankReader.h.

References fBankName.

14 { return fBankName; }
std::vector<TOctalFADCIsland>& TOctalFADCBankReader::GetIslandVector ( )
inline

Definition at line 18 of file TOctalFADCBankReader.h.

References fData.

18 {return fData;}
const std::vector<TOctalFADCIsland*>& TOctalFADCBankReader::GetIslandVectorCopy ( )
inline

Definition at line 17 of file TOctalFADCBankReader.h.

References fData.

17 {return fData;}
int TOctalFADCBankReader::GetNIslands ( ) const
inline

Definition at line 16 of file TOctalFADCBankReader.h.

References fData.

16 { return fData.size(); }
int TOctalFADCBankReader::GetNIslands ( ) const
inline

Definition at line 16 of file TOctalFADCBankReader.h.

References fData.

16 { return fData.size(); }
void TOctalFADCBankReader::ProcessEvent ( EVENT_HEADER *  pheader,
void *  pevent 
)

Reads the specified MIDAS bank, interpretting the raw data format into a vector<TOctalFADCIsland*>. Steps to use:

TOctalFADCBankReader reader("BANK"); // BANK is the MIDAS bank name
reader.ProcessEvent(pheader, pevent);
vector<TOctalFADCIsland*> islands = reader.GetIslandVectorCopy();
// Do stuff with islands

Automatically calls ClearEvent() at the beginning of ProcessEvent().

Definition at line 27 of file TOctalFADCBankReader.cpp.

References ClearEvent(), fBankName, fData, i, kDataBlockSize, kSamplesArrayInitialSize, nSamples, printf(), and StitchIslands().

28 {
29  ClearEvent();
30 
31  unsigned char* raw; // Points at the raw data, one byte at a time.
32  int bankSize = bk_locate(pevent,fBankName.c_str(),&raw);
33  int nSamples = bankSize / kDataBlockSize;
34 
35  vector<int> islandSamples;
36  islandSamples.reserve(kSamplesArrayInitialSize);
37 
38  bool allowLowSampls = 1;
39  int islandTimestamp = 0; // time of first 4-sample block in stitched island
40  int lastTimestamp = -1; // To see the end of the last island.
41  for(int i=0; i < nSamples; i++){
42  // data format:
43  //
44  // bits
45  // 79 FADC 0 / 1
46  // 78-52 timestamp
47  // 51-48 overflow
48  // 47-36 sampleB0
49  // 35-24 sampleA0
50  // 23-12 sampleB1
51  // 11-0 sampleA1
52  //
53  // Island samples in the order A1 B1 A0 B0
54 
55  int timestamp = ((raw[i*10+0] & 0x7f) << 20) |
56  (raw[i*10+1] << 12) |
57  (raw[i*10+2] << 4) |
58  (raw[i*10+3] >> 4);
59  bool overflowB0 = ((raw[i*10+3] & 0x08) != 0);
60  bool overflowA0 = ((raw[i*10+3] & 0x04) != 0);
61  bool overflowB1 = ((raw[i*10+3] & 0x02) != 0);
62  bool overflowA1 = ((raw[i*10+3] & 0x01) != 0);
63  int sampleB0 = (overflowB0 << 12) |
64  (raw[i*10+4] << 4) |
65  (raw[i*10+5] >> 4);
66  int sampleA0 = (overflowA0 << 12) |
67  ((raw[i*10+5] & 0xf) << 8) |
68  (raw[i*10+6]);
69  int sampleB1 = (overflowB1 << 12) |
70  (raw[i*10+7] << 4) |
71  (raw[i*10+8] >> 4);
72  int sampleA1 = (overflowA1 << 12) |
73  ((raw[i*10+8] & 0xf) << 8) |
74  (raw[i*10+9]);
75 
76  if(timestamp != lastTimestamp + 1) {
77  if(islandSamples.size() > 4) {
78  // This is a new island, so put the old
79  // island on fData and start again.
80  // Remember, time stamps are actually 4 samples long.
81  fData.push_back(
82  new TOctalFADCIsland(islandTimestamp*4,islandSamples)
83  );
84  islandSamples.clear();
85  }
86  else if (islandSamples.size() <= 4) {
87  islandSamples.clear();
88  }
89  // Ignore islands with 4 or less samples.
90  islandTimestamp = timestamp;
91  }
92 
93  islandSamples.push_back(sampleA1);
94  islandSamples.push_back(sampleB1);
95  islandSamples.push_back(sampleA0);
96  islandSamples.push_back(sampleB0);
97 
98  lastTimestamp = timestamp;
99 
100  //last pulse in the block!
101  if ((i==nSamples-1) && (islandSamples.size() > 4)){
102  fData.push_back(
103  new TOctalFADCIsland(islandTimestamp*4,islandSamples)
104  );
105  }
106 
107 #if 0
108 for(int k=0; k<10; k++){
109 printf("%x ",raw[i*10 + k]);
110 }
111 printf("\n");
112 printf("fadc=%x t=%2x %2x %2x %2x %2x\n", i, timestamp,
113 sampleA1, sampleB1, sampleA0,sampleB0);
114 #endif
115 
116  }
117 
118  if(fData.size()>1)
119  {
120  //Time sort islands
121  std::sort(fData.begin(), fData.end(),TOctalFADCIsland::TimeSortFADCIslands());
122  StitchIslands();
123  } // Some Pulses are split over two separate islands. Put them together again
124  // printf(".............. FADC islands sorted .............\n");
125 }
void TOctalFADCBankReader::ProcessEvent ( EVENT_HEADER *  pheader,
void *  pevent 
)
void TOctalFADCBankReader::StitchIslands ( )
protected

Don't use the unnamed constructor.

Definition at line 127 of file TOctalFADCBankReader.cpp.

References fData, TOctalFADCIsland::GetNSamples(), TOctalFADCIsland::GetTime(), i, last, and samples.

Referenced by ProcessEvent().

128 {
129 
130  vector<TOctalFADCIsland*> fData_temp;
131  //fData_temp.clear();
132 
133  TOctalFADCIsland* last = fData.at(0);
134  //if(fData.size()>1){printf("Size first Island: %d\n",fData.at(1).GetNSamples());}
135  fData_temp.push_back(last);
136  int counter_temp = 0; int counter = 0;
137 
138  for(unsigned int i = 1; i<fData.size(); i++)
139  {
140  if(fData.at(i)->GetTime() - (last->GetTime() + last->GetNSamples()) >2 )
141  {
142  last = fData.at(i);
143  fData_temp.push_back(last);
144  counter_temp++;
145  }
146  else
147  {
148  vector<int>& samples = fData_temp.at(counter_temp)->GetSampleVector();
149 
150  for(int j=0;j<fData.at(i)->GetNSamples();j++)
151  {
152  samples.push_back(fData.at(i)->GetSampleVector().at(j));
153  }
154  counter++;
155  last = fData_temp.at(counter_temp);
156  }
157  }
158 
159  //printf("Size original: %d, size stitched: %d, counter %d\n",fData.size(),fData_temp.size(),counter);
160 
161  fData.clear();
162  fData = fData_temp;
163  fData_temp.clear();
164 
165  //printf("Size new: %d, size temp: %d, counter %d , counter_temp %d\n",fData.size(),fData_temp.size(),counter,counter_temp);
166 
167 }
void TOctalFADCBankReader::StitchIslands ( )
protected

Don't use the unnamed constructor.

Field Documentation

std::string TOctalFADCBankReader::fBankName
protected

Definition at line 28 of file TOctalFADCBankReader.h.

Referenced by GetBankName(), and ProcessEvent().

std::vector<TOctalFADCIsland*> TOctalFADCBankReader::fData
protected
std::vector<TOctalFADCIsland> TOctalFADCBankReader::fData
protected

Definition at line 31 of file TOctalFADCBankReader.h.

static const int TOctalFADCBankReader::kDataBlockSize = 10
static

Definition at line 22 of file TOctalFADCBankReader.h.

Referenced by ProcessEvent().

static const int TOctalFADCBankReader::kSamplesArrayInitialSize = 32
static

Definition at line 23 of file TOctalFADCBankReader.h.

Referenced by ProcessEvent().


The documentation for this class was generated from the following files: