GRSISort "v4.0.0.5"
An extension of the ROOT analysis Framework
Loading...
Searching...
No Matches
TTdrDataParser.cxx
Go to the documentation of this file.
1#include "TTdrDataParser.h"
3
4#include "TChannel.h"
5#include "Globals.h"
6
7#include "TScalerQueue.h"
8#include "TTdrMnemonic.h"
9#include "TEpicsFrag.h"
10#include "TParsingDiagnostics.h"
11
12#include "Rtypes.h"
13
14#include "TFragment.h"
15#include "TBadFragment.h"
16
22
26
27int TTdrDataParser::Process(std::shared_ptr<TRawEvent> rawEvent)
28{
29 /// Process this TTdrEvent using the provided data parser.
30 /// Returns the total number of fragments read (good and bad).
31 // right now the parser only returns the total number of fragments read
32 // so we assume (for now) that all fragments are good fragments
33 std::shared_ptr<TTdrEvent> event = std::static_pointer_cast<TTdrEvent>(rawEvent);
34 return TdrToFragment(event->GetData(), event->GetDataSize());
35}
36
37int TTdrDataParser::TdrToFragment(char* data, uint32_t size)
38{
39 uint64_t* ptr = reinterpret_cast<uint64_t*>(data);
40
41 int totalEventsRead = 0;
42 static uint64_t timeStampHighBits = 0;
43 std::shared_ptr<TFragment> eventFrag = std::make_shared<TFragment>();
44 if(fItemsPopped != nullptr && fInputSize != nullptr) {
45 *fInputSize += size/8; // words of 8 bytes each
46 }
47
48 for(size_t i = 0; i < size/8; ++i) {
49 eventFrag->Clear();
50 if(fItemsPopped != nullptr && fInputSize != nullptr) {
51 ++(*fItemsPopped);
52 --(*fInputSize);
53 }
54 //std::cout<<"0x"<<std::setw(16)<<ptr[i]<<std::endl;
55 switch(ptr[i]>>62) {
56 case 0:
57 std::cout<<"unknown word"<<std::endl;
58 break;
59 case 1:
60 std::cout<<"trace word"<<std::endl;
61 break;
62 case 2:
63 // this word gives us the extended timestamp (and a moduleNumber and channelNumber)
64 // the only thing we really care about is the high timestamp bits
65 {
66 //short moduleNumber = (ptr[i]>>56)&0x3f;
67 short infoCode = (ptr[i]>>52)&0xf;
68 if(((ptr[i]>>28)&0xf) != 0x0) {
69 std::cout<<"not a proper word!"<<std::endl;
70 }
71 //uint64_t timeStamp = ptr[i]&0xfffffff;
72 //uint32_t channelNumber = 0;
73 switch(infoCode) {
74 case 0:
75 std::cout<<"undefined infoCode "<<infoCode<<std::endl;
76 break;
77 case 1:
78 //channelNumber = (ptr[i]>>32)&0xfffff;
79 break;
80 case 2:
81 case 3:
82 case 4:
83 case 7:
84 //timeStamp |= ptr[i]&0xfffff00000000>>4;
85 timeStampHighBits = (ptr[i]>>32)&0xfffff;
86 break;
87 case 5:
88 //timeStamp |= (ptr[i]&0xfffff00000000)<<20;
89 timeStampHighBits = (ptr[i]>>12)&0xfffff00000;
90 break;
91 default:
92 std::cout<<"infoCode "<<infoCode<<std::endl;
93 break;
94 }
95 //std::cout<<"moduleNumber "<<moduleNumber<<", channelNumber "<<channelNumber<<", timeStamp "<<timeStamp<<std::endl;
96 break;
97 }
98 case 3:
99 {
100 // data word with channelNumber, adcData, and 28 low bits of timestamp
101 // check if this is the tape-move event
102 auto channel = TChannel::GetChannel((ptr[i]>>48)&0xfff);
103 if(channel != nullptr && static_cast<EDigitizer>(channel->GetDigitizerType()) == EDigitizer::kPixieTapeMove) {
104 //PPG
105 auto* ppgEvent = new TPPGData;
106 switch(channel->GetDetectorNumber()) {
107 case 1:
108 // tape move for "normal" experiments
109 // target finished moving in front of detector for PR294
110 ppgEvent->SetNewPPG(EPpgPattern::kTapeMove);
111 break;
112 case 2:
113 // unused for "normal" experiments
114 // target moving away from detector for PR294
115 ppgEvent->SetNewPPG(EPpgPattern::kBackground);
116 break;
117 default:
118 ppgEvent->SetNewPPG(EPpgPattern::kJunk);
119 break;
120 }
121 ppgEvent->SetLowTimeStamp(ptr[i]&0xfffffff);
122 ppgEvent->SetHighTimeStamp(timeStampHighBits);
123 ppgEvent->SetNetworkPacketId(static_cast<Int_t>((ptr[i]>>32)&0xffff));
124 TPPG::Get()->AddData(ppgEvent);
125 continue;
126 }
127 eventFrag->SetAddress((ptr[i]>>48)&0xfff);
128 eventFrag->SetTimeStamp((ptr[i]&0xfffffff) | (timeStampHighBits<<28));
129 ++totalEventsRead;
130 // charge is a 14bit signed integer (despite being reported as 16 bits) so we extend the sign bit for an Int_t (4 bytes)
131 //eventFrag->SetCharge(static_cast<Int_t>(((ptr[i]>>32)&0xffff) | ((((ptr[i]>>32)&0x2000) == 0x2000) ? 0xffffc000 : 0x0)));
132 eventFrag->SetCharge(static_cast<Int_t>((ptr[i]>>32)&0xffff));
133 //std::cout<<std::hex<<std::setfill('0');
134 //std::cout<<std::setw(16)<<ptr[i]<<": addr "<<eventFrag->GetAddress()<<", ts "<<eventFrag->GetTimeStamp()<<", charge "<<eventFrag->Charge()<<std::endl;
135 //std::cout<<std::dec<<std::setfill(' ');
136 // we expect a second word from the channel+16 with the same timestamp
137 ++i;
138 if(i >= size/8) {
139 if(fRecordDiag) {
141 }
142 Push(*fBadOutputQueue, std::make_shared<TBadFragment>(*eventFrag, reinterpret_cast<uint32_t*>(data), size/4, i, false));
143 continue;
144 }
145 // check address
146 if(((ptr[i]>>48)&0xfff) != eventFrag->GetAddress() + 16) {
147 //std::cout<<"Address mismatch "<<((ptr[i]>>48)&0xfff)<<" != "<<eventFrag->GetAddress()<<std::endl;
148 if(fRecordDiag) {
150 }
151 Push(*fBadOutputQueue, std::make_shared<TBadFragment>(*eventFrag, reinterpret_cast<uint32_t*>(data), size/4, i, false));
152 // re-try this word
153 --i;
154 continue;
155 }
156 // check timestamp
157 if(static_cast<Long64_t>((ptr[i]&0xfffffff) | (timeStampHighBits<<28)) != eventFrag->GetTimeStamp()) {
158 //std::cout<<"Timestamp mismatch "<<((ptr[i]&0xfffffff) | (timeStampHighBits<<28))<<" != "<<eventFrag->GetTimeStamp()<<std::endl;
159 if(fRecordDiag) {
161 }
162 Push(*fBadOutputQueue, std::make_shared<TBadFragment>(*eventFrag, reinterpret_cast<uint32_t*>(data), size/4, i, false));
163 // re-try this word
164 --i;
165 continue;
166 }
167 if(fItemsPopped != nullptr && fInputSize != nullptr) {
168 --(*fInputSize); // we just read another word from the input
169 }
170 // set Cfd ???
171 eventFrag->SetCfd(static_cast<Int_t>((ptr[i]>>32)&0xffff));
172 //std::cout<<std::hex<<std::setfill('0');
173 //std::cout<<std::setw(16)<<ptr[i]<<": addr "<<eventFrag->GetAddress()<<", ts "<<eventFrag->GetTimeStamp()<<", cfd "<<eventFrag->GetCfd()<<std::endl;
174 //std::cout<<std::dec<<std::setfill(' ');
175 if(fRecordDiag) {
177 }
178 Push(fGoodOutputQueues, std::make_shared<TFragment>(*eventFrag));
179 break;
180 }
181 }
182 }
183
184 return totalEventsRead;
185}
EDigitizer
static TChannel * GetChannel(unsigned int temp_address, bool warn=false)
Definition TChannel.cxx:459
bool fRecordDiag
The flag to turn on diagnostics recording.
void Push(ThreadsafeQueue< std::shared_ptr< const TBadFragment > > &queue, const std::shared_ptr< TBadFragment > &frag)
std::shared_ptr< ThreadsafeQueue< std::shared_ptr< const TBadFragment > > > fBadOutputQueue
std::atomic_long * fInputSize
std::vector< std::shared_ptr< ThreadsafeQueue< std::shared_ptr< const TFragment > > > > fGoodOutputQueues
std::atomic_size_t * fItemsPopped
void SetLowTimeStamp(UInt_t lowTime)
Definition TPPG.h:63
void AddData(TPPGData *pat)
Definition TPPG.cxx:121
void BadFragment(Short_t detType)
void GoodFragment(const std::shared_ptr< const TFragment > &)
static TPPG * Get(bool verbose=false)
Definition TSingleton.h:33
int TdrToFragment(char *data, uint32_t size)
int Process(std::shared_ptr< TRawEvent >) override
EDataParserState fState