CMS 3D CMS Logo

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

anonymous enum
Enumerator
Header 
Trailer 
DDUoversize 
FFFF 
Unknown 
EndOfStream 

Definition at line 17 of file FileReaderDDU.h.

17 { Header = 1, Trailer = 2, DDUoversize = 4, FFFF = 8, Unknown = 16, EndOfStream = 32 };

◆ anonymous enum

anonymous enum
Enumerator
Type1 
Type2 
Type3 
Type4 
Type5 
Type6 
Type7 

Definition at line 18 of file FileReaderDDU.h.

18  {
19  Type1 = Header | Trailer,
20  Type2 = Header,
22  Type4 = Trailer,
23  Type5 = Unknown,
25  Type7 = FFFF
26  }; // Andrey Korytov's notations

Constructor & Destructor Documentation

◆ FileReaderDDU()

FileReaderDDU::FileReaderDDU ( void  )

Definition at line 15 of file FileReaderDDU.cc.

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 }

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.

◆ ~FileReaderDDU()

FileReaderDDU::~FileReaderDDU ( void  )
virtual

Definition at line 31 of file FileReaderDDU.cc.

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

References fd.

Member Function Documentation

◆ accept()

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

Definition at line 38 of file FileReaderDDU.h.

38  {
39  acceptCriteria = criteria;
40  } // return all events satisfying any of criteria

References acceptCriteria.

Referenced by esMonitoring.FDJsonServer::handle_accept().

◆ next()

size_t FileReaderDDU::next ( const unsigned short *&  buf,
int  prescaling = 1 
)

Definition at line 142 of file FileReaderDDU.cc.

142  {
143  size_t size = 0;
144  for (int i = 0; i < prescaling; i++) {
145  do {
146  if ((size = read(buf)) == 0)
147  break;
150  }
151  return size;
152 }

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

Referenced by CSCFileReader::readRUI().

◆ open()

int FileReaderDDU::open ( const char *  filename)

Definition at line 36 of file FileReaderDDU.cc.

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 }

References mps_setup::append, fd, corrVsCorr::filename, O_LARGEFILE, and AlCaHLTBitMon_QueryRunRegistry::string.

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

◆ read()

size_t FileReaderDDU::read ( const unsigned short *&  buf)

Definition at line 45 of file FileReaderDDU.cc.

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 }

References visDQMUpload::buf, DDUoversize, end, EndOfStream, 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().

◆ reject()

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

Definition at line 41 of file FileReaderDDU.h.

41  {
42  rejectCriteria = criteria;
43  } // return events not satisfying any of criteria

References rejectCriteria.

Referenced by CSCFileReader::CSCFileReader().

◆ select()

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

Definition at line 37 of file FileReaderDDU.h.

37 { selectCriteria = criteria; } // return events satisfying all criteria

References selectCriteria.

Referenced by CSCFileReader::CSCFileReader().

◆ status()

unsigned int FileReaderDDU::status ( void  ) const
throw (
)
inline

Definition at line 45 of file FileReaderDDU.h.

45 { return eventStatus; }

References eventStatus.

Member Data Documentation

◆ acceptCriteria

unsigned int FileReaderDDU::acceptCriteria
private

Definition at line 28 of file FileReaderDDU.h.

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

◆ end

unsigned long long* FileReaderDDU::end
private

◆ eventStatus

unsigned int FileReaderDDU::eventStatus
private

Definition at line 28 of file FileReaderDDU.h.

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

◆ fd

int FileReaderDDU::fd
private

◆ file_buffer

unsigned long long FileReaderDDU::file_buffer[4000]
private

Definition at line 12 of file FileReaderDDU.h.

Referenced by FileReaderDDU(), and read().

◆ file_buffer_end

unsigned long long * FileReaderDDU::file_buffer_end
private

Definition at line 14 of file FileReaderDDU.h.

Referenced by FileReaderDDU(), and read().

◆ raw_event

unsigned short FileReaderDDU::raw_event[200000]
private

Definition at line 9 of file FileReaderDDU.h.

Referenced by FileReaderDDU(), and read().

◆ rejectCriteria

unsigned int FileReaderDDU::rejectCriteria
private

Definition at line 28 of file FileReaderDDU.h.

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

◆ selectCriteria

unsigned int FileReaderDDU::selectCriteria
private

Definition at line 28 of file FileReaderDDU.h.

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

◆ word_0

unsigned long long FileReaderDDU::word_0
private

Definition at line 11 of file FileReaderDDU.h.

Referenced by FileReaderDDU(), and read().

◆ word_1

unsigned long long FileReaderDDU::word_1
private

Definition at line 11 of file FileReaderDDU.h.

Referenced by FileReaderDDU(), and read().

◆ word_2

unsigned long long FileReaderDDU::word_2
private

Definition at line 11 of file FileReaderDDU.h.

Referenced by FileReaderDDU(), and read().

FileReaderDDU::Type2
Definition: FileReaderDDU.h:20
FileReaderDDU::rejectCriteria
unsigned int rejectCriteria
Definition: FileReaderDDU.h:28
mps_fire.i
i
Definition: mps_fire.py:428
start
Definition: start.py:1
Header
Definition: MsgHeader.h:6
FileReaderDDU::Header
Definition: FileReaderDDU.h:17
FileReaderDDU::word_0
unsigned long long word_0
Definition: FileReaderDDU.h:11
FileReaderDDU::raw_event
unsigned short raw_event[200000]
Definition: FileReaderDDU.h:9
O_LARGEFILE
#define O_LARGEFILE
Definition: FileReaderDDU.cc:12
FileReaderDDU::Type4
Definition: FileReaderDDU.h:22
FileReaderDDU::file_buffer
unsigned long long file_buffer[4000]
Definition: FileReaderDDU.h:12
FileReaderDDU::fd
int fd
Definition: FileReaderDDU.h:30
corrVsCorr.filename
filename
Definition: corrVsCorr.py:123
FileReaderDDU::open
int open(const char *filename)
Definition: FileReaderDDU.cc:36
FileReaderDDU::word_2
unsigned long long word_2
Definition: FileReaderDDU.h:11
FileReaderDDU::read
size_t read(const unsigned short *&buf)
Definition: FileReaderDDU.cc:45
FileReaderDDU::DDUoversize
Definition: FileReaderDDU.h:17
mps_setup.append
append
Definition: mps_setup.py:85
FileReaderDDU::Type1
Definition: FileReaderDDU.h:19
FileReaderDDU::Type6
Definition: FileReaderDDU.h:24
visDQMUpload.buf
buf
Definition: visDQMUpload.py:160
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
FileReaderDDU::Type5
Definition: FileReaderDDU.h:23
FileReaderDDU::acceptCriteria
unsigned int acceptCriteria
Definition: FileReaderDDU.h:28
FileReaderDDU::Type3
Definition: FileReaderDDU.h:21
FileReaderDDU::file_buffer_end
unsigned long long * file_buffer_end
Definition: FileReaderDDU.h:14
FileReaderDDU::eventStatus
unsigned int eventStatus
Definition: FileReaderDDU.h:28
FileReaderDDU::EndOfStream
Definition: FileReaderDDU.h:17
FileReaderDDU::selectCriteria
unsigned int selectCriteria
Definition: FileReaderDDU.h:28
FileReaderDDU::Unknown
Definition: FileReaderDDU.h:17
FileReaderDDU::word_1
unsigned long long word_1
Definition: FileReaderDDU.h:11
command_line.start
start
Definition: command_line.py:167
FileReaderDDU::FFFF
Definition: FileReaderDDU.h:17
event
Definition: event.py:1
FileReaderDDU::Trailer
Definition: FileReaderDDU.h:17
FileReaderDDU::end
unsigned long long * end
Definition: FileReaderDDU.h:14
FileReaderDDU::Type7
Definition: FileReaderDDU.h:25
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443