Hall C ROOT/C++ Analyzer (hcana)
TIBlobModule.cxx
Go to the documentation of this file.
1 
10 #include "TIBlobModule.h"
11 #include "THaSlotData.h"
12 #include <iostream>
13 
14 using namespace std;
15 
16 namespace Decoder {
17 
18  Module::TypeIter_t TIBlobModule::fgThisType =
19  DoRegister( ModuleType( "Decoder::TIBlobModule" , 4 ));
20 
21  TIBlobModule::TIBlobModule(UInt_t crate, UInt_t slot) : PipeliningModule(crate, slot) {
22  fDebugFile=0;
23  Init();
24  }
25 
27  }
28 
30  Module::Init();
32  fData.assign(fNumChan,0);
33 #if defined DEBUG && defined WITH_DEBUG
34  // This will make a HUGE output
35  delete fDebugFile; fDebugFile = 0;
36  fDebugFile = new ofstream;
37  fDebugFile->open(string("TIBlob_debug.txt"));
38 #endif
39  //fDebugFile=0;
40  Clear();
41  IsInit = kTRUE;
42 
43  fName = "TIBlob";
44  }
45 
46  UInt_t TIBlobModule::LoadSlot( THaSlotData *sldat, const UInt_t* evbuffer, const UInt_t *pstop) {
47  // the 3-arg verison of LoadSlot
48 
49  std::vector< UInt_t > evb;
50  while(evbuffer < pstop) evb.push_back(*evbuffer++);
51 
52  // Note, methods SplitBuffer, GetNextBlock are defined in PipeliningModule
53  // SplitBuffer needs to be modified a bit for the TI
54 
55  SplitBuffer(evb);
56  return LoadThisBlock(sldat, GetNextBlock());
57  }
58 
59  UInt_t TIBlobModule::LoadSlot( THaSlotData *sldat, const UInt_t *evbuffer, UInt_t pos, UInt_t len) {
60  // the 4-arg verison of LoadSlot. Let it call the 3-arg version.
61  // Do we need this or is it historical?
62 
63  return LoadSlot(sldat, evbuffer+pos, evbuffer+pos+len);
64  }
65 
67  // Note, GetNextBlock belongs to PipeliningModule
68  return LoadThisBlock(sldat, GetNextBlock());
69  }
70 
71  UInt_t TIBlobModule::LoadThisBlock( THaSlotData *sldat, const vector<UInt_t>& evbuffer) {
72 
73  // Fill data structures of this class using the event buffer of one "event".
74  // An "event" is defined in the traditional way -- a scattering from a target, etc.
75 
76  Clear();
77 
78  // Only interpret data if fSlot agrees with the slot in the headers
79 
80  UInt_t evlen = evbuffer.size();
81  if(evlen>0) {
82  // The first word might be a filler word
83  UInt_t ifill = (((evbuffer[0] >> 27) & 0x1F) == 0x1F) ? 1 : 0;
84  if (evlen>=5+ifill) {// Need at least two headers and the trailer and 2 data words
85  UInt_t header1=evbuffer[ifill];
86  UInt_t slot_blk_hdr=(header1 >> 22) & 0x1F; // Slot number (set by VME64x backplane), mask 5 bits
87  if(fSlot != slot_blk_hdr) {
88  return evlen;
89  }
90  fData[0] = (evbuffer[2 + ifill] >> 24) & 0xFF; // Trigger type
91  fData[1] = evbuffer[3 + ifill]; // Trigger number
92  fData[2] = (evlen>5+ifill) ? evbuffer[4 + ifill] : 0; // Trigger time
93  // cout << "TIBlob Slot " << fSlot << ": ";
94  for(UInt_t i=0;i<3;i++) {
95  sldat->loadData(i, fData[i], fData[i]);
96  // cout << " " << fData[i];
97  }
98  // cout << endl;
99  }
100  }
101 
102  return evlen;
103 
104  }
105 
106  Int_t TIBlobModule::SplitBuffer( const vector<UInt_t>& bigbuffer ) {
107 
108  // Split a CODA buffer into blocks. A block is data from a traditional physics event.
109  // In MultiBlock Mode, a pipelining module can have several events in each CODA buffer.
110  // If block level is 1, then the buffer is a traditional physics event.
111  // If finding >1 block, this will set fMultiBlockMode = kTRUE
112 
113  // Copied from PipeliningModule and customized for TI
114 
115  std::vector<UInt_t > oneEventBuffer;
116  eventblock.clear();
118  // Int_t eventnum = 1;
119  // Int_t evt_num_modblock;
120 
121  // if ((fFirstTime == kFALSE) && (IsMultiBlockMode() == kFALSE)) {
122  eventblock.push_back(bigbuffer);
123  index_buffer=1;
124  return 1;
125  // }
126  // return 0;
127  // The rest of this is only use if we are in multiblock mode
128  // It still needs to be developed.
129 #if 0
130  int debug=1;
131 
132  Int_t slot_blk_hdr, slot_evt_hdr, slot_blk_trl;
133  Int_t iblock_num, nblock_events, nwords_inblock, evt_num;
134  Int_t BlockStart=0;
135 
136  slot_blk_hdr = 0;
137  slot_evt_hdr = 0;
138  slot_blk_trl = 0;
139  nblock_events = 0;
140 
141  if(codabuffer.size() > 2) { // Need at least the two headers and the trailer
142  UInt_t header1=codabuffer[0];
143  UInt_t header2=codabuffer[1];
144 
145  if((header1&0xF8000000)==0x80000000 &&
146  (header1&0xF8000000)==0xF8000000) { // Header words
147  slot_blk_hdr = (header1 >> 22) & 0x1F; // Slot number (set by VME64x backplane), mask 5 bits
148  // iblock_num = (data >> 8) & 0x3FF;
149  nblock_events = header1 & 0xFF;
150  if(nblock_events > 1) fMultiBlockMode = kTRUE;
151  UInt_t i=2;
152  while(i+1 < codabuffer.size()) {
153  // This should be event header
154 
155 
156 ...
157 #endif
158 }
159 
160 
161  /* Does anything use this method */
163  if (chan >= fNumChan) return 0;
164  return fData[chan];
165 }
166 
167 void TIBlobModule::Clear(const Option_t* opt) {
168  VmeModule::Clear(opt);
169  fData.assign(fNumChan,0);
170 }
171 
172 }
173 
const char Option_t
std::vector< std::vector< UInt_t > > eventblock
virtual void Clear(const Option_t *opt="")
int Int_t
STL namespace.
std::vector< UInt_t > fData
virtual Int_t SplitBuffer(const std::vector< UInt_t > &bigbuffer)
virtual void Init()
virtual UInt_t GetData(UInt_t chan) const
static const size_t NTICHAN
Definition: TIBlobModule.h:44
std::ofstream * fDebugFile
unsigned int UInt_t
virtual UInt_t LoadNextEvBuffer(THaSlotData *sldat)
const Bool_t kFALSE
virtual UInt_t LoadThisBlock(THaSlotData *sldat, const std::vector< UInt_t > &evbuffer)
Bool_t fMultiBlockMode
virtual UInt_t LoadSlot(THaSlotData *sldat, const UInt_t *evbuffer, const UInt_t *pstop)
tuple debug
std::vector< UInt_t > GetNextBlock()
string::size_type pos
Int_t loadData(const char *type, UInt_t chan, UInt_t dat, UInt_t raw)
ClassImp(THcDCLookupTTDConv) THcDCLookupTTDConv
virtual void Init()
const Bool_t kTRUE
virtual void Clear(Option_t *="")