ShmMilliBlock.cpp
Go to the documentation of this file.
1 // This file (getMilliBlock.cpp) was created by Ron Rechenmacher <ron@fnal.gov> on
2 // Nov 4, 2011. "TERMS AND CONDITIONS" governing this file are in the README
3 // or COPYING file. If you do not have such a file, one can be obtained by
4 // contacting Ron or Fermi Lab in Batavia IL, 60510, phone: 630-840-3000.
5 // $RCSfile: ShmMilliBlock.cpp,v $
6 // rev="$Revision: 1.7 $$Date: 2012/09/25 18:46:00 $";
7 
8 #include <string.h> // memcpy
9 #include "../include/ShmMilliBlock.h"
10 #include "DAQDataFormats/RawMilliBlockHeader.h"
11 #include "DAQDataFormats/RawMilliBlock.h"
12 using namespace daqdataformats;
13 
14 bool
16  , RawMilliBlock & mb )
17 {
18  uint64_t start=shm_rd_.get_us_timeofday();
20  shm_rdwr_header *shm_info_ptr;
21  ShmRdWrCnt missed;
22  uint32_t cushion;
23  int new_tmo=tmo_us;
24  std::vector<RawMilliSlice> rms_vec;
26 
27  mb.set_ovrwrt( false );
28 
29  shm_info_ptr = shm_rd_.get_ptr();
30  if (shm_info_ptr == (void*)-1)
31  {
32  if (shm_rd_.attach()!=0) return (false);
33  shm_info_ptr = shm_rd_.get_ptr();
34  my_area_.resize( shm_info_ptr->buf_sz_bytes/sizeof(uint32_t), 0 );
35  }
36 
37 
38  do
39  {
40  int sts=shm_rd_.start_read( &hdr, missed, cushion, new_tmo );
41  if (sts > 0)
42  {
43 
44  memcpy( &my_area_[0], hdr, hdr->bytes_total );
45  sts = shm_rd_.check_overwrite( missed, cushion );
46  if (sts != 0)
47  { // assume problem
48  mb.set_ovrwrt( true );
49  break;
50  }
51  hdr = (shm_rdwr_buffer_header*)&my_area_[0];
54  rmbh=*rmbhp;
55  void * msdataptr=(void*)(rmbhp+1);
56 
57  rms_vec.reserve(rmbh.millislice_count);
58 
59  uint32_t retrieved_millislice=0;
60  for (; retrieved_millislice<rmbh.millislice_count; ++retrieved_millislice)
61  {
62  // get the millislice size
63  rms_vec.push_back( rms_tmp );
64  msdataptr = rms_vec[retrieved_millislice].readData( msdataptr );
65  }
66  //printf("retrieved_millislice=%u\n", retrieved_millislice );
67  shm_rd_.end_read( missed, cushion );
68  if (retrieved_millislice)
69  { // If at least one slice, then rmbh stuff is good
70  mb.set( rmbh.seqNum, rmbh.timeStart, rmbh.timeEnd
71  , rmbh.flags.truncated );
72  mb.slices.swap( rms_vec ); // swap vectors
73  return (true);
74  }
75  else
76  { mb.set_tmo( false );
77  return (false);
78  }
79  }
80  } while ((new_tmo=tmo_us-(shm_rd_.get_us_timeofday()-start)) > 0);
81  mb.set_tmo( true );
82  return (false);
83 } // getMilliBlock
void set_tmo(bool tmo)
Definition: RawMilliBlock.h:32
uint32_t ShmRdWrCnt
Definition: ShmRdWr.h:29
std::vector< daqdataformats::RawMilliSlice > slices
Definition: RawMilliBlock.h:35
#define shm_rdwr_header
Definition: ShmRdWr.h:26
void set_ovrwrt(bool ovrwrt)
Definition: RawMilliBlock.h:33
#define shm_rdwr_buffer_header
Definition: ShmRdWr.h:25
Class to hold the data from the FEBs in correct formats.
struct RawMilliBlockHeader::@12 flags
bool getMilliBlock(uint32_t tmo_us, RawMilliBlock &mb)
int set(uint32_t sn, uint64_t start, uint64_t end, bool ovrflw)
Definition: RawMilliBlock.h:26