/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Event/RawDataCnv/RawDataCnv-00-04-35/src/EventManagement/TofBuilder.cxx

Go to the documentation of this file.
00001 #include <iostream>
00002 #include <fstream>
00003 #include "Identifier/TofID.h"
00004 #include "RawDataCnv/EventManagement/TofBuilder.h"
00005 using namespace std;
00006 
00007 TofBuilder::TofBuilder()
00008   :Builder()
00009 {
00010   // set vector size (2^14) and initialize to -1
00011   m_re2te = new uint32_t[16384];  // we have 2^14 different REID
00012   memset((void*)m_re2te, 0xFF, 16384*sizeof(uint32_t));
00013 
00014   initialize (Builder::m_confFile);
00015 }
00016 
00017 TofBuilder::~TofBuilder()
00018 {
00019    delete m_re2te;
00020 }
00021 
00022 void TofBuilder::unPack(uint32_t reDigi, uint32_t &REId, uint32_t &TEData,
00023                         uint32_t &overFlow, uint32_t &TorQ)
00024 {
00025    REId = (reDigi&m_idMask)>>m_idIndex;
00026    //cout << "TofBuilder::unPack reDigi: 0x" << hex << reDigi
00027    //     << "  reid: 0x" << reid << dec << endl;
00028 
00029    TEData = (reDigi&m_dataMask); 
00030    overFlow = (reDigi&m_overflowMask)>>m_overflowIndex;
00031    TorQ = (reDigi&m_TQMask)>>m_TQIndex; 
00032    //if (TorQ) TEData &= 0x1FFF;   // ADC 13 bits
00033    //cout << "reid" << hex << reid << endl;
00034    //cout << "teid" << hex << TEId << endl;
00035    return;
00036 }
00037 
00038 StatusCode TofBuilder::pack(TofDigiCol* digiCol, WriteRawEvent*& re)
00039 {
00040   if (digiCol == 0 ) {
00041     cerr << "TofBuilder::pack can't get digiCol" << endl;
00042     return StatusCode::FAILURE;
00043   }
00044 
00045   uint32_t size = 0;
00046   uint32_t teid = 0, tetdc = 0, teadc = 0, reid = 0, redigi = 0, overflow = 0;
00047 
00048   TofDigiCol::const_iterator pTofDigi = digiCol->begin();
00049   for (pTofDigi; pTofDigi!= digiCol->end(); pTofDigi++) {
00050     teid  = (*pTofDigi)->getIntId();
00051     if ( teid == 0xFFFFFFFF ) {
00052        m_buf[size++] = (*pTofDigi)->getOverflow();
00053        continue;
00054     }
00055     // check weither it's a valid teid (for a mistake in simulation)
00056     if ((teid&0x4001) == 1)  continue;
00057     reid  = getREID(teid);
00058     tetdc = (*pTofDigi)->getTimeChannel();
00059     teadc = (*pTofDigi)->getChargeChannel();
00060     // overflow
00061     uint32_t overflow_tmp = (*pTofDigi)->getOverflow();
00062     // set tdc
00063     if(tetdc!=0x7FFFFFFF){
00064       overflow = ((tetdc > m_dataMask) ? 1 : 0) | (overflow_tmp&1);
00065       redigi = (tetdc&m_dataMask)|
00066                ((reid<<m_idIndex)&m_idMask)|
00067                ((overflow<<m_overflowIndex)&m_overflowMask)|
00068                ((0<<m_TQIndex)&m_TQMask);
00069       m_buf[size++] = redigi;
00070     }
00071     // set adc
00072     if(teadc!=0x7FFFFFFF){
00073       overflow = ((teadc > m_dataMask) ? 1 : 0) | ((overflow_tmp>>1)&1);
00074       redigi = (teadc&m_dataMask)|
00075                ((reid<<m_idIndex)&m_idMask)|
00076                ((overflow<<m_overflowIndex)&m_overflowMask)|
00077                ((1<<m_TQIndex)&m_TQMask);
00078       m_buf[size++] = redigi;
00079     }
00080   }
00081 
00082   append2event(re, 0xa20000, size);
00083 
00084   return StatusCode::SUCCESS;
00085 }
00086 
00087 // initialize re2te tables
00088 
00089 StatusCode  TofBuilder::initialize(string& initFile)
00090 {
00091   ifstream f;
00092 
00093   uint32_t nRELayerPos, nRECellPos, nREEaWePos;
00094   uint32_t nRELayerMask, nRECellMask, nREEaWeMask;
00095 
00096   //-----------------------------------------------------------
00097   // read initFile
00098   f.open( initFile.c_str());
00099 
00100   if( f.bad() ) {
00101     cerr << "Error: could not open file " << initFile << endl;
00102     return false;
00103   }
00104 
00105   if (!Builder::find( f, "##TofDigiConf", initFile)) {
00106     cerr << "Error: could not find '##TofDigiConf' in file " << initFile << endl;
00107     return StatusCode::FAILURE;
00108   }
00109 
00110   if( !Builder::expect( f, "#Index,mask", initFile) ||  
00111       !Builder::expectInt( f, "id", initFile, m_idIndex, m_idMask) ||   
00112       !Builder::expectInt( f, "data", initFile, m_dataIndex, m_dataMask) ||   
00113       !Builder::expectInt( f, "Overflow", initFile, m_overflowIndex, m_overflowMask) ||   
00114       !Builder::expectInt( f, "T/Q", initFile, m_TQIndex, m_TQMask) ||   
00115       !Builder::expectInt( f, "Cell", initFile, nRECellPos, nRECellMask) ||  
00116       !Builder::expectInt( f, "Layer", initFile, nRELayerPos, nRELayerMask) ||
00117       !Builder::expectInt( f, "EaWe", initFile, nREEaWePos, nREEaWeMask) ) 
00118     return false; 
00119 
00120 
00121   f.close();
00122 
00123   //-----------------------------------------------------------
00124   //Build re2te table
00125   for(uint32_t  barrel_ec_eawe = TofID::getBARREL_EC_MIN();
00126       barrel_ec_eawe <= TofID::getBARREL_EC_MAX(); barrel_ec_eawe++)
00127   {
00128     uint32_t TELayerMax, TEphiMax, TEBaEaWe;
00129     uint32_t eawe = 0, layer = 0, cell = 0;
00130 
00131     if(barrel_ec_eawe == 1) {
00132       //it is BARREL
00133       TELayerMax = TofID::getLAYER_BARREL_MAX();
00134       TEphiMax = TofID::getPHI_BARREL_MAX();
00135     } else {
00136       //it is ease and west ENDCAP
00137       TELayerMax = TofID::getLAYER_ENDCAP_MAX();
00138       //zoujh: for luminosity !!! the right value should be 47
00139       TEphiMax = 48;  //TofID::getPHI_ENDCAP_MAX();
00140     }
00141 
00142     for(TEBaEaWe = 0; TEBaEaWe < 2; TEBaEaWe++) {
00143       if (barrel_ec_eawe != 1 && TEBaEaWe > 0) break;
00144       eawe = TEBaEaWe + (barrel_ec_eawe/2);
00145       for(uint32_t TELayer = 0; TELayer <= TELayerMax; TELayer++) {
00146         if (barrel_ec_eawe == 1) {
00147           layer = TELayer + 1;
00148         } else {
00149           //if (barrel_ec_eawe == TofID::getBARREL_EC_MIN()) layer = TELayer + 0;
00150           //else layer = TELayer + 3;
00151           layer = 3;
00152         }
00153         if (layer <= 3) {
00154           for (uint32_t TEphi = 0; TEphi <= TEphiMax; TEphi++) {
00155             cell = TEphi + 1;
00156             uint32_t reid = (((eawe<<nREEaWePos)&nREEaWeMask)|
00157                 ((layer<<nRELayerPos)&nRELayerMask)|
00158                 ((cell<<nRECellPos)&nRECellMask));
00159             uint32_t teid = TofID::getIntID(barrel_ec_eawe, TELayer, TEphi, TEBaEaWe);
00160             //std::cout << "reid " << reid << " eawe " << eawe << " layer " << layer << " cell " << cell
00161             //          << " teid " << hex << teid << dec << " barrel_ec_eawe " << barrel_ec_eawe  << " TELayer "
00162             //          << TELayer << " TEphi " << TEphi << " TEBaEaWe " << TEBaEaWe << std::endl;
00163             m_re2te[reid] = teid;
00164             m_te2reMap.insert(TE2REMAP::value_type(teid, reid)) ;
00165           }
00166         }
00167       }
00168     }
00169   }
00170 
00171   // return successful initialization
00172   return StatusCode::SUCCESS;
00173 }
00174 
00175  
00176 uint32_t TofBuilder::getREID(uint32_t teid)
00177 {
00178   TE2REMAP::iterator itr = m_te2reMap.find(teid);
00179 
00180   if (itr == m_te2reMap.end()) {
00181       cout << "wrong teid in tof" << teid << endl;
00182       exit(8);
00183   }
00184  
00185   return itr->second;
00186 }
00187 

Generated on Tue Nov 29 22:58:32 2016 for BOSS_7.0.2 by  doxygen 1.4.7