CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Attributes
CSCTFEvent Class Reference

#include <CSCTFEvent.h>

Public Types

enum  {
  MISSING_HEADER =0x2, MISSING_TRAILER =0x4, OUT_OF_BUFFER =0x8, WORD_COUNT =0x10,
  CONFIGURATION =0x20, NONSENSE =0x40
}
 

Public Member Functions

 CSCTFEvent (void)
 
std::vector< CSCSPEventSPs (void) const throw ()
 
std::vector< const CSCSPEvent * > SPs_fast (void) const throw ()
 
unsigned int unpack (const unsigned short *buf, unsigned int length)
 

Private Attributes

int nRecords
 
CSCSPEvent sp [12]
 

Detailed Description

Definition at line 7 of file CSCTFEvent.h.

Member Enumeration Documentation

anonymous enum
Enumerator
MISSING_HEADER 
MISSING_TRAILER 
OUT_OF_BUFFER 
WORD_COUNT 
CONFIGURATION 
NONSENSE 

Definition at line 14 of file CSCTFEvent.h.

Constructor & Destructor Documentation

CSCTFEvent::CSCTFEvent ( void  )
inline

Definition at line 34 of file CSCTFEvent.h.

34 {}

Member Function Documentation

std::vector<CSCSPEvent> CSCTFEvent::SPs ( void  ) const
throw (
)
inline

Definition at line 16 of file CSCTFEvent.h.

References nRecords, and mps_fire::result.

16  {
17  std::vector<CSCSPEvent> result;
18  result.reserve(nRecords);
19  for(int spNum=0; spNum<nRecords; spNum++) result.push_back(sp[spNum]);
20  return result;
21  }
CSCSPEvent sp[12]
Definition: CSCTFEvent.h:9
int nRecords
Definition: CSCTFEvent.h:10
std::vector<const CSCSPEvent*> CSCTFEvent::SPs_fast ( void  ) const
throw (
)
inline

Definition at line 24 of file CSCTFEvent.h.

References nRecords, and unpack().

Referenced by CSCTFUnpacker::produce().

24  {
25  std::vector<const CSCSPEvent*> retval;
26  retval.clear();
27  retval.reserve(nRecords);
28  for(int spNum=0; spNum<nRecords; spNum++) retval.push_back(sp+spNum);
29  return retval;
30  }
CSCSPEvent sp[12]
Definition: CSCTFEvent.h:9
int nRecords
Definition: CSCTFEvent.h:10
unsigned int CSCTFEvent::unpack ( const unsigned short *  buf,
unsigned int  length 
)

Definition at line 6 of file CSCTFEvent.cc.

References CSCSPHeader::active(), CONFIGURATION, CSCSPHeader::empty(), CSCSPHeader::format_version(), RecoTauValidation_cfi::header, MISSING_HEADER, MISSING_TRAILER, NONSENSE, nRecords, CSCSPHeader::nTBINs(), OUT_OF_BUFFER, edm::shift, sp, AlCaHLTBitMon_QueryRunRegistry::string, CSCSPHeader::suppression(), CSCSPHeader::unpack(), and WORD_COUNT.

Referenced by CSCTFUnpacker::produce(), and SPs_fast().

6  {
7  // Clean up
8  nRecords = 0;
9  bzero(sp,sizeof(sp));
10 
11  // Make sure that we are running right platform (can't imagine opposite)
12  if( sizeof(unsigned long long)!=8 || sizeof(unsigned short)!=2 )
13  throw std::runtime_error(std::string("Wrong platform: sizeof(unsigned long long)!=8 || sizeof(unsigned short)!=2"));
14 
15  // Type of coruptions
16  unsigned long coruptions=0;
17 
18  // Combine 64-bit ddu word for simlicity and efficiency
19  const unsigned long long *dduWord = reinterpret_cast<const unsigned long long*>(buf);
20  unsigned long long word_1=0, word_2=0;
21  // 'length' counts ddu words now
22  length /= sizeof(unsigned long long)/sizeof(unsigned short);
23  // Set of markers
24  bool spHeader=false, spTrailer=false;
25  unsigned long spWordCount=0, spWordCountExpected=0;
26 
27  // Run through the buffer and check its structure
28  unsigned int index=0;
29  while( index<length ){
30  word_1 = word_2; // delay by 1 DDU word
31  word_2 = dduWord[index]; // current DDU word
32 
33  if( spHeader && !spTrailer ) spWordCount++;
34 
35  if( (word_1&0xF000F000F000F000LL)==0x9000900090009000LL &&
36  (word_2&0xF000F000F000F000LL)==0xA000A000A000A000LL ){
37  if( spHeader ){
38  coruptions |= MISSING_TRAILER;
39  break;
40  }
41  spHeader=true;
42  spTrailer=false;
43  // number of 64-bit words between header and trailer
44  spWordCount=0;
45  spWordCountExpected=0;
46  // need header to calculate expected word count
48  const unsigned short *spWord = reinterpret_cast<const unsigned short*>(&dduWord[index-1]);
49  // we are here because we have a header => we are safe from crash instantiating one
50  header.unpack(spWord);
51 
52  // Counter block exists only in format version 4.3 and higher
53  if( header.format_version() && !header.empty() ){
54  if( length > index+1 ){ spWord += 4; } else { coruptions |= OUT_OF_BUFFER; break; }
55  }
56 
57  // Calculate expected record length (internal variable 'shift' counts 16-bit words)
58  for(unsigned short tbin=0,shift=0; tbin<header.nTBINs() && !header.empty(); tbin++){
59  // check if didn't pass end of event, keep in mind that 'length', 'index', and 'spWordCountExpected' counts 64-bit words
60  if( length <= index+spWordCountExpected+2 ){
61  coruptions |= OUT_OF_BUFFER;
62  break;
63  } else {
64  // In the format version >=5.3 with zero_supression
65  if( header.format_version()>=3 && header.suppression() ){
66  // we seek the loop index untill it matches the current non-empty tbin
67  if( ((spWord[shift+7]>>8) & 0x7) != tbin+1 ) continue;
68  // otherwise there may be no more non-empty tbins and we ran into the trailer
69  if( (spWord[shift+0]&0xF000)==0xF000 && (spWord[shift+1]&0xF000)==0xF000 && (spWord[shift+2]&0xF000)==0xF000 && (spWord[shift+3]&0xF000)==0xF000 &&
70  (spWord[shift+4]&0xF000)==0xE000 && (spWord[shift+5]&0xF000)==0xE000 && (spWord[shift+6]&0xF000)==0xE000 && (spWord[shift+7]&0xF000)==0xE000 ) break;
71  }
72 
73  // Data Block Header always exists if we got so far
74  spWordCountExpected += 2;
75  // 15 ME data blocks
76  for(unsigned int me_block=0; me_block<15; me_block++)
77  if( header.active()&(1<<(me_block/3)) && (!header.suppression() || spWord[shift+0]&(1<<me_block)) )
78  spWordCountExpected += 1;
79  // 2 MB data blocks
80  for(unsigned int mb_block=0; mb_block<2; mb_block++)
81  if( header.active()&0x20 && (!header.suppression() || spWord[shift+1]&(1<<(mb_block+12))) )
82  spWordCountExpected += 1;
83  // 3 SP data blocks
84  for(unsigned int sp_block=0; sp_block<3; sp_block++)
85  if( header.active()&0x40 && (!header.suppression() || spWord[shift+1]&(0xF<<(sp_block*4))) )
86  spWordCountExpected += 1;
87 
88  shift = spWordCountExpected*4; // multiply by 4 because 'shift' is a 16-bit array index and 'spWordCountExpected' conuts 64-bit words
89  }
90  }
91 
92  // Counter block exists only in format version 4.3 and higher
93  if( header.format_version() && !header.empty() ) spWordCountExpected += 1;
94 
95  if( coruptions&OUT_OF_BUFFER ) break;
96  }
97 
98  //if( !spHeader && spTrailer ) coruptions |= NONSENSE; ///???
99 
100  if( (word_1&0xF000F000F000F000LL)==0xF000F000F000F000LL &&
101  (word_2&0xF000F000F000F000LL)==0xE000E000E000E000LL ){
102  if( spTrailer ){
103  coruptions |= MISSING_HEADER;
104  break;
105  }
106  spHeader=false;
107  spTrailer=true;
108 
109  if( spWordCount!=spWordCountExpected+2 ){
110  coruptions |= WORD_COUNT;
111  break;
112  }
113  // main unpacking
114  const unsigned short *spWord = reinterpret_cast<const unsigned short*>(&dduWord[index-spWordCount-1]);
115  if( nRecords<12 ) {
116  if( sp[nRecords++].unpack(spWord) ) coruptions |= NONSENSE;
117  } else {
118  coruptions |= CONFIGURATION;
119  break;
120  }
121  }
122 
123  index++;
124  }
125 
126  return coruptions;
127 }
unsigned int unpack(const unsigned short *buf, unsigned int length)
Definition: CSCTFEvent.cc:6
bool suppression(void) const
Definition: CSCSPHeader.h:94
int format_version(void) const
Definition: CSCSPHeader.h:101
bool unpack(const unsigned short *&buf)
Definition: CSCSPHeader.h:104
unsigned int nTBINs(void) const
Definition: CSCSPHeader.h:92
CSCSPEvent sp[12]
Definition: CSCTFEvent.h:9
int nRecords
Definition: CSCTFEvent.h:10
static unsigned int const shift
bool empty(void) const
Definition: CSCSPHeader.h:99
unsigned int active(void) const
Definition: CSCSPHeader.h:97

Member Data Documentation

int CSCTFEvent::nRecords
private

Definition at line 10 of file CSCTFEvent.h.

Referenced by SPs(), SPs_fast(), and unpack().

CSCSPEvent CSCTFEvent::sp[12]
private

Definition at line 9 of file CSCTFEvent.h.

Referenced by unpack().