00001 #include "DCCTowerBlock.h"
00002 #include "DCCEventBlock.h"
00003 #include "DCCDataParser.h"
00004 #include "DCCXtalBlock.h"
00005 #include "DCCEventBlock.h"
00006 #include "DCCDataMapper.h"
00007 #include "ECALParserBlockException.h"
00008 #include <stdio.h>
00009
00010
00011
00012 DCCTBTowerBlock::DCCTBTowerBlock(
00013 DCCTBEventBlock * dccBlock,
00014 DCCTBDataParser * parser,
00015 ulong * buffer,
00016 ulong numbBytes,
00017 ulong wordsToEnd,
00018 ulong wordEventOffset,
00019 ulong expectedTowerID
00020 )
00021 : DCCTBBlockPrototype(parser,"TOWERHEADER", buffer, numbBytes,wordsToEnd, wordEventOffset )
00022 , dccBlock_(dccBlock), expectedTowerID_(expectedTowerID)
00023 {
00024
00025
00026 errors_["FE::HEADER"] = 0;
00027 errors_["FE::TT/SC ID"] = 0;
00028 errors_["FE::BLOCK LENGTH"] = 0;
00030
00031
00032
00033
00034 mapperFields_ = parser_->mapper()->towerFields();
00035 parseData();
00037 }
00038
00039
00040 void DCCTBTowerBlock::parseXtalData(){
00041
00042 ulong numbBytes = blockSize_;
00043 ulong wordsToEnd =wordsToEndOfEvent_;
00044
00045
00046 ulong numbDWInXtalBlock = ( parser_->numbXtalSamples() )/4 + 1;
00047 ulong length = getDataField("BLOCK LENGTH");
00048 ulong numbOfXtalBlocks = 0 ;
00049
00050 if( length > 0 ){ numbOfXtalBlocks = (length-1)/numbDWInXtalBlock; }
00051 ulong xtalBlockSize = numbDWInXtalBlock*8;
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061 bool zs = dccBlock_->getDataField("ZS");
00062 if( !zs && numbOfXtalBlocks != 25 ){
00063
00064
00065 (errors_["FE::BLOCK LENGTH"])++;
00066 errorString_ += "\n ======================================================================\n";
00067 errorString_ += std::string(" ") + name_ + std::string(" ZS is not active, error in the Tower Length !") ;
00068 errorString_ += "\n Tower Length is : " + (parser_->getDecString(numbBytes/8))+std::string(" , while it should be : ");
00069 std::string myString = parser_->getDecString((ulong)(25*numbDWInXtalBlock+1));
00070 errorString_ += "\n It was only possible to build : " + parser_->getDecString( numbOfXtalBlocks)+ std::string(" XTAL blocks");
00071 errorString_ += "\n ======================================================================";
00072 blockError_ = true;
00073 };
00074 if( numbOfXtalBlocks > 25 ){
00075 if (errors_["FE::BLOCK LENGTH"]==0)(errors_["FE::BLOCK LENGTH"])++;
00076 errorString_ += "\n ======================================================================\n";
00077 errorString_ += std::string(" ") + name_ + std::string(" Tower Length is larger then expected...!") ;
00078 errorString_ += "\n Tower Length is : " + parser_->getDecString(numbBytes/8)+std::string(" , while it should be at maximum : ");
00079 std::string myString = parser_->getDecString((ulong)(25*numbDWInXtalBlock+1));
00080 errorString_ += "\n Action -> data after the xtal 25 is ignored... ";
00081 errorString_ += "\n ======================================================================";
00082 blockError_ = true;
00083
00084 }
00086
00087 blockSize_ += length*8;
00088
00089
00090 ulong stripID, xtalID;
00091
00092
00093 for(ulong numbXtal=1; numbXtal <= numbOfXtalBlocks && numbXtal <=25 ; numbXtal++){
00094
00095 increment(1);
00096
00097 stripID =( numbXtal-1)/5 + 1;
00098 xtalID = numbXtal - (stripID-1)*5;
00099
00100
00101 if(!zs){
00102 xtalBlocks_.push_back( new DCCTBXtalBlock( parser_, dataP_, xtalBlockSize, wordsToEnd-wordCounter_,wordCounter_+wordEventOffset_,xtalID, stripID) );
00103 }else{
00104 xtalBlocks_.push_back( new DCCTBXtalBlock( parser_, dataP_, xtalBlockSize, wordsToEnd-wordCounter_,wordCounter_+wordEventOffset_,0,0));
00105 }
00106
00107 increment(xtalBlockSize/4-1);
00108 }
00110
00111
00112
00113 if(parser_->debug()){ dataCheck();};
00115 }
00116
00117
00118
00119 DCCTBTowerBlock::~DCCTBTowerBlock(){
00120 std::vector<DCCTBXtalBlock *>::iterator it;
00121 for(it=xtalBlocks_.begin();it!=xtalBlocks_.end();it++){ delete (*it);}
00122 xtalBlocks_.clear();
00123 }
00124
00125
00126
00127 void DCCTBTowerBlock::dataCheck(){
00128 std::string checkErrors("");
00129
00130
00131 std::pair <bool,std::string> res;
00132
00134
00135
00136
00138
00139
00140 res = checkDataField("LV1", L1MASK & (dccBlock_->getDataField("LV1") -1) );
00141 if(!res.first){ checkErrors += res.second; (errors_["FE::HEADER"])++; }
00142
00143
00144 if(expectedTowerID_ != 0){
00145 res = checkDataField("TT/SC ID",expectedTowerID_);
00146 if(!res.first){ checkErrors += res.second; (errors_["FE::HEADER"])++; }
00147 }
00148
00149 if( checkErrors !="" ){
00150 std::string myTowerId;
00151
00152 errorString_ +="\n ======================================================================\n";
00153 errorString_ += std::string(" ") + name_ + std::string("( ID = ")+parser_->getDecString((ulong)(expectedTowerID_))+std::string(" ) errors : ") ;
00154 errorString_ += checkErrors ;
00155 errorString_ += "\n ======================================================================";
00156 blockError_ = true;
00157 }
00158 }
00159
00160
00161 std::vector< DCCTBXtalBlock * > DCCTBTowerBlock::xtalBlocksById(ulong stripId, ulong xtalId){
00162 std::vector<DCCTBXtalBlock *> myVector;
00163 std::vector<DCCTBXtalBlock *>::iterator it;
00164
00165 for( it = xtalBlocks_.begin(); it!= xtalBlocks_.end(); it++ ){
00166 try{
00167
00168 std::pair<bool,std::string> stripIdCheck = (*it)->checkDataField("STRIP ID",stripId);
00169 std::pair<bool,std::string> xtalIdCheck = (*it)->checkDataField("XTAL ID",xtalId);
00170
00171 if(xtalIdCheck.first && stripIdCheck.first ){ myVector.push_back( (*it) ); }
00172
00173 }catch (ECALTBParserBlockException &e){ }
00174 }
00175
00176 return myVector;
00177 }
00178
00179 int DCCTBTowerBlock::towerID() {
00180 int result=-1;
00181
00182 for(std::set<DCCTBDataField *,DCCTBDataFieldComparator>::iterator it = mapperFields_->begin(); it!= mapperFields_->end(); it++){
00183 if ( (*it)->name() == "TT/SC ID" )
00184 result=getDataField( (*it)->name() ) ;
00185
00186 }
00187
00188 return result;
00189
00190 }