CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
InitMsgData.cc
Go to the documentation of this file.
1 // $Id: InitMsgData.cc,v 1.9 2012/04/20 10:48:02 mommsen Exp $
3 
5 
7 
8 namespace stor
9 {
10 
11  namespace detail
12  {
13 
14  InitMsgData::InitMsgData(toolbox::mem::Reference* pRef) :
16  headerFieldsCached_(false)
17  {
18  addFirstFragment(pRef);
20  }
21 
22  inline size_t InitMsgData::do_i2oFrameSize() const
23  {
24  return sizeof(I2O_SM_PREAMBLE_MESSAGE_FRAME);
25  }
26 
27  unsigned long InitMsgData::do_headerSize() const
28  {
29  if ( !headerOkay() )
30  {
31  return 0;
32  }
33 
35  return headerSize_;
36  }
37 
38  unsigned char* InitMsgData::do_headerLocation() const
39  {
40  if ( !headerOkay() )
41  {
42  return 0;
43  }
44 
46  return headerLocation_;
47  }
48 
49  inline unsigned char*
50  InitMsgData::do_fragmentLocation(unsigned char* dataLoc) const
51  {
52  if ( parsable() )
53  {
56  return (unsigned char*) smMsg->dataPtr();
57  }
58  else
59  {
60  return dataLoc;
61  }
62  }
63 
65  {
66  if ( !headerOkay() )
67  {
68  std::stringstream msg;
69  msg << "An adler32 checksum can not be determined from a ";
70  msg << "faulty or incomplete INIT message.";
71  XCEPT_RAISE(stor::exception::IncompleteInitMessage, msg.str());
72  }
73 
75  return adler32_;
76  }
77 
79  {
80  if ( !headerOkay() )
81  {
82  std::stringstream msg;
83  msg << "An output module label can not be determined from a ";
84  msg << "faulty or incomplete INIT message.";
85  XCEPT_RAISE(stor::exception::IncompleteInitMessage, msg.str());
86  }
87 
89  return outputModuleLabel_;
90  }
91 
93  {
94  if ( !headerOkay() )
95  {
96  std::stringstream msg;
97  msg << "An output module ID can not be determined from a ";
98  msg << "faulty or incomplete INIT message.";
99  XCEPT_RAISE(stor::exception::IncompleteInitMessage, msg.str());
100  }
101 
103  return outputModuleId_;
104  }
105 
107  {
108  if ( !headerOkay() )
109  {
110  std::stringstream msg;
111  msg << "The HLT trigger names can not be determined from a ";
112  msg << "faulty or incomplete INIT message.";
113  XCEPT_RAISE(stor::exception::IncompleteInitMessage, msg.str());
114  }
115 
117  nameList = hltTriggerNames_;
118  }
119 
121  {
122  if ( !headerOkay() )
123  {
124  std::stringstream msg;
125  msg << "The HLT trigger selections can not be determined from a ";
126  msg << "faulty or incomplete INIT message.";
127  XCEPT_RAISE(stor::exception::IncompleteInitMessage, msg.str());
128  }
129 
131  nameList = hltTriggerSelections_;
132  }
133 
135  {
136  if ( !headerOkay() )
137  {
138  std::stringstream msg;
139  msg << "The L1 trigger names can not be determined from a ";
140  msg << "faulty or incomplete INIT message.";
141  XCEPT_RAISE(stor::exception::IncompleteInitMessage, msg.str());
142  }
143 
145  nameList = l1TriggerNames_;
146  }
147 
149  {
150  if ( parsable() )
151  {
153  (I2O_SM_PREAMBLE_MESSAGE_FRAME*) ref_->getDataLocation();
155  fragKey_.run_ = 0;
156  fragKey_.event_ = smMsg->hltTid;
157  fragKey_.secondaryId_ = smMsg->outModID;
160  rbBufferId_ = smMsg->rbBufferID;
161  hltLocalId_ = smMsg->hltLocalId;
162  hltInstance_ = smMsg->hltInstance;
163  hltTid_ = smMsg->hltTid;
164  fuProcessId_ = smMsg->fuProcID;
165  fuGuid_ = smMsg->fuGUID;
166  nExpectedEPs_ = smMsg->nExpectedEPs;
167  }
168  }
169 
171  {
172  unsigned char* firstFragLoc = dataLocation(0);
173  unsigned long firstFragSize = dataSize(0);
174  bool useFirstFrag = false;
175 
176  // if there is only one fragment, use it
177  if (fragmentCount_ == 1)
178  {
179  useFirstFrag = true;
180  }
181  // otherwise, check if the first fragment is large enough to hold
182  // the full INIT message header (we require some minimal fixed
183  // size in the hope that we don't parse garbage when we overlay
184  // the InitMsgView on the buffer)
185  else if (firstFragSize > (sizeof(InitHeader) + 16384))
186  {
187  InitMsgView view(firstFragLoc);
188  if (view.headerSize() <= firstFragSize)
189  {
190  useFirstFrag = true;
191  }
192  }
193 
194  boost::shared_ptr<InitMsgView> msgView;
195  if (useFirstFrag)
196  {
197  msgView.reset(new InitMsgView(firstFragLoc));
198  }
199  else
200  {
202  msgView.reset(new InitMsgView(&headerCopy_[0]));
203  }
204 
205  headerSize_ = msgView->headerSize();
206  headerLocation_ = msgView->startAddress();
207  adler32_ = msgView->adler32_chksum();
208  outputModuleLabel_ = msgView->outputModuleLabel();
209  outputModuleId_ = msgView->outputModuleId();
210  msgView->hltTriggerNames(hltTriggerNames_);
211  msgView->hltTriggerSelections(hltTriggerSelections_);
212  msgView->l1TriggerNames(l1TriggerNames_);
213 
214  headerFieldsCached_ = true;
215 
216  #ifdef STOR_DEBUG_WRONG_ADLER
217  double r = rand()/static_cast<double>(RAND_MAX);
218  if (r < 0.01)
219  {
220  std::cout << "Simulating corrupt Adler calculation" << std::endl;
221  headerSize_ += 3;
222  }
223  else if (r < 0.02)
224  {
225  std::cout << "Simulating corrupt Adler entry" << std::endl;
226  adler32_ += r*10000;
227  }
228  #endif // STOR_DEBUG_WRONG_ADLER
229  }
230 
231  } // namespace detail
232 
233 } // namespace stor
234 
235 
std::vector< unsigned char > headerCopy_
Definition: ChainData.h:259
uint32 originatorPid_
Definition: FragKey.h:39
unsigned char * dataLocation(int fragmentIndex) const
Definition: ChainData.cc:449
unsigned char * do_headerLocation() const
Definition: InitMsgData.cc:38
unsigned int rbBufferId_
Definition: ChainData.h:164
#define I2O_SM_PREAMBLE
Definition: i2oEvfMsgs.h:21
toolbox::mem::Reference * ref_
Definition: ChainData.h:154
std::vector< std::string > Strings
Definition: MsgTools.h:18
unsigned int hltTid_
Definition: ChainData.h:167
void do_hltTriggerNames(Strings &nameList) const
Definition: InitMsgData.cc:106
std::string outputModuleLabel_
Definition: ChainData.h:265
unsigned char * headerLocation_
Definition: ChainData.h:261
uint32 event_
Definition: FragKey.h:34
unsigned long do_headerSize() const
Definition: InitMsgData.cc:27
void do_hltTriggerSelections(Strings &nameList) const
Definition: InitMsgData.cc:120
void addFirstFragment(toolbox::mem::Reference *)
Definition: ChainData.cc:115
bool parsable() const
Definition: ChainData.cc:103
uint32 originatorGuid_
Definition: FragKey.h:40
void do_l1TriggerNames(Strings &nameList) const
Definition: InitMsgData.cc:134
uint32_t do_outputModuleId() const
Definition: InitMsgData.cc:92
InitMsgData(toolbox::mem::Reference *pRef)
Definition: InitMsgData.cc:14
unsigned int copyFragmentsIntoBuffer(std::vector< unsigned char > &buff) const
Definition: ChainData.cc:489
unsigned int hltLocalId_
Definition: ChainData.h:165
uint8 code_
Definition: FragKey.h:32
uint32 run_
Definition: FragKey.h:33
unsigned int fuProcessId_
Definition: ChainData.h:168
_I2O_SM_PREAMBLE_MESSAGE_FRAME I2O_SM_PREAMBLE_MESSAGE_FRAME
uint32 headerSize() const
Definition: InitMessage.h:88
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 secondaryId_
Definition: FragKey.h:38
std::string do_outputModuleLabel() const
Definition: InitMsgData.cc:78
unsigned long headerSize_
Definition: ChainData.h:260
unsigned int messageCode_
Definition: ChainData.h:159
Signal rand(Signal arg)
Definition: vlib.cc:442
size_t do_i2oFrameSize() const
Definition: InitMsgData.cc:22
unsigned char * do_fragmentLocation(unsigned char *dataLoc) const
Definition: InitMsgData.cc:50
tuple cout
Definition: gather_cfg.py:121
bool headerOkay() const
Definition: ChainData.cc:110
void cacheHeaderFields() const
Definition: InitMsgData.cc:170
uint32_t do_adler32Checksum() const
Definition: InitMsgData.cc:64
unsigned int hltInstance_
Definition: ChainData.h:166