Namespaces | Classes | Typedefs | Functions | Variables
DAQToOffline Namespace Reference

Namespaces

 TypeSizes
 

Classes

class  BadTimings
 
class  FilterAnalyzer
 
class  FilterAnalyzerRunList
 
class  GoodRun
 
class  NoiseCorrelation
 
class  PTBToOffline
 
class  Splitter
 
class  SSPDiagnosticAna
 
class  SSPReformatterAlgs
 
class  SSPToOffline
 
class  SSPTriggerAna
 
class  TpcDAQToOffline
 

Typedefs

typedef std::pair< lbne::PennMicroSlice::Payload_Header::short_nova_timestamp_t, std::bitset< TypeSizes::TriggerWordSize > > PTBTrigger
 

Functions

void GetRCEFirstTimestamp (artdaq::Fragments const &Fragments, int &ConsistRCE, int &NumADCs, long long &RCETime)
 
void GetSSPFirstTimestamp (artdaq::Fragments const &Fragments, int &nSSPPayloads, long long &SSPTime)
 
void GetPTBFirstTimestamp (artdaq::Fragments const &PTBrawFragments, int &nPTBPayloads, long long &PTBTime)
 
void CollectCounterBits (lbne::PennMicroSlice::Payload_Header *header, lbne::PennMicroSlice::Payload_Counter *trigger)
 
void CollectTrigger (lbne::PennMicroSlice::Payload_Header *header, lbne::PennMicroSlice::Payload_Trigger *trigger)
 
std::vector< raw::ExternalTriggerPennFragmentToExternalTrigger (artdaq::Fragments const &Fragments, std::map< int, int > &channelMap, lbne::PennMicroSlice::Payload_Timestamp *&FirstPTBTimestamp)
 
void GetTimestamp (lbne::PennMilliSliceFragment msf, lbne::PennMicroSlice::Payload_Header *&word_header, lbne::PennMicroSlice::Payload_Timestamp *const &previous_timestamp, lbne::PennMicroSlice::Payload_Timestamp *&future_timestamp, lbne::PennMicroSlice::Payload_Header *&future_timestamp_header, std::vector< lbne::PennMicroSlice::Payload_Timestamp::timestamp_t > &TimeVector)
 
bool MakeNewExtTrig (uint32_t pos, bool &PrevOn, bool NowOn)
 
void BuildPTBChannelMap (std::string MapDir, std::string MapFile, std::map< int, int > &channelMap)
 
void MakeCounterPositionMap (std::string CounterDir, std::string CounterFile, std::map< unsigned int, std::pair< TVector3, std::vector< TVector3 > > > &CounterPositionMap, double fExtendCountersX=0, double fExtendCountersY=0, double fExtendCountersZ=0)
 
void MakeCounterCorners (int CountInd, double HalfLength, double HalfWidth1, double HalfWidth2, TVector3 Centre, TVector3 &TL, TVector3 &TR, TVector3 &BL, TVector3 &BR, double fExtendCountersX=0, double fExtendCountersY=0, double fExtendCountersZ=0)
 
std::vector< raw::RawDigittpcFragmentToRawDigits (artdaq::Fragments const &rawFragments, std::vector< std::pair< std::pair< unsigned int, unsigned int >, lbne::TpcNanoSlice::Header::nova_timestamp_t > > &DigitsIndexList, lbne::TpcNanoSlice::Header::nova_timestamp_t &firstTimestamp, art::ServiceHandle< lbne::ChannelMapService > const &channelMap, bool useChannelMap, bool debug, raw::Compress_t compression, unsigned int zeroThreshold)
 
art::Timestamp make_art_timestamp_from_nova_timestamp (lbne::TpcNanoSlice::Header::nova_timestamp_t this_nova_timestamp)
 
art::Timestamp old_make_art_timestamp_from_nova_timestamp (lbne::TpcNanoSlice::Header::nova_timestamp_t this_nova_timestamp)
 

Variables

const lbne::TpcNanoSlice::Header::nova_timestamp_t nova_time_ticks_per_second = 64e6
 

Typedef Documentation

typedef std::pair<lbne::PennMicroSlice::Payload_Header::short_nova_timestamp_t, std::bitset<TypeSizes::TriggerWordSize> > DAQToOffline::PTBTrigger

Definition at line 43 of file PennToOffline.h.

Function Documentation

void DAQToOffline::BuildPTBChannelMap ( std::string  MapDir,
std::string  MapFile,
std::map< int, int > &  channelMap 
)

Builds PTB channel map from the map txt file

Definition at line 245 of file PennToOffline.cc.

245  {
246  /// Builds PTB channel map from the map txt file
247  channelMap.clear();
248 
249  int onlineChannel;
250  int offlineChannel;
251 
252  std::ostringstream LocStream;
253  LocStream << MapDir << MapFile;
254  std::string fullname = LocStream.str();
255 
256  std::string FileLoc;
257  cet::search_path sp("FW_SEARCH_PATH");
258  if (sp.find_file(MapFile, FileLoc)) fullname = FileLoc;
259 
260  if (fullname.empty())
261  mf::LogWarning("DAQToOffline") << "Input PTB channel map file " << MapFile << " not found in FW_SEARCH_PATH, or in location " << LocStream.str() << ". Using online channel numbers!" << std::endl;
262 
263  else {
264  mf::LogVerbatim("DAQToOffline") << "Build PTB Online->Offline channel Map from " << fullname;
265  std::ifstream infile(fullname);
266  if (!infile.good()) std::cout << "Not finding " << fullname << std::endl;
267  while (infile.good()) {
268  infile >> onlineChannel >> offlineChannel;
269  channelMap.insert(std::make_pair(onlineChannel,offlineChannel));
270  mf::LogVerbatim("DAQToOffline") << " " << onlineChannel << " -> " << offlineChannel;
271  }
272  mf::LogVerbatim("DAQToOffline")<< "channelMap has size " << channelMap.size();
273  }
274 }
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
std::string string
Definition: nybbler.cc:12
string infile
QTextStream & endl(QTextStream &s)
void DAQToOffline::CollectCounterBits ( lbne::PennMicroSlice::Payload_Header *  header,
lbne::PennMicroSlice::Payload_Counter *  trigger 
)
void DAQToOffline::CollectTrigger ( lbne::PennMicroSlice::Payload_Header *  header,
lbne::PennMicroSlice::Payload_Trigger *  trigger 
)
void DAQToOffline::GetPTBFirstTimestamp ( artdaq::Fragments const &  PTBrawFragments,
int &  nPTBPayloads,
long long &  PTBTime 
)

Definition at line 74 of file CheckTime.cc.

74  {
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 }
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
void DAQToOffline::GetRCEFirstTimestamp ( artdaq::Fragments const &  Fragments,
int &  ConsistRCE,
int &  NumADCs,
long long &  RCETime 
)

Definition at line 14 of file CheckTime.cc.

14  {
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 }
unsigned __int64 uint64_t
Definition: stdint.h:136
void DAQToOffline::GetSSPFirstTimestamp ( artdaq::Fragments const &  Fragments,
int &  nSSPPayloads,
long long &  SSPTime 
)

Definition at line 58 of file CheckTime.cc.

58  {
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 }
void DAQToOffline::GetTimestamp ( lbne::PennMilliSliceFragment  msf,
lbne::PennMicroSlice::Payload_Header *&  word_header,
lbne::PennMicroSlice::Payload_Timestamp *const &  previous_timestamp,
lbne::PennMicroSlice::Payload_Timestamp *&  future_timestamp,
lbne::PennMicroSlice::Payload_Header *&  future_timestamp_header,
std::vector< lbne::PennMicroSlice::Payload_Timestamp::timestamp_t > &  TimeVector 
)

Definition at line 204 of file PennToOffline.cc.

209  {
210 
211  if (previous_timestamp != nullptr) {
212  TimeVector.push_back(word_header->get_full_timestamp_post(previous_timestamp->nova_timestamp));
213  } else {
214  if (future_timestamp == nullptr) {
215  future_timestamp = reinterpret_cast<lbne::PennMicroSlice::Payload_Timestamp*>(msf.get_next_timestamp(future_timestamp_header));
216  if (future_timestamp == nullptr) {
217  std::cerr << "CAN'T FIND PTB TIMESTAMP WORDS IN MILLISLICE FRAGMENT!!! Logic will fail." << std::endl;
218  return;
219  }
220  }
221  TimeVector.push_back(word_header->get_full_timestamp_pre(future_timestamp->nova_timestamp));
222  }
223  return;
224 }
QTextStream & endl(QTextStream &s)
art::Timestamp DAQToOffline::make_art_timestamp_from_nova_timestamp ( lbne::TpcNanoSlice::Header::nova_timestamp_t  this_nova_timestamp)

Definition at line 150 of file tpcFragmentToRawDigits.cc.

150  {
151  return DuneTimeConverter:: fromNova(novaTime);
152 }
static art::Timestamp fromNova(uint64_t tnova)
void DAQToOffline::MakeCounterCorners ( int  CountInd,
double  HalfLength,
double  HalfWidth1,
double  HalfWidth2,
TVector3  Centre,
TVector3 &  TL,
TVector3 &  TR,
TVector3 &  BL,
TVector3 &  BR,
double  fExtendCountersX = 0,
double  fExtendCountersY = 0,
double  fExtendCountersZ = 0 
)

Definition at line 348 of file PennToOffline.cc.

348  {
349  // The actual corners are calculated. As above:
350  // NOTE: The corners are calculated as if the counters were rectangular I pass both widths incase somebody wishes to correct this...
351  // The telescope corners are not yet calculated...
352 
353  if ( fExtendCountersY == 0 ) fExtendCountersY = fExtendCountersX;
354  if ( fExtendCountersZ == 0 ) fExtendCountersZ = fExtendCountersX;
355  //std::cout << "Extending counters by " << fExtendCountersX << " " << fExtendCountersY << " " << fExtendCountersZ << std::endl;
356 
357  if ( CountInd < 44 ) {
358  if ( (CountInd >=6 && CountInd <=15) || (CountInd >=28 && CountInd <=37) ) { // For the East / West counters
359  //std::cout << "Looking at an East West counter " << std::endl;
360  // Top Left
361  TL[0] = Centre[0] - fExtendCountersX - HalfWidth1;
362  TL[1] = Centre[1] + fExtendCountersY + HalfLength;
363  TL[2] = Centre[2];
364  // Top Right
365  TR[0] = Centre[0] + fExtendCountersX + HalfWidth1;
366  TR[1] = Centre[1] + fExtendCountersY + HalfLength;
367  TR[2] = Centre[2];
368  // Bottom Left
369  BL[0] = Centre[0] - fExtendCountersX - HalfWidth1;
370  BL[1] = Centre[1] - fExtendCountersY - HalfLength;
371  BL[2] = Centre[2];
372  // Bottom Right
373  BR[0] = Centre[0] + fExtendCountersX + HalfWidth1;
374  BR[1] = Centre[1] - fExtendCountersY - HalfLength;
375  BR[2] = Centre[2];
376  } else { // For the North / South counters
377  //std::cout << "Looking at a North South counter " << std::endl;
378  // Top Left
379  TL[0] = Centre[0];
380  TL[1] = Centre[1] + fExtendCountersY + HalfLength;
381  TL[2] = Centre[2] - fExtendCountersZ - HalfWidth1;
382  // Top Right
383  TR[0] = Centre[0];
384  TR[1] = Centre[1] + fExtendCountersY + HalfLength;
385  TR[2] = Centre[2] + fExtendCountersZ + HalfWidth1;
386  // Bottom Left
387  BL[0] = Centre[0];
388  BL[1] = Centre[1] - fExtendCountersY - HalfLength;
389  BL[2] = Centre[2] - fExtendCountersZ - HalfWidth1;
390  // Bottom Right
391  BR[0] = Centre[0];
392  BR[1] = Centre[1] - fExtendCountersY - HalfLength;
393  BR[2] = Centre[2] + fExtendCountersZ + HalfWidth1;
394  }
395  } else { // For the telescope counters.
396  if ( (CountInd >= 44 && CountInd <= 56) || (CountInd >= 67 && CountInd <= 82) ) { // For one group of Telescope counters
397  //std::cout << "Looking at a Telescope 1 counter " << std::endl;
398  for (int ww=0; ww<3; ++ww )
399  TL[ww] = TR[ww] = BL[ww] = BR[ww] = Centre[ww];
400  } else { // For the other group of Telescope counters
401  //std::cout << "Looking at a Telescope 2 counter " << std::endl;
402  for (int ww=0; ww<3; ++ww )
403  TL[ww] = TR[ww] = BL[ww] = BR[ww] = Centre[ww];
404  }
405  }
406 }
void DAQToOffline::MakeCounterPositionMap ( std::string  CounterDir,
std::string  CounterFile,
std::map< unsigned int, std::pair< TVector3, std::vector< TVector3 > > > &  CounterPositionMap,
double  fExtendCountersX = 0,
double  fExtendCountersY = 0,
double  fExtendCountersZ = 0 
)

Definition at line 276 of file PennToOffline.cc.

276  {
277 
278  if ( fExtendCountersY == 0 ) fExtendCountersY = fExtendCountersX;
279  if ( fExtendCountersZ == 0 ) fExtendCountersZ = fExtendCountersX;
280  // A function to make a map of counter corners and their centres.
281  // Until the LArSoft counters are changed this is the preferred way to get their centres.
282  // A text file is loaded in from pardata, though a user defined one can be uploaded instead.
283  // The geometries of the LArSoft counters ( which are correct ) are used to determine the size of the corners
284  // of the counters from the loaded centres.
285  // NOTE. The counters are assumed to rectangular as this make the maths much simpler.
286  // In truth the short width is 27.06 cm, whilst the long width is 32.5 cm.
287  // This means that there an overlap of counter corner produced though is relatively insignificant.
288  // The Map is structured as follows:
289  // Key - Counter Index, numbered 0 - 92
290  // Value - a pair of TVector3 and vector of TVector3
291  // Value.first - The centre position of the counter
292  // Value.second[0] - The Top Left corner of the counter
293  // Value.second[1] - The Top Right corner of the counter
294  // Value.second[2] - The Bottom Left corner of the counter
295  // Value.second[3] - The Bottom Right corner of the counter
296  CounterPositionMap.clear();
297 
298  auto fGeom = lar::providerFrom<geo::Geometry>();
299 
300  std::ostringstream CountStream;
301  CountStream << CounterDir << CounterFile;
302  std::string CountPath = CountStream.str();
303 
304  std::string CountLoc;
305  cet::search_path sp("FW_SEARCH_PATH");
306  if (sp.find_file(CounterFile, CountLoc)) CountPath = CountLoc;
307 
308  if (CountPath.empty()) {
309  mf::LogWarning("DAQToOffline") << "ERROR::Cannot find the counter position map file " << CounterFile << " in FW_SEARCH_PATH or " << CounterDir << std::endl;
310  return;
311  } else {
312  std::cout << "Loading the counter position map from " << CountPath << std::endl;
313  std::ifstream infile(CountPath);
314  while (infile.good()) {
315  int CountInd;
316  double CentreX, CentreY, CentreZ;
317  char Type, Side, Orientation;
318  infile >> CountInd >> CentreX >> CentreY >> CentreZ >> Type >> Side >> Orientation;
319  //std::cout << "Read in new line " << CountInd << " " << CentreX << " " << CentreY << " " << CentreZ << " " << Type << " " << Side << " " << Orientation << std::endl;
320 
321  geo::AuxDetGeo const& auxDet = fGeom->AuxDet(CountInd);
322 
323  // Make my TVector3's
324  TVector3 Centre( CentreX, CentreY, CentreZ );
325  TVector3 TL, TR, BL, BR;
326 
327  // Access the counter dimensions from the geometry
328  double HalfLength = 0.5 * auxDet.Length();
329  double HalfWidth1 = auxDet.HalfWidth1();
330  double HalfWidth2 = auxDet.HalfWidth2();
331 
332  // Call the counter corner alg.
333  MakeCounterCorners( CountInd, HalfLength, HalfWidth1, HalfWidth2, Centre, TL, TR, BL, BR, fExtendCountersX, fExtendCountersY, fExtendCountersZ );
334 
335  // Make my vector of TVector3's
336  std::vector<TVector3> Corners;
337  Corners.push_back( TL );
338  Corners.push_back( TR );
339  Corners.push_back( BL );
340  Corners.push_back( BR );
341 
342  // Add this counter to my map.
343  CounterPositionMap.insert( std::make_pair( CountInd, std::make_pair( Centre, Corners ) ) );
344  } // Loading in CountPath.
345  } // If found CountPath
346 } // MakeCounterPositionMap
void MakeCounterCorners(int CountInd, double HalfLength, double HalfWidth1, double HalfWidth2, TVector3 Centre, TVector3 &TL, TVector3 &TR, TVector3 &BL, TVector3 &BR, double fExtendCountersX=0, double fExtendCountersY=0, double fExtendCountersZ=0)
std::string string
Definition: nybbler.cc:12
double HalfWidth2() const
Definition: AuxDetGeo.h:104
string infile
double Length() const
Definition: AuxDetGeo.h:102
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
double HalfWidth1() const
Definition: AuxDetGeo.h:103
Type
Type of JSON value.
Definition: rapidjson.h:618
QTextStream & endl(QTextStream &s)
bool DAQToOffline::MakeNewExtTrig ( uint32_t  pos,
bool PrevOn,
bool  NowOn 
)

Definition at line 226 of file PennToOffline.cc.

226  {
227  if (pos == 0 && NowOn )
228  return false;
229  else if (PrevOn && NowOn )
230  return false;
231  else if (PrevOn && !NowOn) {
232  PrevOn = false;
233  return false;
234  } else if (!PrevOn && !NowOn )
235  return false;
236  else if (!PrevOn && NowOn) {
237  PrevOn = true;
238  return true;
239  } else {
240  std::cout<<"ERROR IN PTBFORMATTER'S LOGIC IN COUNTER ANALYSIS"<<std::endl; //We should never get here
241  return false;
242  }
243 }
QTextStream & endl(QTextStream &s)
art::Timestamp DAQToOffline::old_make_art_timestamp_from_nova_timestamp ( lbne::TpcNanoSlice::Header::nova_timestamp_t  this_nova_timestamp)

Definition at line 155 of file tpcFragmentToRawDigits.cc.

155  {
156  lbne::TpcNanoSlice::Header::nova_timestamp_t seconds_since_nova_epoch = (this_nova_timestamp/nova_time_ticks_per_second);
157  TTimeStamp time_of_event(20100101u,
158  0u,
159  0u,
160  true,
161  seconds_since_nova_epoch);
162  return art::Timestamp(time_of_event.GetSec());
163 }
const lbne::TpcNanoSlice::Header::nova_timestamp_t nova_time_ticks_per_second
std::vector< raw::ExternalTrigger > DAQToOffline::PennFragmentToExternalTrigger ( artdaq::Fragments const &  Fragments,
std::map< int, int > &  channelMap,
lbne::PennMicroSlice::Payload_Timestamp *&  FirstPTBTimestamp 
)

Definition at line 17 of file PennToOffline.cc.

17  {
18 
19  std::vector<raw::ExternalTrigger> ExternTrigs;
20 
21  std::vector<lbne::PennMicroSlice::Payload_Trigger::trigger_type_t> trigger_types = {lbne::PennMicroSlice::Payload_Trigger::TA, // The 'telescope' coincidence...........110
22  lbne::PennMicroSlice::Payload_Trigger::TB, // North upper, South lower coincidence..112
23  lbne::PennMicroSlice::Payload_Trigger::TC, // North lower, South upper coincidence..113
24  lbne::PennMicroSlice::Payload_Trigger::TD};// East lower, West upper coincidence....111
25  std::vector<lbne::PennMicroSlice::Payload_Trigger::trigger_type_t> calib_types = {lbne::PennMicroSlice::Payload_Trigger::C1,
26  lbne::PennMicroSlice::Payload_Trigger::C2,
27  lbne::PennMicroSlice::Payload_Trigger::C3,
28  lbne::PennMicroSlice::Payload_Trigger::C4};
29  std::vector<lbne::PennMicroSlice::Payload_Timestamp::timestamp_t> fCounterTimes;
30  std::vector<lbne::PennMicroSlice::Payload_Timestamp::timestamp_t> fMuonTriggerTimes;
31  std::vector<lbne::PennMicroSlice::Payload_Timestamp::timestamp_t> fSSPTriggerTimes;
32  //std::vector<lbne::PennMicroSlice::Payload_Timestamp::timestamp_t> fRCETriggerTimes;
33  std::vector<lbne::PennMicroSlice::Payload_Timestamp::timestamp_t> fCalibrationTriggerTimes;
34 
35  std::vector<lbne::PennMicroSlice::Payload_Counter> fCounterWords;
36  std::vector<lbne::PennMicroSlice::Payload_Trigger> fMuonTriggers;
37  std::vector<lbne::PennMicroSlice::Payload_Trigger> fSSPTriggers;
38  //std::vector<lbne::PennMicroSlice::Payload_Trigger> fRCETriggers;
39  std::vector<lbne::PennMicroSlice::Payload_Trigger> fCalibrationTriggers;
40 
41  //std::cout << "There are " << Fragments.size() << " fragments" << std::endl;
42  for ( size_t idx = 0; idx < Fragments.size(); ++idx ) {
43  const auto& frag(Fragments[idx]);
44 
45  //Get the PennMilliSliceFragment from the artdaq fragment
46  lbne::PennMilliSliceFragment msf(frag);
47 
48  lbne::PennMicroSlice::Payload_Header *word_header = nullptr;
49  lbne::PennMicroSlice::Payload_Counter *word_p_counter = nullptr;
50  lbne::PennMicroSlice::Payload_Trigger *word_p_trigger = nullptr;
51  lbne::PennMicroSlice::Payload_Timestamp *previous_timestamp = nullptr;
52  lbne::PennMicroSlice::Payload_Header *future_timestamp_header = nullptr;
53  lbne::PennMicroSlice::Payload_Timestamp *future_timestamp = nullptr;
54  uint8_t* payload_data = nullptr;
55  uint32_t payload_index = 0;
56 
57  uint16_t counter, trigger, timestamp, payloadCount;
58  payloadCount = msf.payloadCount(counter, trigger, timestamp);
59 
60  //std::cout << "There are a total of " << counter << " counters, " << trigger << " triggers, " << timestamp << " timestamps, giving a total of " << payloadCount << std::endl;
61 
62  while (payload_index < uint32_t(payloadCount-1) ) {
63  payload_data = msf.get_next_payload(payload_index,word_header);
64  //std::cout << "\nGot payload data " << payload_data << " for index " << payload_index << std::endl;
65  if (payload_data == nullptr)
66  continue;
67  switch(word_header->data_packet_type) {
68 
69  case lbne::PennMicroSlice::DataTypeCounter:
70  word_p_counter = reinterpret_cast<lbne::PennMicroSlice::Payload_Counter*>(payload_data);
71  fCounterWords.push_back(*word_p_counter);
72  GetTimestamp( msf, word_header, previous_timestamp, future_timestamp, future_timestamp_header, fCounterTimes );
73  //std::cout << "Got a counter " << word_p_counter << " with timestamp " << fCounterTimes.back() << std::endl;
74  break; // Counter Type
75 
76  case lbne::PennMicroSlice::DataTypeTrigger:
77  word_p_trigger = reinterpret_cast<lbne::PennMicroSlice::Payload_Trigger*>(payload_data);
78 
79  if (word_p_trigger->has_muon_trigger()) { // If a 'Muon Trigger' ie counter coincidence
80  fMuonTriggers.push_back(*word_p_trigger);
81  GetTimestamp( msf, word_header, previous_timestamp, future_timestamp, future_timestamp_header, fMuonTriggerTimes );
82  //std::cout << "It is a Muon Trigger " << word_p_trigger << " with timestamp " << fMuonTriggerTimes.back() << std::endl;
83  }
84  if (word_p_trigger->has_ssp_trigger()) { // If an 'SSP Trigger'
85  fSSPTriggers.push_back(*word_p_trigger);
86  GetTimestamp( msf, word_header, previous_timestamp, future_timestamp, future_timestamp_header, fSSPTriggerTimes );
87  //std::cout << "It is an SSP Trigger " << word_p_trigger << " with timestamp " << fSSPTriggerTimes.back() << std::endl;
88  }
89  /*
90  if (word_p_trigger->has_rce_trigger() ) { // If an 'RCE Trigger'
91  fRCETriggers.push_back(*word_p_trigger);
92  GetTimestamp( msf, word_header, previous_timestamp, future_timestamp, future_timestamp_header, fRCETriggerTimes );
93  //std::cout << "It is an RCE Trigger " << word_p_trigger << " with timestamp " << fRCETriggerTimes.back() << std::endl;
94  }
95  */
96  if (word_p_trigger->has_calibration()) { // If a 'Calibration Trigger'
97  fCalibrationTriggers.push_back(*word_p_trigger);
98  GetTimestamp( msf, word_header, previous_timestamp, future_timestamp, future_timestamp_header, fCalibrationTriggerTimes );
99  //std::cout << "It is a Calibration Trigger " << word_p_trigger << " with timestamp " << fCalibrationTriggerTimes.back() << std::endl;
100  }
101 
102  break; // Trigger Type
103 
104  case lbne::PennMicroSlice::DataTypeTimestamp:
105  previous_timestamp = reinterpret_cast<lbne::PennMicroSlice::Payload_Timestamp*>(payload_data);
106  if (FirstPTBTimestamp == nullptr) FirstPTBTimestamp = previous_timestamp;
107  //std::cout << "Got a timestamp " << previous_timestamp << " " << previous_timestamp->nova_timestamp << ", the first timestamp in this event is " << FirstPTBTimestamp << " " << FirstPTBTimestamp->nova_timestamp << std::endl;
108  break; // Timestamp Type
109 
110  default:
111  //std::cout << "It isn't a counter, trigger or timestamp. It is a " << std::bitset<3>(word_header->data_packet_type) << std::endl;
112  break; // Default case - do nothing.
113  } // switch/case
114  }
115  } // NumFragments
116 
117  // *************** Now I want to loop over all counters and find out when they turned on to make ExternalTriggers ****************
118  for (int counter_index=0; counter_index<98; ++counter_index ) {
119  bool counter_previously_on = true;
120  for (uint32_t pos = 0; pos < fCounterWords.size(); ++pos) {
121  bool counter_currently_on = fCounterWords.at(pos).get_counter_status(counter_index);
122  //std::cout << "Looking at counter " << counter_index << " which in the map is channel " << channelMap[counter_index]
123  // << ", position " << pos << ", PrevOn? " << counter_previously_on << ", NowOn? " << counter_currently_on << std::endl;
124  bool MakeNewExtCount = MakeNewExtTrig(pos, counter_previously_on, counter_currently_on);
125  if (MakeNewExtCount) {
126  raw::ExternalTrigger counter( channelMap[counter_index], fCounterTimes.at(pos) );
127  ExternTrigs.push_back(counter);
128  //std::cout << "Made my new trigger, TrigID " << ExternTrigs.back().GetTrigID() << " (" << counter.GetTrigID() << ") TrigTime "
129  // << ExternTrigs.back().GetTrigTime() << " (" << counter.GetTrigTime() << ")" << std::endl;
130  }
131  } // Loop over counter word size
132  } // Loop over channels.
133 
134  // *************** Now to loop through 'MUON TRIGGERS' ****************
135  bool trigA_previously_on = false, trigB_previously_on = false, trigC_previously_on = false, trigD_previously_on = false;
136  for (uint32_t pos = 0; pos < fMuonTriggers.size(); ++pos) {
137  bool trigA_currently_on = fMuonTriggers.at(pos).has_muon_TA();
138  bool trigB_currently_on = fMuonTriggers.at(pos).has_muon_TB();
139  bool trigC_currently_on = fMuonTriggers.at(pos).has_muon_TC();
140  bool trigD_currently_on = fMuonTriggers.at(pos).has_muon_TD();
141  lbne::PennMicroSlice::Payload_Timestamp::timestamp_t current_trigger_time = fMuonTriggerTimes.at(pos);
142  bool MakeNewExtTrigA, MakeNewExtTrigB, MakeNewExtTrigC, MakeNewExtTrigD;
143  if (pos == 0) {
144  MakeNewExtTrigA = trigA_previously_on = trigA_currently_on;
145  MakeNewExtTrigB = trigA_previously_on = trigB_currently_on;
146  MakeNewExtTrigC = trigA_previously_on = trigC_currently_on;
147  MakeNewExtTrigD = trigA_previously_on = trigD_currently_on;
148  } else {
149  MakeNewExtTrigA = MakeNewExtTrig( pos, trigA_previously_on, trigA_currently_on );
150  MakeNewExtTrigB = MakeNewExtTrig( pos, trigB_previously_on, trigB_currently_on );
151  MakeNewExtTrigC = MakeNewExtTrig( pos, trigC_previously_on, trigC_currently_on );
152  MakeNewExtTrigD = MakeNewExtTrig( pos, trigD_previously_on, trigD_currently_on );
153  }
154  //std::cout << "Looking at element " << pos << " of " << fMuonTriggers.size() << "." << std::endl;
155  //std::cout << "Trigs prev on (A,B,C,D) (" << trigA_previously_on <<","<< trigB_previously_on <<","<< trigC_previously_on <<","<< trigD_previously_on <<")." << std::endl;
156  //std::cout << "And now (" << trigA_currently_on <<","<< trigB_currently_on <<","<< trigC_currently_on <<","<< trigD_currently_on << ")." << std::endl;;
157  //std::cout << "So do I make a trigger? (" << MakeNewExtTrigA <<","<< MakeNewExtTrigB <<","<< MakeNewExtTrigC <<","<< MakeNewExtTrigD <<")."<< std::endl;
158  if (MakeNewExtTrigA) {
159  //std::cout << "Making an external trigger from Trigger A!!" << std::endl;
160  raw::ExternalTrigger counter( 110, current_trigger_time );
161  ExternTrigs.push_back(counter);
162  }
163  if (MakeNewExtTrigB) {
164  //std::cout << "Making an external trigger from Trigger B!!" << std::endl;
165  raw::ExternalTrigger counter( 112, current_trigger_time );
166  ExternTrigs.push_back(counter);
167  }
168  if (MakeNewExtTrigC) {
169  //std::cout << "Making an external trigger from Trigger C!!" << std::endl;
170  raw::ExternalTrigger counter( 113, current_trigger_time );
171  ExternTrigs.push_back(counter);
172  }
173  if (MakeNewExtTrigD) {
174  //std::cout << "Making an external trigger from Trigger D!!" << std::endl;
175  raw::ExternalTrigger counter( 111, current_trigger_time );
176  ExternTrigs.push_back(counter);
177  }
178  } // Loop over Muon Triggers
179 
180  // *************** Now to loop through 'SSP TRIGGERS' ****************
181  for (uint32_t pos = 0; pos < fSSPTriggers.size(); ++pos) {
182  //std::cout << "Making an external trigger from SSP trigger!!" << std::endl;
183  lbne::PennMicroSlice::Payload_Timestamp::timestamp_t current_trigger_time = fSSPTriggerTimes.at(pos);
184  raw::ExternalTrigger counter( 115, current_trigger_time );
185  }
186 
187  // *************** Now to loop through 'RCE TRIGGERS' ****************
188  /*
189  for (uint32_t pos = 0; pos < fRCETriggers.size(); ++pos) {
190  //std::cout << "Making an external trigger from RCE trigger!!" << std::endl;
191  lbne::PennMicroSlice::Payload_Timestamp::timestamp_t current_trigger_time = fRCETriggerTimes.at(pos);
192  raw::ExternalTrigger counter( 116, current_trigger_time ); // WHAT CHANNEL DOES AN RCE TRIGGER GO ON!!!????
193  }
194  */
195 
196  //std::cout << "\n\nAll done, lets loop through ExternTrigs...." << std::endl;
197  for ( std::vector<raw::ExternalTrigger>::const_iterator TrigIt = ExternTrigs.begin(); TrigIt != ExternTrigs.end(); TrigIt++ ) {
198  //std::cout << "Looking at index " << std::distance((std::vector<raw::ExternalTrigger>::const_iterator)ExternTrigs.begin(), TrigIt) << " which has indexes " << TrigIt->GetTrigID() << ", " << TrigIt->GetTrigTime() << std::endl;
199  }
200 
201  return ExternTrigs;
202 }
unsigned short uint16_t
Definition: stdint.h:125
intermediate_table::const_iterator const_iterator
unsigned char uint8_t
Definition: stdint.h:124
void GetTimestamp(lbne::PennMilliSliceFragment msf, lbne::PennMicroSlice::Payload_Header *&word_header, lbne::PennMicroSlice::Payload_Timestamp *const &previous_timestamp, lbne::PennMicroSlice::Payload_Timestamp *&future_timestamp, lbne::PennMicroSlice::Payload_Header *&future_timestamp_header, std::vector< lbne::PennMicroSlice::Payload_Timestamp::timestamp_t > &TimeVector)
bool MakeNewExtTrig(uint32_t pos, bool &PrevOn, bool NowOn)
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
std::vector< raw::RawDigit > DAQToOffline::tpcFragmentToRawDigits ( artdaq::Fragments const &  rawFragments,
std::vector< std::pair< std::pair< unsigned int, unsigned int >, lbne::TpcNanoSlice::Header::nova_timestamp_t > > &  DigitsIndexList,
lbne::TpcNanoSlice::Header::nova_timestamp_t &  firstTimestamp,
art::ServiceHandle< lbne::ChannelMapService > const &  channelMap,
bool  useChannelMap,
bool  debug,
raw::Compress_t  compression,
unsigned int  zeroThreshold 
)

Definition at line 7 of file tpcFragmentToRawDigits.cc.

11  {
12 
13  DigitsIndexList.clear();
14  //Create a map containing (fragmentID, fragIndex) for the event, will be used to check if each channel is present
15  unsigned int numFragments = rawFragments.size();
16  bool TimestampSet = false;
17 
18  std::map < unsigned int, unsigned int > mapFragID;
19 
20  for(size_t fragIndex = 0; fragIndex < rawFragments.size(); fragIndex++){
21 
22  const artdaq::Fragment &singleFragment = rawFragments[fragIndex];
23 
24  unsigned int fragmentID = singleFragment.fragmentID();
25 
26  mapFragID.insert(std::pair<unsigned int, unsigned int>(fragmentID,fragIndex));
27  }
28 
29 
30  if(debug){
31  std::cout << numFragments<< " rawFragments" << std::endl;
32  }
33 
34  std::vector<raw::RawDigit> rawDigitVector;
35 
36  //JPD -- first go at unpacking the information
37  // -- seems to make sense to look through channel number,
38  // -- then we'll create a rawDigit object for each channel
39  // -- will need some helper functions to do this for us, so I created a utilites directory
40 
42  size_t numChans = geometry->Nchannels();
43  for(size_t chan=0;chan < numChans;chan++){
44 
45  //Each channel is uniquely identified by (fragmentID, group, sample) in an online event
46 
47  unsigned int fragmentID = UnpackFragment::getFragIDForChan(chan);
48  unsigned int sample = UnpackFragment::getNanoSliceSampleForChan(chan);
49 
50  if (debug) {
51  std::cout << "channel: " << chan
52  << "\tfragment: " << fragmentID
53  //<< "\tgroup: " << group
54  << "\tsample: " << sample
55  << std::endl;
56  }
57 
58  //Check that the necessary fragmentID is present in the event
59  //i.e. do we have data for this channel?
60 
61  if( mapFragID.find(fragmentID) == mapFragID.end() ){
62 
63  if (debug) std::cout << "Fragment not found" << std::endl;
64  continue;
65 
66  }
67 
68  unsigned int fragIndex = mapFragID[fragmentID];
69 
70  if (debug) std::cout << "fragIndex: " << fragIndex << std::endl;
71 
72  std::vector<short> adcvec;
73 
74 
75  const artdaq::Fragment &singleFragment = rawFragments[fragIndex];
76  lbne::TpcMilliSliceFragment millisliceFragment(singleFragment);
77 
78  //Properties of fragment
79  auto numMicroSlices = millisliceFragment.microSliceCount();
80  bool FirstMicro = false;
81  unsigned int FirstGoodIndex = 0;
82  unsigned int LastGoodIndex = 0;
83  bool PrevMicroRCE = false;
84  lbne::TpcNanoSlice::Header::nova_timestamp_t ThisTimestamp = 0;
85  bool MadeList = DigitsIndexList.size();
86  for(unsigned int i_micro=0;i_micro<numMicroSlices;i_micro++){
87  std::unique_ptr <const lbne::TpcMicroSlice> microSlice = millisliceFragment.microSlice(i_micro);
88  auto numNanoSlices = microSlice->nanoSliceCount();
89 
90  // Push back adcvec with the ADC values.
91  for(uint32_t i_nano=0; i_nano < numNanoSlices; i_nano++){
93  bool success = microSlice->nanosliceSampleValue(i_nano, sample, val);
94  if(success) adcvec.push_back(short(val));
95  }
96 
97  if ( chan%128==0 ) {
98  //std::cout << "Looking at microslice " << i_micro << ", it has " << numNanoSlices << " nanoslices." << std::endl;
99  // Get the First Timestamp for this channel
100  if (!FirstMicro && numNanoSlices) {
101  lbne::TpcNanoSlice::Header::nova_timestamp_t Timestamp = microSlice->nanoSlice(0)->nova_timestamp();
102  FirstMicro=true;
103  if (!TimestampSet || Timestamp < firstTimestamp) {
104  //std::cout << "!!!Resetting timestamp to " << Timestamp << " on Chan " << chan << ",Micro " << i_micro << "!!!" << std::endl;
105  firstTimestamp = Timestamp;
106  TimestampSet = true;
107  }
108  }
109  // Which indexes have RCE information?
110  if (!MadeList) {
111  if (numNanoSlices) {
112  LastGoodIndex = LastGoodIndex + numNanoSlices;
113  if (PrevMicroRCE == false)
114  ThisTimestamp = microSlice->nanoSlice(0)->nova_timestamp();
115  }
116  if (PrevMicroRCE == true && ( !numNanoSlices || i_micro==numMicroSlices-1 ) ) {
117  //std::cout << "This is the end of a good set of RCEs, so want to add a pair to my vector...." << std::endl;
118  DigitsIndexList.push_back( std::make_pair( std::make_pair(FirstGoodIndex,LastGoodIndex-1), ThisTimestamp) );
119  FirstGoodIndex = LastGoodIndex;
120  }
121  PrevMicroRCE = (bool)numNanoSlices;
122  } // If not made index list
123  } // Do stuff once for each RCE...
124  }
125  // Make my list of good RCEs
126  if (DigitsIndexList.size() && !MadeList ) {
127  //std::cout << "Finished looking through microslices. DigitsIndexList has size " << DigitsIndexList.size() << ", the useful things were in these microslices." << std::endl;
128  //for (size_t qq=0; qq<DigitsIndexList.size(); ++qq)
129  //std::cout << "Looking at element " << qq << " start " << DigitsIndexList[qq].first.first << ", end " << DigitsIndexList[qq].first.second << " timestamp " << DigitsIndexList[qq].second << std::endl;
130  }
131 
132  if (debug) std::cout << "adcvec->size(): " << adcvec.size() << std::endl;
133  unsigned int numTicks = adcvec.size();
134  raw::Compress(adcvec, compression, zeroThreshold);
135  int offlineChannel = -1;
136  if (useChannelMap) offlineChannel = channelMap->Offline(chan);
137  else offlineChannel = chan;
138  raw::RawDigit theRawDigit(offlineChannel, numTicks, adcvec, compression);
139  rawDigitVector.push_back(theRawDigit); // add this digit to the collection
140  }
141 
142  return rawDigitVector;
143 }
Collection of charge vs time digitized from a single readout channel.
Definition: RawDigit.h:69
unsigned int getNanoSliceSampleForChan(unsigned int channel)
unsigned short uint16_t
Definition: stdint.h:125
unsigned int Nchannels() const
Returns the number of TPC readout channels in the detector.
unsigned int getFragIDForChan(unsigned int channel)
unsigned int uint32_t
Definition: stdint.h:126
static int max(int a, int b)
void Compress(std::vector< short > &adc, raw::Compress_t compress)
Compresses a raw data buffer.
Definition: raw.cxx:19
int bool
Definition: qglobal.h:345
QTextStream & endl(QTextStream &s)

Variable Documentation

const lbne::TpcNanoSlice::Header::nova_timestamp_t DAQToOffline::nova_time_ticks_per_second = 64e6

Definition at line 44 of file tpcFragmentToRawDigits.h.