CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Public Types | Public Member Functions | Private Attributes
FileReaderDDU Class Reference

#include <FileReaderDDU.h>

Public Types

enum  {
  Header = 1, Trailer = 2, DDUoversize = 4, FFFF = 8,
  Unknown = 16, EndOfStream = 32
}
 
enum  {
  Type1 = Header | Trailer, Type2 = Header, Type3 = Header | DDUoversize, Type4 = Trailer,
  Type5 = Unknown, Type6 = Unknown | DDUoversize, Type7 = FFFF
}
 

Public Member Functions

void accept (unsigned int criteria) throw ()
 
 FileReaderDDU (void)
 
size_t next (const unsigned short *&buf, int prescaling=1)
 
int open (const char *filename)
 
size_t read (const unsigned short *&buf)
 
void reject (unsigned int criteria) throw ()
 
void select (unsigned int criteria) throw ()
 
unsigned int status (void) const throw ()
 
virtual ~FileReaderDDU (void)
 

Private Attributes

unsigned int acceptCriteria
 
unsigned long long * end
 
unsigned int eventStatus
 
int fd
 
unsigned long long file_buffer [4000]
 
unsigned long long * file_buffer_end
 
unsigned short raw_event [200000]
 
unsigned int rejectCriteria
 
unsigned int selectCriteria
 
unsigned long long word_0
 
unsigned long long word_1
 
unsigned long long word_2
 

Detailed Description

Definition at line 7 of file FileReaderDDU.h.

Member Enumeration Documentation

anonymous enum
Enumerator
Header 
Trailer 
DDUoversize 
FFFF 
Unknown 
EndOfStream 

Definition at line 17 of file FileReaderDDU.h.

anonymous enum

Constructor & Destructor Documentation

FileReaderDDU::FileReaderDDU ( void  )

Definition at line 15 of file FileReaderDDU.cc.

References acceptCriteria, DDUoversize, end, eventStatus, fd, FFFF, file_buffer, file_buffer_end, raw_event, rejectCriteria, selectCriteria, AlCaHLTBitMon_QueryRunRegistry::string, Trailer, Unknown, word_0, word_1, and word_2.

15  {
16  if (sizeof(unsigned long long) != 8 || sizeof(unsigned short) != 2)
17  throw std::runtime_error(std::string("Wrong platform: sizeof(unsigned long long)!=8 || sizeof(unsigned short)!=2"));
18  end = (file_buffer_end = file_buffer + sizeof(file_buffer) / sizeof(unsigned long long));
19  bzero(raw_event, sizeof(raw_event));
20  bzero(file_buffer, sizeof(file_buffer));
21  word_0 = 0;
22  word_1 = 0;
23  word_2 = 0;
24  eventStatus = 0;
27  acceptCriteria = 0x3F; // Everything
28  fd = 0;
29 }
unsigned int rejectCriteria
Definition: FileReaderDDU.h:28
unsigned long long word_2
Definition: FileReaderDDU.h:11
unsigned short raw_event[200000]
Definition: FileReaderDDU.h:9
unsigned int acceptCriteria
Definition: FileReaderDDU.h:28
unsigned long long word_0
Definition: FileReaderDDU.h:11
unsigned long long * file_buffer_end
Definition: FileReaderDDU.h:14
unsigned int eventStatus
Definition: FileReaderDDU.h:28
unsigned long long file_buffer[4000]
Definition: FileReaderDDU.h:12
unsigned int selectCriteria
Definition: FileReaderDDU.h:28
unsigned long long word_1
Definition: FileReaderDDU.h:11
unsigned long long * end
Definition: FileReaderDDU.h:14
FileReaderDDU::~FileReaderDDU ( void  )
virtual

Definition at line 31 of file FileReaderDDU.cc.

References fd.

31  {
32  if (fd)
33  close(fd);
34 }

Member Function Documentation

void FileReaderDDU::accept ( unsigned int  criteria)
throw (
)
inline

Definition at line 38 of file FileReaderDDU.h.

References acceptCriteria.

Referenced by esMonitoring.FDJsonServer::handle_accept().

38  {
39  acceptCriteria = criteria;
40  } // return all events satisfying any of criteria
unsigned int acceptCriteria
Definition: FileReaderDDU.h:28
size_t FileReaderDDU::next ( const unsigned short *&  buf,
int  prescaling = 1 
)

Definition at line 142 of file FileReaderDDU.cc.

References acceptCriteria, eventStatus, mps_fire::i, read(), rejectCriteria, selectCriteria, and findQualityFiles::size.

Referenced by BeautifulSoup.PageElement::_invert(), and CSCFileReader::readRUI().

142  {
143  size_t size = 0;
144  for (int i = 0; i < prescaling; i++) {
145  do {
146  if ((size = read(buf)) == 0)
147  break;
149  (selectCriteria ? selectCriteria != eventStatus : 0));
150  }
151  return size;
152 }
unsigned int rejectCriteria
Definition: FileReaderDDU.h:28
size_t read(const unsigned short *&buf)
unsigned int acceptCriteria
Definition: FileReaderDDU.h:28
unsigned int eventStatus
Definition: FileReaderDDU.h:28
unsigned int selectCriteria
Definition: FileReaderDDU.h:28
tuple size
Write out results.
int FileReaderDDU::open ( const char *  filename)

Definition at line 36 of file FileReaderDDU.cc.

References bitset_utilities::append(), fd, O_LARGEFILE, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by CSCFileReader::CSCFileReader(), and CSCFileReader::readRUI().

36  {
37  if (fd)
38  close(fd);
39  fd = ::open(filename, O_RDONLY | O_LARGEFILE);
40  if (fd == -1)
41  throw(std::runtime_error(std::string("Error opening ").append(filename).append(" data file.")));
42  return fd;
43 }
boost::dynamic_bitset append(const boost::dynamic_bitset<> &bs1, const boost::dynamic_bitset<> &bs2)
this method takes two bitsets bs1 and bs2 and returns result of bs2 appended to the end of bs1 ...
#define O_LARGEFILE
tuple filename
Definition: lut2db_cfg.py:20
int open(const char *filename)
size_t FileReaderDDU::read ( const unsigned short *&  buf)

Definition at line 45 of file FileReaderDDU.cc.

References DDUoversize, end, EndOfStream, edmPickEvents::event, eventStatus, fd, FFFF, file_buffer, file_buffer_end, Header, raw_event, command_line::start, Trailer, Unknown, word_0, word_1, and word_2.

Referenced by edmIntegrityCheck.PublishToFileSystem::get(), and next().

45  {
46  // Check for ubnormal situation
48  throw(std::runtime_error("Error of reading"));
49  if (!fd)
50  throw(std::runtime_error("Open some file first"));
51 
52  unsigned long long *start = end;
53  unsigned short *event = raw_event;
54 
55  eventStatus = 0;
56  size_t dduWordCount = 0;
57  end = nullptr;
58 
59  while (!end && dduWordCount < 50000) {
60  unsigned long long *dduWord = start;
61  unsigned long long preHeader = 0;
62 
63  // Did we reach end of current buffer and want to read next block?
64  // If it was first time and we don't have file buffer then we won't get inside
65  while (dduWord < file_buffer_end && dduWordCount < 50000) {
66  word_0 = word_1; // delay by 2 DDU words
67  word_1 = word_2; // delay by 1 DDU word
68  word_2 = *dduWord; // current DDU word
69  if ((word_2 & 0xFFFFFFFFFFFF0000LL) == 0x8000000180000000LL) {
70  if (eventStatus & Header) // Second header
71  {
72  word_2 = word_1; // Fall back to get rigth preHeader next time
73  end = dduWord; // Even if we end with preHeader of next evet put it to the end of this event too
74  break;
75  }
76  if (dduWordCount > 1) // Extra words between trailer and header
77  {
78  if ((word_0 & 0xFFFFFFFFFFFF0000LL) == 0xFFFFFFFFFFFF0000LL)
79  eventStatus |= FFFF;
80  word_2 = word_1; // Fall back to get rigth preHeader next time
81  end = dduWord;
82  break;
83  }
85  if (event == raw_event)
86  preHeader = word_1; // If preHeader not yet in event then put it there
87  start = dduWord;
88  }
89  if ((word_0 & 0xFFFFFFFFFFFF0000LL) == 0x8000FFFF80000000LL) {
91  end = ++dduWord;
92  break;
93  }
94  // Increase counters by one DDU word
95  dduWord++;
96  dduWordCount++;
97  }
98 
99  // If have DDU Header
100  if (preHeader) {
101  // Need to account first word of DDU Header
102  memcpy(event, &preHeader, sizeof(preHeader));
103  event += sizeof(preHeader) / sizeof(unsigned short);
104  }
105 
106  // Take care of the rest
107  memcpy(event, start, (dduWord - start) * sizeof(unsigned long long));
108  event += (dduWord - start) * sizeof(unsigned long long) / sizeof(unsigned short);
109 
110  // If reach max length
111  if (dduWordCount == 50000) {
112  end = dduWord;
113  break;
114  }
115 
116  if (!end) {
117  // Need to read next block for the rest of this event
118  ssize_t length = ::read(fd, file_buffer, sizeof(file_buffer));
119  if (length == -1)
120  throw(std::runtime_error("Error of reading"));
121  if (length == 0) {
123  end = (file_buffer_end = file_buffer + sizeof(file_buffer) / sizeof(unsigned long long));
124  break;
125  }
126  file_buffer_end = file_buffer + length / sizeof(unsigned long long);
127 
128  // Will start from the beginning of new buffer next time we read it
129  start = file_buffer;
130  }
131  }
132 
133  if (!end)
135  if (!(eventStatus & Header) && !(eventStatus & Trailer) && !(eventStatus & FFFF))
136  eventStatus |= Unknown;
137 
138  buf = (const unsigned short *)raw_event;
139  return (eventStatus & FFFF ? event - raw_event - 4 : event - raw_event);
140 }
unsigned long long word_2
Definition: FileReaderDDU.h:11
size_t read(const unsigned short *&buf)
unsigned short raw_event[200000]
Definition: FileReaderDDU.h:9
unsigned long long word_0
Definition: FileReaderDDU.h:11
unsigned long long * file_buffer_end
Definition: FileReaderDDU.h:14
unsigned int eventStatus
Definition: FileReaderDDU.h:28
unsigned long long file_buffer[4000]
Definition: FileReaderDDU.h:12
unsigned long long word_1
Definition: FileReaderDDU.h:11
unsigned long long * end
Definition: FileReaderDDU.h:14
void FileReaderDDU::reject ( unsigned int  criteria)
throw (
)
inline

Definition at line 41 of file FileReaderDDU.h.

References rejectCriteria.

Referenced by CSCFileReader::CSCFileReader().

41  {
42  rejectCriteria = criteria;
43  } // return events not satisfying any of criteria
unsigned int rejectCriteria
Definition: FileReaderDDU.h:28
void FileReaderDDU::select ( unsigned int  criteria)
throw (
)
inline

Definition at line 37 of file FileReaderDDU.h.

References selectCriteria.

Referenced by CSCFileReader::CSCFileReader().

37 { selectCriteria = criteria; } // return events satisfying all criteria
unsigned int selectCriteria
Definition: FileReaderDDU.h:28
unsigned int FileReaderDDU::status ( void  ) const
throw (
)
inline

Definition at line 45 of file FileReaderDDU.h.

References eventStatus.

45 { return eventStatus; }
unsigned int eventStatus
Definition: FileReaderDDU.h:28

Member Data Documentation

unsigned int FileReaderDDU::acceptCriteria
private

Definition at line 28 of file FileReaderDDU.h.

Referenced by accept(), FileReaderDDU(), and next().

unsigned long long* FileReaderDDU::end
private
unsigned int FileReaderDDU::eventStatus
private

Definition at line 28 of file FileReaderDDU.h.

Referenced by FileReaderDDU(), next(), read(), and status().

int FileReaderDDU::fd
private
unsigned long long FileReaderDDU::file_buffer[4000]
private

Definition at line 12 of file FileReaderDDU.h.

Referenced by FileReaderDDU(), and read().

unsigned long long * FileReaderDDU::file_buffer_end
private

Definition at line 14 of file FileReaderDDU.h.

Referenced by FileReaderDDU(), and read().

unsigned short FileReaderDDU::raw_event[200000]
private

Definition at line 9 of file FileReaderDDU.h.

Referenced by FileReaderDDU(), and read().

unsigned int FileReaderDDU::rejectCriteria
private

Definition at line 28 of file FileReaderDDU.h.

Referenced by FileReaderDDU(), next(), and reject().

unsigned int FileReaderDDU::selectCriteria
private

Definition at line 28 of file FileReaderDDU.h.

Referenced by FileReaderDDU(), next(), and select().

unsigned long long FileReaderDDU::word_0
private

Definition at line 11 of file FileReaderDDU.h.

Referenced by FileReaderDDU(), and read().

unsigned long long FileReaderDDU::word_1
private

Definition at line 11 of file FileReaderDDU.h.

Referenced by FileReaderDDU(), and read().

unsigned long long FileReaderDDU::word_2
private

Definition at line 11 of file FileReaderDDU.h.

Referenced by FileReaderDDU(), and read().