CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EventMsgData.cc
Go to the documentation of this file.
1 // $Id: EventMsgData.cc,v 1.11 2011/03/08 18:34:11 mommsen Exp $
3 
5 
7 
8 #include <stdlib.h>
9 
10 namespace stor
11 {
12 
13  namespace detail
14  {
15 
16  EventMsgData::EventMsgData(toolbox::mem::Reference* pRef) :
17  ChainData(I2O_SM_DATA, Header::EVENT),
18  headerFieldsCached_(false)
19  {
20  addFirstFragment(pRef);
22  }
23 
24  inline size_t EventMsgData::do_i2oFrameSize() const
25  {
26  return sizeof(I2O_SM_DATA_MESSAGE_FRAME);
27  }
28 
29  unsigned long EventMsgData::do_headerSize() const
30  {
31  if ( !headerOkay() )
32  {
33  return 0;
34  }
35 
37  return headerSize_;
38  }
39 
40  unsigned char* EventMsgData::do_headerLocation() const
41  {
42  if ( !headerOkay() )
43  {
44  return 0;
45  }
46 
48  return headerLocation_;
49  }
50 
51  inline unsigned char*
52  EventMsgData::do_fragmentLocation(unsigned char* dataLoc) const
53  {
54  if ( parsable() )
55  {
57  (I2O_SM_DATA_MESSAGE_FRAME*) dataLoc;
58  return (unsigned char*) smMsg->dataPtr();
59  }
60  else
61  {
62  return dataLoc;
63  }
64  }
65 
67  {
68  if ( !headerOkay() )
69  {
70  std::stringstream msg;
71  msg << "An output module ID can not be determined from a ";
72  msg << "faulty or incomplete Event message.";
73  XCEPT_RAISE(stor::exception::IncompleteEventMessage, msg.str());
74  }
75 
77  return outputModuleId_;
78  }
79 
81  {
82  if ( !headerOkay() )
83  {
84  std::stringstream msg;
85  msg << "The number of HLT trigger bits can not be determined ";
86  msg << "from a faulty or incomplete Event message.";
87  XCEPT_RAISE(stor::exception::IncompleteEventMessage, msg.str());
88  }
89 
91  return hltTriggerCount_;
92  }
93 
94  void
95  EventMsgData::do_hltTriggerBits(std::vector<unsigned char>& bitList) const
96  {
97  if ( !headerOkay() )
98  {
99  std::stringstream msg;
100  msg << "The HLT trigger bits can not be determined from a ";
101  msg << "faulty or incomplete Event message.";
102  XCEPT_RAISE(stor::exception::IncompleteEventMessage, msg.str());
103  }
104 
106  bitList = hltTriggerBits_;
107  }
108 
109  unsigned int
111  {
112  if ( !headerOkay() )
113  {
114  std::stringstream msg;
115  msg << "The dropped events count cannot be determined from a ";
116  msg << "faulty or incomplete Event message.";
117  XCEPT_RAISE(stor::exception::IncompleteEventMessage, msg.str());
118  }
119 
121  return droppedEventsCount_;
122  }
123 
124  void
126  {
127  if ( headerOkay() )
128  {
129  const unsigned long firstFragSize = dataSize(0);
130 
131  // This should always be the case:
132  assert( firstFragSize > sizeof(EventHeader) );
133 
135  convert(count,header->droppedEventsCount_);
136  }
137  }
138 
139  void
141  {
142  if ( headerOkay() && do_runNumber() != runNumber )
143  {
144  std::ostringstream errorMsg;
145  errorMsg << "Run number " << do_runNumber()
146  << " of event " << do_eventNumber() <<
147  " received from " << hltURL() <<
148  " (FU process id " << fuProcessId() << ")" <<
149  " does not match the run number " << runNumber <<
150  " used to configure the StorageManager.";
151  XCEPT_RAISE(stor::exception::RunNumberMismatch, errorMsg.str());
152  }
153  }
154 
155  uint32_t EventMsgData::do_runNumber() const
156  {
157  if ( !headerOkay() )
158  {
159  std::stringstream msg;
160  msg << "A run number can not be determined from a ";
161  msg << "faulty or incomplete Event message.";
162  XCEPT_RAISE(stor::exception::IncompleteEventMessage, msg.str());
163  }
164 
166  return runNumber_;
167  }
168 
170  {
171  if ( !headerOkay() )
172  {
173  std::stringstream msg;
174  msg << "A luminosity section can not be determined from a ";
175  msg << "faulty or incomplete Event message.";
176  XCEPT_RAISE(stor::exception::IncompleteEventMessage, msg.str());
177  }
178 
180  return lumiSection_;
181  }
182 
184  {
185  if ( !headerOkay() )
186  {
187  std::stringstream msg;
188  msg << "An event number can not be determined from a ";
189  msg << "faulty or incomplete Event message.";
190  XCEPT_RAISE(stor::exception::IncompleteEventMessage, msg.str());
191  }
192 
194  return eventNumber_;
195  }
196 
198  {
199  if ( !headerOkay() )
200  {
201  std::stringstream msg;
202  msg << "An adler32 checksum can not be determined from a ";
203  msg << "faulty or incomplete Event message.";
204  XCEPT_RAISE(stor::exception::IncompleteEventMessage, msg.str());
205  }
206 
208  return adler32_;
209  }
210 
212  {
213  if ( parsable() )
214  {
216  (I2O_SM_DATA_MESSAGE_FRAME*) ref_->getDataLocation();
218  fragKey_.run_ = smMsg->runID;
219  fragKey_.event_ = smMsg->eventID;
220  fragKey_.secondaryId_ = smMsg->outModID;
223  rbBufferId_ = smMsg->rbBufferID;
224  hltLocalId_ = smMsg->hltLocalId;
225  hltInstance_ = smMsg->hltInstance;
226  hltTid_ = smMsg->hltTid;
227  fuProcessId_ = smMsg->fuProcID;
228  fuGuid_ = smMsg->fuGUID;
229  }
230  }
231 
233  {
234  unsigned char* firstFragLoc = dataLocation(0);
235  unsigned long firstFragSize = dataSize(0);
236  bool useFirstFrag = false;
237 
238  // if there is only one fragment, use it
239  if (fragmentCount_ == 1)
240  {
241  useFirstFrag = true;
242  }
243  // otherwise, check if the first fragment is large enough to hold
244  // the full Event message header (we require some minimal fixed
245  // size in the hope that we don't parse garbage when we overlay
246  // the EventMsgView on the buffer)
247  else if (firstFragSize > (sizeof(EventHeader) + 4096))
248  {
249  EventMsgView view(firstFragLoc);
250  if (view.headerSize() <= firstFragSize)
251  {
252  useFirstFrag = true;
253  }
254  }
255 
256  boost::shared_ptr<EventMsgView> msgView;
257  if (useFirstFrag)
258  {
259  msgView.reset(new EventMsgView(firstFragLoc));
260  }
261  else
262  {
264  msgView.reset(new EventMsgView(&headerCopy_[0]));
265  }
266 
267  headerSize_ = msgView->headerSize();
268  headerLocation_ = msgView->startAddress();
269  outputModuleId_ = msgView->outModId();
270  hltTriggerCount_ = msgView->hltCount();
271  if (hltTriggerCount_ > 0)
272  {
273  hltTriggerBits_.resize(1 + (hltTriggerCount_-1)/4);
274  }
275  msgView->hltTriggerBits(&hltTriggerBits_[0]);
276 
277  runNumber_ = msgView->run();
278  lumiSection_ = msgView->lumi();
279  eventNumber_ = msgView->event();
280  adler32_ = msgView->adler32_chksum();
281  droppedEventsCount_ = msgView->droppedEventsCount();
282 
283  headerFieldsCached_ = true;
284 
285  #ifdef STOR_DEBUG_WRONG_ADLER
286  double r = rand()/static_cast<double>(RAND_MAX);
287  if (r < 0.01)
288  {
289  std::cout << "Simulating corrupt Adler calculation" << std::endl;
290  headerSize_ += 3;
291  }
292  else if (r < 0.02)
293  {
294  std::cout << "Simulating corrupt Adler entry" << std::endl;
295  adler32_ += r*10000;
296  }
297  #endif // STOR_DEBUG_WRONG_ADLER
298  }
299 
300  } // namespace detail
301 
302 } // namespace stor
303 
304 
uint32 originatorPid_
Definition: FragKey.h:39
unsigned char * dataLocation(int fragmentIndex) const
Definition: ChainData.cc:449
uint32_t do_runNumber() const
unsigned char * do_headerLocation() const
Definition: EventMsgData.cc:40
unsigned int rbBufferId_
Definition: ChainData.h:164
toolbox::mem::Reference * ref_
Definition: ChainData.h:154
unsigned int fuProcessId() const
Definition: ChainData.h:82
unsigned int hltTid_
Definition: ChainData.h:167
unsigned char * do_fragmentLocation(unsigned char *dataLoc) const
Definition: EventMsgData.cc:52
void do_assertRunNumber(uint32_t runNumber)
uint32 event_
Definition: FragKey.h:34
std::string hltURL() const
Definition: ChainData.cc:542
void addFirstFragment(toolbox::mem::Reference *)
Definition: ChainData.cc:115
unsigned int droppedEventsCount_
Definition: ChainData.h:320
void convert(uint32 i, char_uint32 v)
Definition: MsgTools.h:46
bool parsable() const
Definition: ChainData.cc:103
void cacheHeaderFields() const
uint32 originatorGuid_
Definition: FragKey.h:40
size_t do_i2oFrameSize() const
Definition: EventMsgData.cc:24
unsigned int do_droppedEventsCount() const
uint32_t do_adler32Checksum() const
EventMsgData(toolbox::mem::Reference *pRef)
Definition: EventMsgData.cc:16
unsigned int copyFragmentsIntoBuffer(std::vector< unsigned char > &buff) const
Definition: ChainData.cc:489
uint32_t do_hltTriggerCount() const
Definition: EventMsgData.cc:80
uint32 headerSize() const
Definition: EventMessage.h:81
uint32_t do_eventNumber() const
unsigned int hltLocalId_
Definition: ChainData.h:165
unsigned char * headerLocation_
Definition: ChainData.h:312
uint8 code_
Definition: FragKey.h:32
void do_setDroppedEventsCount(unsigned int)
uint32 run_
Definition: FragKey.h:33
char_uint32 droppedEventsCount_
Definition: EventMessage.h:66
unsigned int fuProcessId_
Definition: ChainData.h:168
unsigned int fragmentCount_
Definition: ChainData.h:162
unsigned long dataSize(int fragmentIndex) const
Definition: ChainData.cc:426
unsigned int fuGuid_
Definition: ChainData.h:169
uint32_t do_lumiSection() const
uint32 secondaryId_
Definition: FragKey.h:38
char * dataPtr() const
Definition: i2oEvfMsgs.h:108
std::vector< unsigned char > headerCopy_
Definition: ChainData.h:310
uint32_t do_outputModuleId() const
Definition: EventMsgData.cc:66
_I2O_SM_DATA_MESSAGE_FRAME I2O_SM_DATA_MESSAGE_FRAME
unsigned int messageCode_
Definition: ChainData.h:159
Signal rand(Signal arg)
Definition: vlib.cc:442
tuple cout
Definition: gather_cfg.py:121
bool headerOkay() const
Definition: ChainData.cc:110
unsigned long headerSize_
Definition: ChainData.h:311
void do_hltTriggerBits(std::vector< unsigned char > &bitList) const
Definition: EventMsgData.cc:95
#define I2O_SM_DATA
Definition: i2oEvfMsgs.h:22
std::vector< unsigned char > hltTriggerBits_
Definition: ChainData.h:315
unsigned int hltInstance_
Definition: ChainData.h:166
unsigned long do_headerSize() const
Definition: EventMsgData.cc:29