CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
I2OChain.cc
Go to the documentation of this file.
1 // $Id: I2OChain.cc,v 1.27 2012/04/20 10:48:02 mommsen Exp $
3 
4 #include <algorithm>
5 
10 
12 
14 
16 
17 #include "interface/evb/i2oEVBMsgs.h"
18 #include "interface/shared/i2oXFunctionCodes.h"
19 #include "interface/shared/version.h"
20 
21 
22 namespace stor
23 {
24 
25  // A default-constructed I2OChain has a null (shared) pointer.
27  data_()
28  {}
29 
30  I2OChain::I2OChain(toolbox::mem::Reference* pRef)
31  {
32  if (pRef)
33  {
34  I2O_PRIVATE_MESSAGE_FRAME *pvtMsg =
35  (I2O_PRIVATE_MESSAGE_FRAME*) pRef->getDataLocation();
36  if (!pvtMsg)
37  {
38  data_.reset(new detail::ChainData());
39  data_->addFirstFragment(pRef);
40  return;
41  }
42 
43  unsigned short i2oMessageCode = pvtMsg->XFunctionCode;
44  switch (i2oMessageCode)
45  {
46 
47  case I2O_SM_PREAMBLE:
48  {
49  data_.reset(new detail::InitMsgData(pRef));
50  break;
51  }
52 
53  case I2O_SM_DATA:
54  {
55  data_.reset(new detail::EventMsgData(pRef));
56  break;
57  }
58 
59  case I2O_SM_DQM:
60  {
61  data_.reset(new detail::DQMEventMsgData(pRef));
62  break;
63  }
64 
65  case I2O_EVM_LUMISECTION:
66  {
67  data_.reset(new detail::EndLumiSectMsgData(pRef));
68  break;
69  }
70 
71  case I2O_SM_ERROR:
72  {
73  data_.reset(new detail::ErrorEventMsgData(pRef));
74  break;
75  }
76 
77  default:
78  {
79  data_.reset(new detail::ChainData());
80  data_->addFirstFragment(pRef);
81  data_->markCorrupt();
82  break;
83  }
84 
85  }
86  }
87  }
88 
89  I2OChain::I2OChain(I2OChain const& other) :
90  data_(other.data_)
91  { }
92 
94  { }
95 
97  {
98  // This is the standard copy/swap algorithm, to obtain the strong
99  // exception safety guarantee.
100  I2OChain temp(rhs);
101  swap(temp);
102  return *this;
103  }
104 
106  {
107  data_.swap(other.data_);
108  }
109 
110  bool I2OChain::empty() const
111  {
112  // We're empty if we have no ChainData, or if the ChainData object
113  // we have is empty.
114  return !data_ || data_->empty();
115  }
116 
117 
118  bool I2OChain::complete() const
119  {
120  if (!data_) return false;
121  return data_->complete();
122  }
123 
124 
125  bool I2OChain::faulty() const
126  {
127  if (!data_) return false;
128  return data_->faulty();
129  }
130 
131 
132  unsigned int I2OChain::faultyBits() const
133  {
134  if (!data_) return 0;
135  return data_->faultyBits();
136  }
137 
138 
140  {
141  // fragments can not be added to empty, complete, or faulty chains.
142  if (empty())
143  {
144  XCEPT_RAISE(stor::exception::I2OChain,
145  "A fragment may not be added to an empty chain.");
146  }
147  if (complete())
148  {
149  XCEPT_RAISE(stor::exception::I2OChain,
150  "A fragment may not be added to a complete chain.");
151  }
152 
153  // empty, complete, or faulty new parts can not be added to chains
154  if (newpart.empty())
155  {
156  XCEPT_RAISE(stor::exception::I2OChain,
157  "An empty chain may not be added to an existing chain.");
158  }
159  if (newpart.complete())
160  {
161  XCEPT_RAISE(stor::exception::I2OChain,
162  "A complete chain may not be added to an existing chain.");
163  }
164 
165  // require the new part and this chain to have the same fragment key
166  FragKey thisKey = fragmentKey();
167  FragKey thatKey = newpart.fragmentKey();
168  // should change this to != once we implement that operator in FragKey
169  if (thisKey < thatKey || thatKey < thisKey)
170  {
171  std::stringstream msg;
172  msg << "A fragment key mismatch was detected when trying to add "
173  << "a chain link to an existing chain. "
174  << "Existing key values = ("
175  << ((int)thisKey.code_) << "," << thisKey.run_ << ","
176  << thisKey.event_ << "," << thisKey.secondaryId_ << ","
177  << thisKey.originatorPid_ << "," << thisKey.originatorGuid_
178  << "), new key values = ("
179  << ((int)thatKey.code_) << "," << thatKey.run_ << ","
180  << thatKey.event_ << "," << thatKey.secondaryId_ << ","
181  << thatKey.originatorPid_ << "," << thatKey.originatorGuid_
182  << ").";
183  XCEPT_RAISE(stor::exception::I2OChain, msg.str());
184  }
185 
186  // add the fragment to the current chain
187  data_->addToChain(*(newpart.data_));
188  newpart.release();
189  }
190 
191  //void I2OChain::markComplete()
192  //{
193  // // TODO:: Should we throw an exception if data_ is null? If so, what
194  // // type? Right now, we do nothing if data_ is null.
195  // if (data_) data_->markComplete();
196  //}
197 
199  {
200  // TODO:: Should we throw an exception if data_ is null? If so, what
201  // type? Right now, we do nothing if data_ is null.
202  if (data_) data_->markFaulty();
203  }
204 
205  unsigned long* I2OChain::getBufferData() const
206  {
207  return data_ ? data_->getBufferData() : 0UL;
208  }
209 
211  {
212  // A default-constructed chain controls no resources; we can
213  // relinquish our control over any controlled Reference by
214  // becoming like a default-constructed chain.
215  I2OChain().swap(*this);
216  }
217 
218  unsigned int I2OChain::messageCode() const
219  {
220  if (!data_) return Header::INVALID;
221  return data_->messageCode();
222  }
223 
224  unsigned short I2OChain::i2oMessageCode() const
225  {
226  if (!data_) return 0xffff;
227  return data_->i2oMessageCode();
228  }
229 
230  unsigned int I2OChain::rbBufferId() const
231  {
232  if (!data_) return 0;
233  return data_->rbBufferId();
234  }
235 
236  unsigned int I2OChain::hltLocalId() const
237  {
238  if (!data_) return 0;
239  return data_->hltLocalId();
240  }
241 
242  unsigned int I2OChain::hltInstance() const
243  {
244  if (!data_) return 0;
245  return data_->hltInstance();
246  }
247 
248  unsigned int I2OChain::hltTid() const
249  {
250  if (!data_) return 0;
251  return data_->hltTid();
252  }
253 
255  {
256  if (!data_) return "";
257  return data_->hltURL();
258  }
259 
261  {
262  if (!data_) return "";
263  return data_->hltClassName();
264  }
265 
266  unsigned int I2OChain::fuProcessId() const
267  {
268  if (!data_) return 0;
269  return data_->fuProcessId();
270  }
271 
272  unsigned int I2OChain::fuGuid() const
273  {
274  if (!data_) return 0;
275  return data_->fuGuid();
276  }
277 
279  {
280  if (!data_) return FragKey(Header::INVALID,0,0,0,0,0);
281  return data_->fragmentKey();
282  }
283 
284  unsigned int I2OChain::fragmentCount() const
285  {
286  if (!data_) return 0;
287  return data_->fragmentCount();
288  }
289 
291  {
292  if (!data_) return boost::posix_time::not_a_date_time;
293  return data_->creationTime();
294  }
295 
297  {
298  if (!data_) return boost::posix_time::not_a_date_time;
299  return data_->lastFragmentTime();
300  }
301 
303  {
304  if (!data_) return boost::posix_time::not_a_date_time;
305  return data_->staleWindowStartTime();
306  }
307 
309  {
310  if (!data_) return;
311  data_->addToStaleWindowStartTime(duration);
312  }
313 
315  {
316  if (!data_) return;
317  data_->resetStaleWindowStartTime();
318  }
319 
321  {
322  if (!data_)
323  {
324  std::stringstream msg;
325  msg << "An empty chain can not be tagged for a specific ";
326  msg << "event stream.";
327  XCEPT_RAISE(stor::exception::I2OChain, msg.str());
328  }
329  data_->tagForStream(streamId);
330  }
331 
333  {
334  if (!data_)
335  {
336  std::stringstream msg;
337  msg << "An empty chain can not be tagged for a specific ";
338  msg << "event consumer.";
339  XCEPT_RAISE(stor::exception::I2OChain, msg.str());
340  }
341  data_->tagForEventConsumer(queueId);
342  }
343 
345  {
346  if (!data_)
347  {
348  std::stringstream msg;
349  msg << "An empty chain can not be tagged for a specific ";
350  msg << "DQM event consumer.";
351  XCEPT_RAISE(stor::exception::I2OChain, msg.str());
352  }
353  data_->tagForDQMEventConsumer(queueId);
354  }
355 
357  {
358  if (!data_) return false;
359  return data_->isTaggedForAnyStream();
360  }
361 
363  {
364  if (!data_) return false;
365  return data_->isTaggedForAnyEventConsumer();
366  }
367 
369  {
370  if (!data_) return false;
371  return data_->isTaggedForAnyDQMEventConsumer();
372  }
373 
374  std::vector<StreamID> I2OChain::getStreamTags() const
375  {
376  if (!data_)
377  {
378  std::vector<StreamID> tmpList;
379  return tmpList;
380  }
381  return data_->getStreamTags();
382  }
383 
385  {
386  if (!data_)
387  {
388  QueueIDs tmpList;
389  return tmpList;
390  }
391  return data_->getEventConsumerTags();
392  }
393 
395  {
396  if (!data_)
397  {
398  QueueIDs tmpList;
399  return tmpList;
400  }
401  return data_->getDQMEventConsumerTags();
402  }
403 
404  unsigned int I2OChain::droppedEventsCount() const
405  {
406  if (!data_)
407  {
408  std::stringstream msg;
409  msg << "A dropped event count cannot be retrieved from an empty chain";
410  XCEPT_RAISE(stor::exception::I2OChain, msg.str());
411  }
412  return data_->droppedEventsCount();
413  }
414 
416  {
417  if (!data_)
418  {
419  std::stringstream msg;
420  msg << "A dropped event count cannot be added to an empty chain";
421  XCEPT_RAISE(stor::exception::I2OChain, msg.str());
422  }
423  data_->setDroppedEventsCount(count);
424  }
425 
426  size_t I2OChain::memoryUsed() const
427  {
428  if (!data_) return 0;
429  return data_->memoryUsed();
430  }
431 
432  unsigned long I2OChain::totalDataSize() const
433  {
434  if (!data_) return 0UL;
435  return data_->totalDataSize();
436  }
437 
438  unsigned long I2OChain::dataSize(int fragmentIndex) const
439  {
440  if (!data_) return 0UL;
441  return data_->dataSize(fragmentIndex);
442  }
443 
444  unsigned char* I2OChain::dataLocation(int fragmentIndex) const
445  {
446  if (!data_) return 0UL;
447  return data_->dataLocation(fragmentIndex);
448  }
449 
450  unsigned int I2OChain::getFragmentID(int fragmentIndex) const
451  {
452  if (!data_) return 0;
453  return data_->getFragmentID(fragmentIndex);
454  }
455 
456  unsigned long I2OChain::headerSize() const
457  {
458  if (!data_) return 0UL;
459  return data_->headerSize();
460  }
461 
462  unsigned char* I2OChain::headerLocation() const
463  {
464  if (!data_) return 0UL;
465  return data_->headerLocation();
466  }
467 
468  unsigned int I2OChain::
469  copyFragmentsIntoBuffer(std::vector<unsigned char>& targetBuffer) const
470  {
471  if (!data_) return 0;
472  return data_->copyFragmentsIntoBuffer(targetBuffer);
473  }
474 
476  {
477  if( !data_ )
478  {
479  XCEPT_RAISE( stor::exception::I2OChain,
480  "The top folder name can not be determined from an empty I2OChain." );
481  }
482  return data_->topFolderName();
483  }
484 
486  {
487  if( !data_ )
488  {
489  XCEPT_RAISE( stor::exception::I2OChain,
490  "The DQM key can not be determined from an empty I2OChain." );
491  }
492  return data_->dqmKey();
493  }
494 
496  {
497  if (!data_)
498  {
499  XCEPT_RAISE(stor::exception::I2OChain,
500  "The output module label can not be determined from an empty I2OChain.");
501  }
502  return data_->outputModuleLabel();
503  }
504 
505  uint32_t I2OChain::outputModuleId() const
506  {
507  if (!data_)
508  {
509  XCEPT_RAISE(stor::exception::I2OChain,
510  "The output module ID can not be determined from an empty I2OChain.");
511  }
512  return data_->outputModuleId();
513  }
514 
515  uint32_t I2OChain::nExpectedEPs() const
516  {
517  if (!data_)
518  {
519  XCEPT_RAISE(stor::exception::I2OChain,
520  "The slave EP count can not be determined from an empty I2OChain.");
521  }
522  return data_->nExpectedEPs();
523  }
524 
525  void I2OChain::hltTriggerNames(Strings& nameList) const
526  {
527  if (!data_)
528  {
529  XCEPT_RAISE(stor::exception::I2OChain,
530  "HLT trigger names can not be determined from an empty I2OChain.");
531  }
532  data_->hltTriggerNames(nameList);
533  }
534 
536  {
537  if (!data_)
538  {
539  XCEPT_RAISE(stor::exception::I2OChain,
540  "HLT trigger selections can not be determined from an empty I2OChain.");
541  }
542  data_->hltTriggerSelections(nameList);
543  }
544 
545  void I2OChain::l1TriggerNames(Strings& nameList) const
546  {
547  if (!data_)
548  {
549  XCEPT_RAISE(stor::exception::I2OChain,
550  "L1 trigger names can not be determined from an empty I2OChain.");
551  }
552  data_->l1TriggerNames(nameList);
553  }
554 
555  uint32_t I2OChain::hltTriggerCount() const
556  {
557  if (!data_)
558  {
559  XCEPT_RAISE(stor::exception::I2OChain,
560  "The number of HLT trigger bits can not be determined from an empty I2OChain.");
561  }
562  return data_->hltTriggerCount();
563  }
564 
565  void I2OChain::hltTriggerBits(std::vector<unsigned char>& bitList) const
566  {
567  if (!data_)
568  {
569  XCEPT_RAISE(stor::exception::I2OChain,
570  "HLT trigger bits can not be determined from an empty I2OChain.");
571  }
572  data_->hltTriggerBits(bitList);
573  }
574 
576  {
577  if (!data_)
578  {
579  XCEPT_RAISE(stor::exception::I2OChain,
580  "The run number can not be checked for an empty I2OChain.");
581  }
582  return data_->assertRunNumber(runNumber);
583  }
584 
585  uint32_t I2OChain::runNumber() const
586  {
587  if (!data_)
588  {
589  XCEPT_RAISE(stor::exception::I2OChain,
590  "The run number can not be determined from an empty I2OChain.");
591  }
592  return data_->runNumber();
593  }
594 
595  uint32_t I2OChain::lumiSection() const
596  {
597  if (!data_)
598  {
599  XCEPT_RAISE(stor::exception::I2OChain,
600  "The luminosity section can not be determined from an empty I2OChain.");
601  }
602  return data_->lumiSection();
603  }
604 
605  uint32_t I2OChain::eventNumber() const
606  {
607  if (!data_)
608  {
609  XCEPT_RAISE(stor::exception::I2OChain,
610  "The event number can not be determined from an empty I2OChain.");
611  }
612  return data_->eventNumber();
613  }
614 
615  uint32_t I2OChain::adler32Checksum() const
616  {
617  if (!data_)
618  {
619  XCEPT_RAISE(stor::exception::I2OChain,
620  "The adler32 checksum can not be determined from an empty I2OChain.");
621  }
622  return data_->adler32Checksum();
623  }
624 
626  {
627  if (!data_) return false;
628  return data_->isEndOfLumiSectionMessage();
629  }
630 
631 } // namespace stor
632 
uint32 originatorPid_
Definition: FragKey.h:39
unsigned int fragmentCount() const
Definition: I2OChain.cc:284
DQMKey dqmKey() const
Definition: I2OChain.cc:485
uint32_t runNumber() const
Definition: I2OChain.cc:585
#define I2O_SM_ERROR
Definition: i2oEvfMsgs.h:23
QueueIDs getEventConsumerTags() const
Definition: I2OChain.cc:384
#define I2O_SM_DQM
Definition: i2oEvfMsgs.h:25
std::string hltClassName() const
Definition: I2OChain.cc:260
unsigned long * getBufferData() const
Definition: I2OChain.cc:205
#define I2O_SM_PREAMBLE
Definition: i2oEvfMsgs.h:21
std::vector< QueueID > QueueIDs
Definition: QueueID.h:80
unsigned short i2oMessageCode() const
Definition: I2OChain.cc:224
bool complete() const
Definition: I2OChain.cc:118
std::vector< std::string > Strings
Definition: MsgTools.h:18
bool isEndOfLumiSectionMessage() const
Definition: I2OChain.cc:625
void tagForEventConsumer(QueueID)
Definition: I2OChain.cc:332
unsigned int fuProcessId() const
Definition: I2OChain.cc:266
uint32 event_
Definition: FragKey.h:34
void addToChain(I2OChain &newpart)
Definition: I2OChain.cc:139
void setDroppedEventsCount(unsigned int)
Definition: I2OChain.cc:415
unsigned long headerSize() const
Definition: I2OChain.cc:456
utils::TimePoint_t lastFragmentTime() const
Definition: I2OChain.cc:296
void addToStaleWindowStartTime(const utils::Duration_t)
Definition: I2OChain.cc:308
unsigned int getFragmentID(int fragmentIndex) const
Definition: I2OChain.cc:450
uint32 originatorGuid_
Definition: FragKey.h:40
void hltTriggerBits(std::vector< unsigned char > &bitList) const
Definition: I2OChain.cc:565
bool empty() const
Definition: I2OChain.cc:110
unsigned int faultyBits() const
Definition: I2OChain.cc:132
void assertRunNumber(uint32_t runNumber)
Definition: I2OChain.cc:575
void swap(I2OChain &other)
Definition: I2OChain.cc:105
unsigned int messageCode() const
Definition: I2OChain.cc:218
void hltTriggerNames(Strings &nameList) const
Definition: I2OChain.cc:525
uint32_t lumiSection() const
Definition: I2OChain.cc:595
unsigned int hltInstance() const
Definition: I2OChain.cc:242
QueueIDs getDQMEventConsumerTags() const
Definition: I2OChain.cc:394
unsigned int hltLocalId() const
Definition: I2OChain.cc:236
uint32_t nExpectedEPs() const
Definition: I2OChain.cc:515
boost::posix_time::time_duration Duration_t
Definition: Utils.h:41
I2OChain & operator=(I2OChain const &rhs)
Definition: I2OChain.cc:96
std::vector< StreamID > getStreamTags() const
Definition: I2OChain.cc:374
unsigned int droppedEventsCount() const
Definition: I2OChain.cc:404
boost::shared_ptr< detail::ChainData > data_
Definition: I2OChain.h:574
unsigned int fuGuid() const
Definition: I2OChain.cc:272
std::string outputModuleLabel() const
Definition: I2OChain.cc:495
bool isTaggedForAnyStream() const
Definition: I2OChain.cc:356
boost::posix_time::ptime TimePoint_t
Definition: Utils.h:35
std::string topFolderName() const
Definition: I2OChain.cc:475
unsigned char * headerLocation() const
Definition: I2OChain.cc:462
uint8 code_
Definition: FragKey.h:32
uint32 run_
Definition: FragKey.h:33
void release()
Definition: I2OChain.cc:210
unsigned int copyFragmentsIntoBuffer(std::vector< unsigned char > &buff) const
Definition: I2OChain.cc:469
size_t StreamID
Definition: StreamID.h:19
void hltTriggerSelections(Strings &nameList) const
Definition: I2OChain.cc:535
unsigned int hltTid() const
Definition: I2OChain.cc:248
uint32 secondaryId_
Definition: FragKey.h:38
size_t memoryUsed() const
Definition: I2OChain.cc:426
unsigned long totalDataSize() const
Definition: I2OChain.cc:432
unsigned int rbBufferId() const
Definition: I2OChain.cc:230
utils::TimePoint_t staleWindowStartTime() const
Definition: I2OChain.cc:302
FragKey fragmentKey() const
Definition: I2OChain.cc:278
void resetStaleWindowStartTime()
Definition: I2OChain.cc:314
void tagForStream(StreamID)
Definition: I2OChain.cc:320
uint32_t hltTriggerCount() const
Definition: I2OChain.cc:555
unsigned long dataSize(int fragmentIndex) const
Definition: I2OChain.cc:438
void l1TriggerNames(Strings &nameList) const
Definition: I2OChain.cc:545
void tagForDQMEventConsumer(QueueID)
Definition: I2OChain.cc:344
bool isTaggedForAnyDQMEventConsumer() const
Definition: I2OChain.cc:368
uint32_t eventNumber() const
Definition: I2OChain.cc:605
uint32_t adler32Checksum() const
Definition: I2OChain.cc:615
bool faulty() const
Definition: I2OChain.cc:125
#define I2O_SM_DATA
Definition: i2oEvfMsgs.h:22
void markFaulty()
Definition: I2OChain.cc:198
std::string hltURL() const
Definition: I2OChain.cc:254
utils::TimePoint_t creationTime() const
Definition: I2OChain.cc:290
bool isTaggedForAnyEventConsumer() const
Definition: I2OChain.cc:362
uint32_t outputModuleId() const
Definition: I2OChain.cc:505
unsigned char * dataLocation(int fragmentIndex) const
Definition: I2OChain.cc:444