CheckTime.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // File: CheckTime.cc
3 // Author: Karl Warburton (Feb 2016)
4 //
5 // Utility to provide methods for checking the timestamps of the
6 // DAQ components.
7 ////////////////////////////////////////////////////////////////////////
8 
9 #include "CheckTime.h"
10 #include <map>
11 #include <iostream>
12 #include <iomanip>
13 //=======================================================================================
14 void DAQToOffline::GetRCEFirstTimestamp( artdaq::Fragments const& Fragments, int &ConsistRCE, int &NumADCs, long long &RCETime ) {
15 
16  for ( size_t fragIndex=0; fragIndex < Fragments.size(); ++fragIndex ) {
17  int ThisADCcount = 0;
18  const artdaq::Fragment &singleFragment = Fragments[fragIndex];
19  lbne::TpcMilliSliceFragment millisliceFragment(singleFragment);
20  auto numMicroSlices = millisliceFragment.microSliceCount();
21  for (unsigned int i_micro=0;i_micro<numMicroSlices;i_micro++) { // Loop through all MicroSlices
22  std::unique_ptr <const lbne::TpcMicroSlice> microSlice = millisliceFragment.microSlice(i_micro);
23  auto numNanoSlices = microSlice->nanoSliceCount();
24  if (numNanoSlices) {
25  ConsistRCE = 1;
26  ThisADCcount += numNanoSlices;
27  //if (ThisADCcount == 1000 )
28  //std::cout << "Some microslice things..."
29  // << " Soft Message " << microSlice->software_message()
30  // << ", Firm Message " << microSlice->firmware_message()
31  // << ", Type ID " << microSlice->type_id()
32  // << ", sequence ID " << microSlice->sequence_id()
33  // << ", SoftTrig? " << microSlice->softTrig()
34  // << ", Ext Trig? " << microSlice->extTrig() << std::endl;
35  } // If numNanoSlices.
36  if ( fragIndex==0 && i_micro==0 ) {
37  // MWallbank 8/30/16: fixed this bug. The 8 msb need to be masked as they represent the external trigger counter
38  uint64_t timestamp = microSlice->software_message() & (((long int)0x1 << 56) - 1);
39  if ( microSlice->nanoSliceCount() ) { // If this MicroSlice has any NanoSlices
40  RCETime = microSlice->nanoSlice(0)->nova_timestamp();
41  } // NanoSlice
42  else {
43  RCETime = timestamp;
44  }
45  } // Looking at first MicroSlice of first Fragment
46  } // MicroSlice
47  if ( fragIndex == 0 ) {
48  NumADCs = ThisADCcount;
49  } else {
50  if ( ThisADCcount != NumADCs ) ConsistRCE = 0;
51  }
52  //std::cout << "Looking at event " << evt.event() << ", fragment " << fragIndex << ", it has " << ThisADCcount << ", InconsistRCEs? " << InconsistRCE << std::endl;
53  } // rawFragments.size()
54  //std::cout << "Got RCE start time, it is " << RCETime << std::endl;
55  return;
56 }
57 //=======================================================================================
58 void DAQToOffline::GetSSPFirstTimestamp( artdaq::Fragments const& Fragments, int &nSSPPayloads, long long &SSPTime ) {
59  if ( Fragments.size() ) {
60  const auto& frag(Fragments[0]);
61  const SSPDAQ::MillisliceHeader* meta=0;
62  if(frag.hasMetadata()) {
63  ++nSSPPayloads;
64 
65  meta = &(frag.metadata<lbne::SSPFragment::Metadata>()->sliceHeader);
66  //std::cout << "=== SSP Metadata, Start time " << meta->startTime << ", End time " << meta->endTime << " Packet length " << meta->length << " Number of triggers " << meta->nTriggers << "===" << std::endl;
67  SSPTime = meta->startTime;
68  }
69  }
70  //std::cout << "Got SSP start time, it is " << SSPTime << std::endl;
71  return;
72 }
73 //=======================================================================================
74 void DAQToOffline::GetPTBFirstTimestamp( artdaq::Fragments const& PTBrawFragments, int &nPTBPayloads, long long &PTBTime ) {
75 
76  if (PTBrawFragments.size()) {
77  ++nPTBPayloads;
78  lbne::PennMicroSlice::Payload_Header *word_header = nullptr;
79  lbne::PennMicroSlice::Payload_Timestamp *FirstTimestamp = nullptr;
80  uint32_t payload_index = 0;
81  uint16_t counter, trigger, timestamp, payloadCount;
82  uint8_t* payload_data = nullptr;
83 
84  //const auto& frag((PTBrawFragments)[0]);
85  const artdaq::Fragment frag = PTBrawFragments[0];
86  lbne::PennMilliSliceFragment msf(frag);
87 
88  payloadCount = msf.payloadCount(counter, trigger, timestamp);
89 
90  while (payload_index < uint32_t(payloadCount-1) && FirstTimestamp == nullptr) {
91  payload_data = msf.get_next_payload(payload_index,word_header);
92  switch(word_header->data_packet_type) {
93  case lbne::PennMicroSlice::DataTypeTimestamp:
94  FirstTimestamp = reinterpret_cast<lbne::PennMicroSlice::Payload_Timestamp*>(payload_data);
95  break;
96  default:
97  break;
98  }
99  }
100  PTBTime = FirstTimestamp->nova_timestamp;
101  }
102  return;
103 }
104 //=======================================================================================
105 
void GetSSPFirstTimestamp(artdaq::Fragments const &Fragments, int &nSSPPayloads, long long &SSPTime)
Definition: CheckTime.cc:58
unsigned short uint16_t
Definition: stdint.h:125
unsigned char uint8_t
Definition: stdint.h:124
auto counter(T begin, T end)
Returns an object to iterate values from begin to end in a range-for loop.
Definition: counter.h:285
unsigned int uint32_t
Definition: stdint.h:126
unsigned __int64 uint64_t
Definition: stdint.h:136
void GetPTBFirstTimestamp(artdaq::Fragments const &PTBrawFragments, int &nPTBPayloads, long long &PTBTime)
Definition: CheckTime.cc:74
void GetRCEFirstTimestamp(artdaq::Fragments const &Fragments, int &ConsistRCE, int &NumADCs, long long &RCETime)
Definition: CheckTime.cc:14