CMS 3D CMS Logo

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

#include <FileReaderDCC.h>

Public Types

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

Public Member Functions

void accept (unsigned int criteria) throw ()
 
 FileReaderDCC (void)
 
size_t next (const unsigned short *&buf)
 
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 ~FileReaderDCC (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
 
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 FileReaderDCC.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
Header 
Trailer 
DCCoversize 
FFFF 
Unknown 
EndOfStream 

Definition at line 17 of file FileReaderDCC.h.

◆ anonymous enum

anonymous enum

Constructor & Destructor Documentation

◆ FileReaderDCC()

FileReaderDCC::FileReaderDCC ( void  )

Definition at line 15 of file FileReaderDCC.cc.

References acceptCriteria, DCCoversize, 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  raw_event = new unsigned short[200000 * 40];
19  end = (file_buffer_end = file_buffer + sizeof(file_buffer) / sizeof(unsigned long long));
20  bzero(raw_event, sizeof(unsigned short) * 200000 * 40);
21  bzero(file_buffer, sizeof(file_buffer));
22  word_0 = 0;
23  word_1 = 0;
24  word_2 = 0;
25  eventStatus = 0;
28  acceptCriteria = 0x3F; // Everything
29  fd = 0;
30 }
unsigned long long word_0
Definition: FileReaderDCC.h:11
unsigned int acceptCriteria
Definition: FileReaderDCC.h:28
unsigned int rejectCriteria
Definition: FileReaderDCC.h:28
unsigned long long * file_buffer_end
Definition: FileReaderDCC.h:14
unsigned long long word_1
Definition: FileReaderDCC.h:11
unsigned long long file_buffer[4000]
Definition: FileReaderDCC.h:12
unsigned long long word_2
Definition: FileReaderDCC.h:11
unsigned long long * end
Definition: FileReaderDCC.h:14
unsigned int eventStatus
Definition: FileReaderDCC.h:28
unsigned int selectCriteria
Definition: FileReaderDCC.h:28
unsigned short * raw_event
Definition: FileReaderDCC.h:9

◆ ~FileReaderDCC()

FileReaderDCC::~FileReaderDCC ( void  )
virtual

Definition at line 32 of file FileReaderDCC.cc.

References fd.

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

Member Function Documentation

◆ accept()

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

Definition at line 37 of file FileReaderDCC.h.

References acceptCriteria.

Referenced by esMonitoring.FDJsonServer::handle_accept().

37  {
38  acceptCriteria = criteria;
39  } // return all events satisfying any of criteria
unsigned int acceptCriteria
Definition: FileReaderDCC.h:28

◆ next()

size_t FileReaderDCC::next ( const unsigned short *&  buf)

Definition at line 146 of file FileReaderDCC.cc.

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

Referenced by CSCFileReader::readFU().

146  {
147  size_t size = 0;
148  do {
149  if ((size = read(buf)) == 0)
150  break;
153  return size;
154 }
size
Write out results.
size_t read(const unsigned short *&buf)
unsigned int acceptCriteria
Definition: FileReaderDCC.h:28
unsigned int rejectCriteria
Definition: FileReaderDCC.h:28
unsigned int eventStatus
Definition: FileReaderDCC.h:28
unsigned int selectCriteria
Definition: FileReaderDCC.h:28

◆ open()

int FileReaderDCC::open ( const char *  filename)

Definition at line 37 of file FileReaderDCC.cc.

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

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

37  {
38  if (fd)
39  close(fd);
40  fd = ::open(filename, O_RDONLY | O_LARGEFILE);
41  if (fd == -1)
42  throw(std::runtime_error(std::string("Error opening ").append(filename).append(" data file.")));
43  return fd;
44 }
int open(const char *filename)
#define O_LARGEFILE

◆ read()

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

Definition at line 46 of file FileReaderDCC.cc.

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

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

◆ reject()

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

Definition at line 40 of file FileReaderDCC.h.

References rejectCriteria.

Referenced by CSCFileReader::CSCFileReader().

40  {
41  rejectCriteria = criteria;
42  } // return events not satisfying any of criteria
unsigned int rejectCriteria
Definition: FileReaderDCC.h:28

◆ select()

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

Definition at line 36 of file FileReaderDCC.h.

References selectCriteria.

Referenced by CSCFileReader::CSCFileReader().

36 { selectCriteria = criteria; } // return events satisfying all criteria
unsigned int selectCriteria
Definition: FileReaderDCC.h:28

◆ status()

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

Definition at line 44 of file FileReaderDCC.h.

References eventStatus.

44 { return eventStatus; }
unsigned int eventStatus
Definition: FileReaderDCC.h:28

Member Data Documentation

◆ acceptCriteria

unsigned int FileReaderDCC::acceptCriteria
private

Definition at line 28 of file FileReaderDCC.h.

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

◆ end

unsigned long long* FileReaderDCC::end
private

◆ eventStatus

unsigned int FileReaderDCC::eventStatus
private

Definition at line 28 of file FileReaderDCC.h.

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

◆ fd

int FileReaderDCC::fd
private

◆ file_buffer

unsigned long long FileReaderDCC::file_buffer[4000]
private

Definition at line 12 of file FileReaderDCC.h.

Referenced by FileReaderDCC(), and read().

◆ file_buffer_end

unsigned long long * FileReaderDCC::file_buffer_end
private

Definition at line 14 of file FileReaderDCC.h.

Referenced by FileReaderDCC(), and read().

◆ raw_event

unsigned short* FileReaderDCC::raw_event
private

Definition at line 9 of file FileReaderDCC.h.

Referenced by FileReaderDCC(), and read().

◆ rejectCriteria

unsigned int FileReaderDCC::rejectCriteria
private

Definition at line 28 of file FileReaderDCC.h.

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

◆ selectCriteria

unsigned int FileReaderDCC::selectCriteria
private

Definition at line 28 of file FileReaderDCC.h.

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

◆ word_0

unsigned long long FileReaderDCC::word_0
private

Definition at line 11 of file FileReaderDCC.h.

Referenced by FileReaderDCC(), and read().

◆ word_1

unsigned long long FileReaderDCC::word_1
private

Definition at line 11 of file FileReaderDCC.h.

Referenced by FileReaderDCC(), and read().

◆ word_2

unsigned long long FileReaderDCC::word_2
private

Definition at line 11 of file FileReaderDCC.h.

Referenced by FileReaderDCC(), and read().