Go to the documentation of this file.00001 #include "DCCBlockPrototype.h"
00002 #include "DCCDataParser.h"
00003 #include "DCCDataMapper.h"
00004 #include "ECALParserBlockException.h"
00005
00006 #include <stdio.h>
00007 #include <sstream>
00008
00009
00010 DCCTBBlockPrototype::DCCTBBlockPrototype(DCCTBDataParser * parser, std::string name, uint32_t * buffer, uint32_t numbBytes, uint32_t wordsToEndOfEvent, uint32_t wordEventOffset ){
00011
00012 blockError_ = false;
00013 parser_ = parser;
00014 name_ = name;
00015 dataP_ = buffer ;
00016 beginOfBuffer_ = buffer ;
00017 blockSize_ = numbBytes ;
00018 wordEventOffset_ = wordEventOffset;
00019 wordsToEndOfEvent_ = wordsToEndOfEvent;
00020
00021 wordCounter_ = 0;
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 }
00034
00035
00036 void DCCTBBlockPrototype::parseData(){
00037 std::set<DCCTBDataField *,DCCTBDataFieldComparator>::iterator it;
00038
00039
00040
00041
00042
00043
00044
00045 for(it = mapperFields_->begin(); it!= mapperFields_->end(); it++){
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 try{
00058 uint32_t data = getDataWord( (*it)->wordPosition() , (*it)->bitPosition(),(*it)->mask());
00059 dataFields_[(*it)->name()]= data;
00060
00061 }catch( ECALTBParserBlockException & e){
00062
00063 std::string localString;
00064
00065 localString +="\n ======================================================================\n";
00066 localString += std::string(" ") + name_ + std::string(" :: out of scope Error :: Unable to get data field : ") + (*it)->name();
00067 localString += "\n Word position inside block : " + parser_->getDecString( (*it)->wordPosition() );
00068 localString += "\n Word position inside event : " + parser_->getDecString( (*it)->wordPosition() + wordEventOffset_);
00069 localString += "\n Block Size [bytes] : " + parser_->getDecString(blockSize_);
00070 localString += "\n Action -> Stop parsing this block !";
00071 localString += "\n ======================================================================";
00072
00073 std::string error("\n Last decoded fields until error : ");
00074
00075 std::ostringstream a;
00076
00077 try{ displayData(a);}
00078 catch(ECALTBParserBlockException &e){}
00079
00080 std::string outputErrorString(a.str());
00081 error += outputErrorString;
00082
00083 errorString_ += localString + error;
00084
00085 blockError_ = true;
00086
00087 throw( ECALTBParserBlockException(errorString_) );
00088
00089 }
00090 }
00091
00092
00093
00094 }
00095
00096
00097
00098 uint32_t DCCTBBlockPrototype::getDataWord(uint32_t wordPosition, uint32_t bitPosition, uint32_t mask){
00099
00100
00101
00102
00103
00104
00105
00106 if( wordPosition > wordCounter_ ){ increment(wordPosition - wordCounter_); }
00107
00108 return ((*dataP_)>>bitPosition)&mask;
00109
00110 }
00111
00112
00113
00114 void DCCTBBlockPrototype::increment(uint32_t numb,std::string msg){
00115
00116 seeIfIsPossibleToIncrement(numb,msg);
00117 dataP_ += numb; wordCounter_ += numb;
00118 }
00119
00120
00121
00122 void DCCTBBlockPrototype::seeIfIsPossibleToIncrement(uint32_t numb, std::string msg){
00123
00124
00125
00126
00127
00128
00129
00130
00131 if (( ((wordCounter_+numb +1) > blockSize_/4)) ||( wordCounter_ + numb > wordsToEndOfEvent_ )){
00132
00133 std::string error=std::string("\n Unable to get next block position (parser stoped!)") +msg;
00134 error += "\n Decoded fields untill error : ";
00135
00136 std::ostringstream a;
00137 std::string outputErrorString;
00138
00139
00140 try{ displayData(a);}
00141 catch(ECALTBParserBlockException &e){}
00142 outputErrorString = a.str();
00143 error += outputErrorString;
00144
00145 throw ECALTBParserBlockException(error);
00146 blockError_=true;
00147 }
00148
00149 }
00150
00151
00152
00153 void DCCTBBlockPrototype::displayData( std::ostream & os ){
00154
00155
00156 std::set<DCCTBDataField *,DCCTBDataFieldComparator>::iterator it;
00157
00158 bool process(true);
00159 os << "\n ======================================================================\n";
00160 os << " Block name : "<<name_<<", size : "<<std::dec<<blockSize_<<" bytes, event WOffset : "<<wordEventOffset_;
00161 long currentPosition(0), position(-1);
00162
00163 std::string dataFieldName;
00164 for(it = mapperFields_->begin(); it!= mapperFields_->end() && process; it++){
00165 try{
00166 dataFieldName = (*it)->name();
00167 currentPosition = (*it)->wordPosition();
00168 if( currentPosition != position ){
00169 os << "\n W["<<std::setw(5)<<std::setfill('0')<<currentPosition<<"]" ;
00170 position = currentPosition;
00171 }
00172 os<<" "<<formatString(dataFieldName,14)<<" = "<<std::dec<<std::setw(5)<<getDataField(dataFieldName);
00173 } catch (ECALTBParserBlockException & e){ process = false; os<<" not able to get data field..."<<dataFieldName<<std::endl;}
00174 }
00175 os<<"\n ======================================================================\n";
00176
00177 }
00178
00179
00180
00181
00182
00183 std::pair<bool,std::string> DCCTBBlockPrototype::checkDataField(std::string name, uint32_t data){
00184
00185 std::string output("");
00186 std::pair<bool,std::string> res;
00187 bool errorFound(false);
00188 uint32_t parsedData = getDataField(name);
00189 if( parsedData != data){
00190 output += std::string("\n Field : ")+name+(" has value ")+parser_->getDecString( parsedData )+ std::string(", while ")+parser_->getDecString(data)+std::string(" is expected");
00191
00192
00193
00195
00196 blockError_ = true;
00197 errorFound = true;
00198 }
00199 res.first = !errorFound;
00200 res.second = output;
00201 return res;
00202 }
00203
00204
00205
00206 uint32_t DCCTBBlockPrototype::getDataField(std::string name){
00207
00208 std::map<std::string,uint32_t>::iterator it = dataFields_.find(name);
00209 if(it == dataFields_.end()){
00210 throw ECALTBParserBlockException( std::string("\n field named : ")+name+std::string(" was not found in block ")+name_ );
00211 blockError_=true;
00212 }
00213
00214 return (*it).second;
00215
00216 }
00217
00218
00219
00220 std::string DCCTBBlockPrototype::formatString(std::string myString,uint32_t minPositions){
00221 std::string ret(myString);
00222 uint32_t stringSize = ret.size();
00223 if( minPositions > stringSize ){
00224 for(uint32_t i=0;i< minPositions-stringSize;i++){ ret+=" ";}
00225 }
00226 return ret;
00227
00228 }
00229
00230
00231
00232
00233
00234
00235 void DCCTBBlockPrototype::setDataField(std::string name, uint32_t data){
00236 std::set<DCCTBDataField *,DCCTBDataFieldComparator>::iterator it;
00237 bool fieldFound(false);
00238 for(it = mapperFields_->begin(); it!= mapperFields_->end(); it++){
00239 if( ! ((*it)->name()).compare(name) ){ fieldFound = true; }
00240 }
00241
00242 if(fieldFound){ dataFields_[name]= data;}
00243 else{
00244 throw ECALTBParserBlockException( std::string("\n field named : ")+name+std::string(" was not found in block ")+name_ );
00245 }
00246
00247 }
00248
00249
00250
00251
00252
00253
00254 std::pair<bool,std::string> DCCTBBlockPrototype::compare(DCCTBBlockPrototype * block){
00255
00256
00257 std::pair<bool,std::string> ret(true,"");
00258
00259
00260 std::set<DCCTBDataField *,DCCTBDataFieldComparator>::iterator it;
00261 std::stringstream out;
00262
00263
00264
00265 out<<"\n ======================================================================";
00266 out<<"\n ORIGINAL BLOCK : ";
00267 out<<"\n Block name : "<<name_<<", size : "<<std::dec<<blockSize_<<" bytes, event WOffset : "<<wordEventOffset_;
00268 out<<"\n COMPARISION BLOCK : ";
00269 out<<"\n Block name : "<<(block->name())<<", size : "<<std::dec<<(block->size())<<" bytes, event WOffset : "<<(block->wOffset());
00270 out<<"\n =====================================================================";
00271
00272
00273 if( block->name() != name_ ){
00274 ret.first = false;
00275 out<<"\n ERROR >> It is not possible to compare blocks with different names ! ";
00276 ret.second += out.str();
00277 return ret;
00278 }
00279
00280 if( block->size() != blockSize_ ){
00281 ret.first = false;
00282 out<<"\n WARNING >> Blocks have different sizes "
00283 <<"\n WARNING >> Comparision will be carried on untill possible";
00284 }
00285
00286
00287 if( block->wOffset()!= wordEventOffset_){
00288 ret.first = false;
00289 out<<"\n WARNING >> Blocks have different word offset within the event ";
00290 }
00291
00292
00293 std::string dataFieldName;
00294
00295 for(it = mapperFields_->begin(); it!= mapperFields_->end(); it++){
00296
00297 dataFieldName = (*it)->name();
00298
00299 uint32_t aValue, bValue;
00300
00301
00302 try{ aValue = getDataField(dataFieldName); }
00303
00304 catch(ECALTBParserBlockException &e ){
00305 ret.first = false;
00306 out<<"\n ERROR ON ORIGINAL BLOCK unable to get data field :"<<dataFieldName;
00307 out<<"\n Comparision was stoped ! ";
00308 ret.second += out.str();
00309 return ret;
00310 }
00312
00313
00314 try{ bValue = block->getDataField(dataFieldName); }
00315 catch(ECALTBParserBlockException &e ){
00316 ret.first = false;
00317 out<<"\n ERROR ON COMPARISION BLOCK unable to get data field :"<<dataFieldName
00318 <<"\n Comparision was stoped ! ";
00319 ret.second += out.str();
00320 return ret;
00321 }
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332 if( aValue != bValue ){
00333 ret.first = false;
00334 out<<"\n Data Field : "<<dataFieldName
00335 <<"\n ORIGINAL BLOCK value : "<<std::dec<<std::setw(5)<<aValue<<" , COMPARISION BLOCK value : "<<std::dec<<std::setw(5)<<bValue;
00336
00337 }
00338 }
00339 out<<"\n ======================================================================\n";
00340 ret.second = out.str();
00341
00342 return ret;
00343
00344 }