CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DCCBlockPrototype.cc
Go to the documentation of this file.
1 #include "DCCBlockPrototype.h"
2 #include "DCCDataParser.h"
3 #include "DCCDataMapper.h"
5 
6 #include <stdio.h>
7 #include <sstream>
8 
9 
10 DCCTBBlockPrototype::DCCTBBlockPrototype(DCCTBDataParser * parser, std::string name, uint32_t * buffer, uint32_t numbBytes, uint32_t wordsToEndOfEvent, uint32_t wordEventOffset ){
11 
12  blockError_ = false;
13  parser_ = parser;
14  name_ = name;
15  dataP_ = buffer ;
16  beginOfBuffer_ = buffer ;
17  blockSize_ = numbBytes ;
18  wordEventOffset_ = wordEventOffset;
19  wordsToEndOfEvent_ = wordsToEndOfEvent;
20 
21  wordCounter_ = 0;
22 
23  /*
24  std::cout<<std::endl;
25  std::cout<<" DEBUG::DCCTBBlockPrototype:: Block Name : "<<name_<<std::endl;
26  std::cout<<" DEBUG::DCCTBBlockPrototype:: Block size [bytes] : "<<std::dec<<blockSize_<<std::endl;
27  std::cout<<" DEBUG::DCCTBBlockPrototype:: Number Of Words : "<<std::dec<<blockSize_/4<<std::endl;
28  std::cout<<" DEBUG::DCCTBBlockPrototype:: word event offset : "<<std::dec<<wordEventOffset_<<std::endl;
29  std::cout<<" DEBUG::DCCTBBlockPrototype:: words to end of event : "<<std::dec<<wordsToEndOfEvent_<<std::endl;
30  std::cout<<" DEBUG::DCCTBBlockPrototype:: First Word (*dataP_) : 0x"<<hex<<(*dataP_)<<std::endl;
31  std::cout<<std::endl;
32  */
33 }
34 
35 
37  std::set<DCCTBDataField *,DCCTBDataFieldComparator>::iterator it; //iterator for data fields
38 
39  //for debug purposes
40  //std::cout << "Starting to parse data in block named : " << std::endl;
41  //std::cout << " Fields: " << std::dec << (mapperFields_->size()) << std::endl;
42  //std::cout << "\n begin of buffer : "<<hex<<(*beginOfBuffer_)<<std::endl;
43 
44  //cycle through mapper fields
45  for(it = mapperFields_->begin(); it!= mapperFields_->end(); it++){
46 
47  /*
48  //for debug purposes
49  std::cout << "\n Field name : " << (*it)->name();
50  std::cout << "\n Word position : " <<std::dec<< (*it)->wordPosition();
51  std::cout << "\n Bit position : " << (*it)->bitPosition();
52  std::cout << "\n Size : " << hex << (*it)->mask() << std::endl;
53  std::cout << "\n data pointer : " <<hex<<(*dataP_)<<std::endl;
54  std::cout << "\n wordsToEndOfEvent : " <<std::dec<<wordsToEndOfEvent_<<std::endl;
55  */
56 
57  try{
58  uint32_t data = getDataWord( (*it)->wordPosition() , (*it)->bitPosition(),(*it)->mask());
59  dataFields_[(*it)->name()]= data;
60 
61  }catch( ECALTBParserBlockException & e){
62 
63  std::string localString;
64 
65  localString +="\n ======================================================================\n";
66  localString += std::string(" ") + name_ + std::string(" :: out of scope Error :: Unable to get data field : ") + (*it)->name();
67  localString += "\n Word position inside block : " + parser_->getDecString( (*it)->wordPosition() );
68  localString += "\n Word position inside event : " + parser_->getDecString( (*it)->wordPosition() + wordEventOffset_);
69  localString += "\n Block Size [bytes] : " + parser_->getDecString(blockSize_);
70  localString += "\n Action -> Stop parsing this block !";
71  localString += "\n ======================================================================";
72 
73  std::string error("\n Last decoded fields until error : ");
74 
75  std::ostringstream a;
76 
77  try{ displayData(a);}
78  catch(ECALTBParserBlockException &e){}
79 
80  std::string outputErrorString(a.str());
81  error += outputErrorString;
82 
83  errorString_ += localString + error;
84 
85  blockError_ = true;
86 
88 
89  }
90  }
91 
92  //debugg
93  //displayData(std::cout);
94 }
95 
96 
97 
98 uint32_t DCCTBBlockPrototype::getDataWord(uint32_t wordPosition, uint32_t bitPosition, uint32_t mask){
99 
100  /*
101  std::cout<<"\n DEBUG::DCCTBBlockPrototype getDataWord method "
102  <<"\n DEBUG::DCCTBBlockPrototype wordPosition = "<<wordPosition
103  <<"\n DEBUG::DCCTBBlockPrototype wordCounter = "<<wordCounter_
104  <<"\n DEBUG::DCCTBBlockPrototype going to increment = "<<(wordPosition-wordCounter_)<<std::endl;
105  */
106  if( wordPosition > wordCounter_ ){ increment(wordPosition - wordCounter_); }
107 
108  return ((*dataP_)>>bitPosition)&mask;
109 
110 }
111 
112 
113 
114 void DCCTBBlockPrototype::increment(uint32_t numb,std::string msg){
115 
116  seeIfIsPossibleToIncrement(numb,msg);
117  dataP_ += numb; wordCounter_ += numb;
118 }
119 
120 
121 
122 void DCCTBBlockPrototype::seeIfIsPossibleToIncrement(uint32_t numb, std::string msg){
123 
124  /*
125  std::cout<<"\n See if is possible to increment numb ="<<std::dec<<numb<<" msg "<<msg<<std::endl;
126  std::cout<<" wordCounter_ "<<wordCounter_<<std::endl;
127  std::cout<<" blockSize "<<blockSize_<<std::endl;
128  std::cout<<" wordsToEndOfEvent_ "<<wordsToEndOfEvent_<<std::endl;
129  */
130 
131  if (( ((wordCounter_+numb +1) > blockSize_/4)) ||( wordCounter_ + numb > wordsToEndOfEvent_ )){
132 
133  std::string error=std::string("\n Unable to get next block position (parser stoped!)") +msg;
134  error += "\n Decoded fields untill error : ";
135  //ostream dataUntilError ;
136  std::ostringstream a;
137  std::string outputErrorString;
138 
139 
140  try{ displayData(a);}
141  catch(ECALTBParserBlockException &e){}
142  outputErrorString = a.str();
143  error += outputErrorString;
144 
145  throw ECALTBParserBlockException(error);
146  blockError_=true;
147  }
148 
149 }
150 
151 
152 
153 void DCCTBBlockPrototype::displayData( std::ostream & os ){
154 
155 
156  std::set<DCCTBDataField *,DCCTBDataFieldComparator>::iterator it;
157 
158  bool process(true);
159  os << "\n ======================================================================\n";
160  os << " Block name : "<<name_<<", size : "<<std::dec<<blockSize_<<" bytes, event WOffset : "<<wordEventOffset_;
161  long currentPosition(0), position(-1);
162 
163  std::string dataFieldName;
164  for(it = mapperFields_->begin(); it!= mapperFields_->end() && process; it++){
165  try{
166  dataFieldName = (*it)->name();
167  currentPosition = (*it)->wordPosition();
168  if( currentPosition != position ){
169  os << "\n W["<<std::setw(5)<<std::setfill('0')<<currentPosition<<"]" ;
170  position = currentPosition;
171  }
172  os<<" "<<formatString(dataFieldName,14)<<" = "<<std::dec<<std::setw(5)<<getDataField(dataFieldName);
173  } catch (ECALTBParserBlockException & e){ process = false; os<<" not able to get data field..."<<dataFieldName<<std::endl;}
174  }
175  os<<"\n ======================================================================\n";
176 
177 }
178 
179 
180 
181 
182 
183 std::pair<bool,std::string> DCCTBBlockPrototype::checkDataField(std::string name, uint32_t data){
184 
185  std::string output("");
186  std::pair<bool,std::string> res;
187  bool errorFound(false);
188  uint32_t parsedData = getDataField(name);
189  if( parsedData != data){
190  output += std::string("\n Field : ")+name+(" has value ")+parser_->getDecString( parsedData )+ std::string(", while ")+parser_->getDecString(data)+std::string(" is expected");
191 
192  //debug//////////
193  //std::cout<<output<<std::endl;
195 
196  blockError_ = true;
197  errorFound = true;
198  }
199  res.first = !errorFound;
200  res.second = output;
201  return res;
202 }
203 
204 
205 
207 
208  std::map<std::string,uint32_t>::iterator it = dataFields_.find(name);
209  if(it == dataFields_.end()){
210  throw ECALTBParserBlockException( std::string("\n field named : ")+name+std::string(" was not found in block ")+name_ );
211  blockError_=true;
212  }
213 
214  return (*it).second;
215 
216 }
217 
218 
219 
220 std::string DCCTBBlockPrototype::formatString(std::string myString,uint32_t minPositions){
221  std::string ret(myString);
222  uint32_t stringSize = ret.size();
223  if( minPositions > stringSize ){
224  for(uint32_t i=0;i< minPositions-stringSize;i++){ ret+=" ";}
225  }
226  return ret;
227 
228 }
229 
230 
231 
232 
233 
234 
235 void DCCTBBlockPrototype::setDataField(std::string name, uint32_t data){
236  std::set<DCCTBDataField *,DCCTBDataFieldComparator>::iterator it; //iterator for data fields
237  bool fieldFound(false);
238  for(it = mapperFields_->begin(); it!= mapperFields_->end(); it++){
239  if( ! ((*it)->name()).compare(name) ){ fieldFound = true; }
240  }
241 
242  if(fieldFound){ dataFields_[name]= data;}
243  else{
244  throw ECALTBParserBlockException( std::string("\n field named : ")+name+std::string(" was not found in block ")+name_ );
245  }
246 
247 }
248 
249 
250 
251 
252 
253 
255 
256 
257  std::pair<bool,std::string> ret(true,"");
258 
259 
260  std::set<DCCTBDataField *,DCCTBDataFieldComparator>::iterator it;
261  std::stringstream out;
262 
263 
264 
265  out<<"\n ======================================================================";
266  out<<"\n ORIGINAL BLOCK : ";
267  out<<"\n Block name : "<<name_<<", size : "<<std::dec<<blockSize_<<" bytes, event WOffset : "<<wordEventOffset_;
268  out<<"\n COMPARISION BLOCK : ";
269  out<<"\n Block name : "<<(block->name())<<", size : "<<std::dec<<(block->size())<<" bytes, event WOffset : "<<(block->wOffset());
270  out<<"\n =====================================================================";
271 
272 
273  if( block->name() != name_ ){
274  ret.first = false;
275  out<<"\n ERROR >> It is not possible to compare blocks with different names ! ";
276  ret.second += out.str();
277  return ret;
278  }
279 
280  if( block->size() != blockSize_ ){
281  ret.first = false;
282  out<<"\n WARNING >> Blocks have different sizes "
283  <<"\n WARNING >> Comparision will be carried on untill possible";
284  }
285 
286 
287  if( block->wOffset()!= wordEventOffset_){
288  ret.first = false;
289  out<<"\n WARNING >> Blocks have different word offset within the event ";
290  }
291 
292 
293  std::string dataFieldName;
294 
295  for(it = mapperFields_->begin(); it!= mapperFields_->end(); it++){
296 
297  dataFieldName = (*it)->name();
298 
299  uint32_t aValue, bValue;
300 
301  //Access original block data fields /////////////////////////////////////////////////////
302  try{ aValue = getDataField(dataFieldName); }
303 
304  catch(ECALTBParserBlockException &e ){
305  ret.first = false;
306  out<<"\n ERROR ON ORIGINAL BLOCK unable to get data field :"<<dataFieldName;
307  out<<"\n Comparision was stoped ! ";
308  ret.second += out.str();
309  return ret;
310  }
312 
313  //Access comparision block data fields ///////////////////////////////////////////////////////
314  try{ bValue = block->getDataField(dataFieldName); }
315  catch(ECALTBParserBlockException &e ){
316  ret.first = false;
317  out<<"\n ERROR ON COMPARISION BLOCK unable to get data field :"<<dataFieldName
318  <<"\n Comparision was stoped ! ";
319  ret.second += out.str();
320  return ret;
321  }
323 
324 
325  //std::cout<<"\n data Field name "<<dataFieldName<<std::endl;
326  //std::cout<<"\n aValue "<<std::dec<<aValue<<std::endl;
327  //std::cout<<"\n bValue "<<std::dec<<bValue<<std::endl;
328 
329 
330 
331  // Compare values
332  if( aValue != bValue ){
333  ret.first = false;
334  out<<"\n Data Field : "<<dataFieldName
335  <<"\n ORIGINAL BLOCK value : "<<std::dec<<std::setw(5)<<aValue<<" , COMPARISION BLOCK value : "<<std::dec<<std::setw(5)<<bValue;
336  //std::cout<<"\n debug... "<<out<<std::endl;
337  }
338  }
339  out<<"\n ======================================================================\n";
340  ret.second = out.str();
341 
342  return ret;
343 
344 }
virtual std::pair< bool, std::string > checkDataField(std::string name, uint32_t data)
virtual uint32_t getDataField(std::string name)
int i
Definition: DBlmapReader.cc:9
std::set< DCCTBDataField *, DCCTBDataFieldComparator > * mapperFields_
virtual void increment(uint32_t numb, std::string msg="")
virtual void parseData()
DCCTBDataParser * parser_
std::map< std::string, uint32_t > dataFields_
DCCTBBlockPrototype(DCCTBDataParser *parser, std::string name, uint32_t *buffer, uint32_t numbBytes, uint32_t wordsToEndOfEvent, uint32_t wordEventOffset=0)
std::string getDecString(uint32_t data)
virtual uint32_t getDataWord(uint32_t wordPosition, uint32_t bitPosition, uint32_t mask)
virtual void displayData(std::ostream &os=std::cout)
tuple out
Definition: dbtoconf.py:99
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
double a
Definition: hdecay.h:121
static int position[264][3]
Definition: ReadPGInfo.cc:509
virtual void seeIfIsPossibleToIncrement(uint32_t numb, std::string msg="")
virtual void setDataField(std::string name, uint32_t data)
tuple process
Definition: LaserDQM_cfg.py:3
virtual std::pair< bool, std::string > compare(DCCTBBlockPrototype *block)
std::string formatString(std::string myString, uint32_t minPositions)