ROOTANA
TV1190Data.cxx
Go to the documentation of this file.
1 #include "TV1190Data.hxx"
2 
3 #include <iostream>
4 
5 
6 void TDCMeasurement::SetTrailer(uint32_t trailer){
7  tdc_trailer_word = trailer;
8 }
9 
10 
11 /// Get the TDC number
12 uint32_t TDCMeasurement::GetTDCNumber() const {
13  if(HasTDCHeader())
14  return ((tdc_header_word & 0x3000000) >> 24 );
15  if(HasTDCTrailer())
16  return ((tdc_trailer_word & 0x3000000) >> 24 );
17  return 0xdeadbeef;
18 }
19 
20 /// Get Event ID
21 uint32_t TDCMeasurement::GetEventID() const {
22  if(HasTDCHeader())
23  return ((tdc_header_word & 0xfff000) >> 12 );
24  if(HasTDCTrailer())
25  return ((tdc_trailer_word & 0xfff000) >> 12 );
26  return 0xdeadbeef;
27 }
28 
29 /// Get Bunch ID
30 uint32_t TDCMeasurement::GetBunchID() const {
31  if(HasTDCHeader())
32  return ((tdc_header_word & 0xfff));
33  return 0xdeadbeef;
34 }
35 
36  /// Get Errors
37 uint32_t TDCMeasurement::GetErrors() const{
38  if(HasTDCErrorWord())
39  return ((tdc_error_error & 0x7fff));
40  return 0xdeadbeef;
41 
42 
43 }
44 
45 
46 TV1190Data::TV1190Data(int bklen, int bktype, const char* name, void *pdata):
47  TGenericData(bklen, bktype, name, pdata)
48 {
49 
50  // Do decoding. Decoding is complicated by the fact that there can be
51  // multiple events in the same bank. So need to find and save multiple
52  // event headers, trailers.
53 
54 
55  // Do some sanity checking.
56  // Make sure first word has right identifier
57  if( (GetData32()[0] & 0xf8000000) != 0x40000000)
58  std::cerr << "First word has wrong identifier; first word = 0x"
59  << std::hex << GetData32()[0] << std::dec << std::endl;
60 
61  // Scan through the data, saving information as we go.
62  int found_trailer_word = -1;
63  // fExtendedTriggerTimeTag = -1;
64 
65  uint32_t current_tdc_header =0;
66  int index_for_trailer = 0;
67  //int index_for_error = 0;
68  int numberEventsInBank = 0;
69  fWordCountTotal =0;
70  for(int i = 0; i < GetSize(); i++){
71  uint32_t word = GetData32()[i];
72  //std::cout << "0x"<<std::hex << word << std::dec << std::endl;
73 
74  // Header
75  if( (word & 0xf8000000) == 0x40000000){
76  fGlobalHeader.push_back(word);
77  numberEventsInBank++;
78  }
79 
80  // TDC header
81  if( (word & 0xf8000000) == 0x08000000){
82  current_tdc_header = word;
83  }
84  // TDC measurement
85  if( (word & 0xf8000000) == 0x00000000){
86  fMeasurements.push_back(TDCMeasurement(current_tdc_header,word,numberEventsInBank-1));
87  }
88 
89  // TDC trailer
90  if( (word & 0xf8000000) == 0x18000000){
91  // Set the TDC trailer word for all the measurements since the last
92  // TDC trailer.
93  for(unsigned int i = index_for_trailer; i < fMeasurements.size(); i++){
94  fMeasurements[i].SetTrailer(word);
95  }
96  index_for_trailer = fMeasurements.size();
97  }
98 
99  // TDC error
100  if( (word & 0xf8000000) == 0x20000000){
101  // Set the TDC error word for all the measurements since the last
102  // TDC error.
103  std::cout << "Error word: " << std::hex << "0x"<<word<< std::dec << std::endl;
104  for(unsigned int i = index_for_trailer; i < fMeasurements.size(); i++){
105  fMeasurements[i].SetErrors(word);
106  }
107  //index_for_error = fMeasurements.size();
108  }
109 
110 
111  // Extended Trigger Time Tag
112  if( (word & 0xf8000000) == 0x88000000) fExtendedTriggerTimeTag.push_back((int)(word & 0x07ffffff));
113 
114  // Found global trailer
115  if( (word & 0xf8000000) == 0x80000000){ // Found trailer
116  found_trailer_word = i;
117  fWordCountTotal += (word & 0x0001fffe0) >> 5;
118  fStatus.push_back( (word & 0x07000000) >> 24);
119  }
120 
121  // Found filler word; ignore
122  if( (word & 0xf8000000) == 0xc0000000) continue;
123 
124  }
125 
126  if(found_trailer_word == -1){
127  std::cerr << "Error in decoding V1190 data; didn't find trailer." << std::endl;
128  std::cerr << "Bank dump: " << std::endl;
129  for(int i = 0; i < GetSize(); i++){
130  uint32_t word = GetData32()[i];
131  std::cout << "0x"<<std::hex << word << std::dec << std::endl;
132  }
133  }
134  if(found_trailer_word != fWordCountTotal-1)
135  std::cerr << "Error; did not find trailer on last word of bank. trailer word = " << found_trailer_word
136  << " last word = " << GetSize()-1 << std::endl;
137 
138  // this check doesn't make sense... sometimes we have filler words...
139  if(0)
140  if(fWordCountTotal != GetSize()){
141  std::cerr << "Error in decoding V1190 data; word count in all trailers ("<<fWordCountTotal
142  << ") doesn't match bank size ("<< GetSize() << ")." << std::endl;
143  }
144 
145 
146 }
147 
149 
150  std::cout << "V1190 decoder for bank " << GetName().c_str() << std::endl;
151  std::cout << "event counter = " << GetEventCounter() << ", geographic address: " << GetGeoAddress() << std::endl;
152  std::cout << "Number of events in this bank: " << GetEventsInBank() << std::endl;
153  for(unsigned int i = 0; i < fMeasurements.size(); i++){
154  std::cout << "Measurement: " << fMeasurements[i].GetMeasurement() << " for tdc/chan " <<
155  fMeasurements[i].GetTDCNumber() << "/"<< fMeasurements[i].GetChannel();
156  if(fMeasurements[i].IsLeading())
157  std::cout << " (leading edge meas)";
158  if(fMeasurements[i].IsTrailing())
159  std::cout << " (trailing edge meas)";
160 
161  std::cout << "[event_id = " << fMeasurements[i].GetEventID() << ",bunch_id="
162  << fMeasurements[i].GetBunchID()<< "]" << "Event index=" << fMeasurements[i].GetEventIndex();
163  if(fMeasurements[i].HasTDCErrorWord())
164  std::cout << "[errors=0x"<< std::hex << fMeasurements[i].GetErrors() << std::dec << "]";
165  std::cout << std::endl;
166  }
167 
168 
169 }
void SetTrailer(uint32_t trailer)
Set the trailer word.
Definition: TV1190Data.cxx:6
uint32_t GetTDCNumber() const
Get the TDC number.
Definition: TV1190Data.cxx:12
bool HasTDCHeader() const
Check if measurement has a TDC header.
Definition: TV1190Data.hxx:38
uint32_t GetErrors() const
Get Errors.
Definition: TV1190Data.cxx:37
uint32_t tdc_trailer_word
Definition: TV1190Data.hxx:52
bool HasTDCTrailer() const
Check if measurement has a TDC trailer.
Definition: TV1190Data.hxx:40
uint32_t tdc_header_word
Found fields to hold the header, measurement, trailer and error words.
Definition: TV1190Data.hxx:50
uint32_t tdc_error_error
Definition: TV1190Data.hxx:53
bool HasTDCErrorWord() const
Check if measurement has a TDC error word.
Definition: TV1190Data.hxx:42
uint32_t GetBunchID() const
Get Bunch ID.
Definition: TV1190Data.cxx:30
uint32_t GetEventID() const
Get Event ID; this is event number defined by V1190 module.
Definition: TV1190Data.cxx:21
int GetSize() const
const uint32_t * GetData32() const
std::string GetName() const
int GetEventsInBank()
Get the number of events in this bank.
Definition: TV1190Data.hxx:119
std::vector< int > fExtendedTriggerTimeTag
Definition: TV1190Data.hxx:136
TV1190Data(int bklen, int bktype, const char *name, void *pdata)
Constructor.
Definition: TV1190Data.cxx:46
void Print()
Print the bank contents in a structured way.
Definition: TV1190Data.cxx:148
std::vector< uint32_t > fGlobalHeader
The overall global header.
Definition: TV1190Data.hxx:133
std::vector< uint32_t > fStatus
Definition: TV1190Data.hxx:139
int fWordCountTotal
Definition: TV1190Data.hxx:137
std::vector< TDCMeasurement > fMeasurements
Vector of TDC Measurements.
Definition: TV1190Data.hxx:143
uint32_t GetEventCounter(int index=0) const
Get Event Counter.
Definition: TV1190Data.hxx:87
uint32_t GetGeoAddress(int index=0) const
Get Geographical Address.
Definition: TV1190Data.hxx:90