MdcBuilder Class Reference

#include <MdcBuilder.h>

Inheritance diagram for MdcBuilder:

Builder List of all members.

Public Types

typedef std::map< uint32_t,
uint32_t > 
TE2REMAP

Public Member Functions

 MdcBuilder ()
virtual ~MdcBuilder ()
virtual StatusCode initialize (string &initFile)
virtual uint32_t getTEID (uint32_t reid)
virtual uint32_t getREID (uint32_t teid)
virtual void unPack (uint32_t reDigi, uint32_t &REId, uint32_t &TEData, uint32_t &overFlow, uint32_t &TorQ)
virtual StatusCode pack (MdcDigiCol *digiCol, WriteRawEvent *&re)

Static Public Member Functions

static bool expect (ifstream &f, string msg, string fname)
static bool expectInt (ifstream &f, string msg, string fname, uint32_t &val1, uint32_t &val2)
static bool expectLong (ifstream &f, string msg, string fname, uint64_t &val)
static bool find (ifstream &f, string msg, string fname)

Protected Member Functions

void append2event (WriteRawEvent *&re, uint32_t source_id, uint32_t size)

Protected Attributes

uint32_t * m_buf
uint32_t m_status

Static Protected Attributes

static string m_confFile

Private Attributes

uint32_t m_idIndex
uint32_t m_idMask
uint32_t m_dataIndex
uint32_t m_dataMask
uint32_t m_overflowIndex
uint32_t m_overflowMask
uint32_t m_TQIndex
uint32_t m_TQMask
uint32_t * m_re2te
TE2REMAP m_te2reMap
PropertyMgr m_propMgr

Detailed Description

Definition at line 9 of file MdcBuilder.h.


Member Typedef Documentation

typedef std::map<uint32_t, uint32_t> Builder::TE2REMAP [inherited]

Definition at line 25 of file Builder.h.


Constructor & Destructor Documentation

MdcBuilder::MdcBuilder (  ) 

Definition at line 7 of file MdcBuilder.cxx.

References initialize(), Builder::m_confFile, and m_re2te.

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 }

MdcBuilder::~MdcBuilder (  )  [virtual]

Definition at line 17 of file MdcBuilder.cxx.

References m_re2te.

00018 {
00019    delete m_re2te;
00020 }


Member Function Documentation

void Builder::append2event ( WriteRawEvent *&  re,
uint32_t  source_id,
uint32_t  size 
) [protected, inherited]

Definition at line 76 of file Builder.cxx.

References eformat::write::FullEventFragment::append(), eformat::write::SubDetectorFragment::append(), eformat::write::ROSFragment::append(), eformat::write::FullEventFragment::lvl1_id(), Builder::m_buf, Builder::m_status, eformat::write::ROBFragment::rod_status(), eformat::write::FullEventFragment::run_no(), eformat::write::SubDetectorFragment::status(), eformat::write::ROSFragment::status(), and eformat::write::ROBFragment::status().

Referenced by TofBuilder::pack(), MucBuilder::pack(), pack(), McParticleBuilder::pack(), HltBuilder::pack(), and EmcBuilder::pack().

00077 {
00078   uint32_t run_no    = re->run_no();
00079   uint32_t lvl1_id   = re->lvl1_id();
00080   uint32_t bc_id     = 0;   // ?
00081   // ROB
00082   eformat::write::ROBFragment* nrob = new eformat::write::ROBFragment(
00083       source_id,      // source_id
00084       run_no,         // run_no
00085       lvl1_id,        // lvl1_id
00086       bc_id,          // bc_id
00087       0,              // lvl1_type
00088       0,              // detev_type
00089       size,           // ndata
00090       m_buf,          // data
00091       0               // status_position
00092       );
00093   if(m_status==0xFFFFFFFF){
00094     nrob->status(0, NULL);
00095     nrob->rod_status(0, NULL);
00096   }
00097   else{                     //fucd
00098     nrob->status(1, &m_status);
00099     nrob->rod_status(1, &m_status);
00100   }
00101   // ROS
00102   eformat::write::ROSFragment* nros = new eformat::write::ROSFragment(
00103       source_id,      // source_id
00104       run_no,         // run_no
00105       lvl1_id,        // lvl1_id
00106       bc_id           // bc_id
00107       );
00108   if(m_status==0xFFFFFFFF) nros->status(0, NULL);
00109   else        nros->status(1, &m_status);    //fucd
00110   // SubDetector
00111   eformat::write::SubDetectorFragment* nsd = new eformat::write::SubDetectorFragment(source_id);
00112   if(m_status==0xFFFFFFFF) nsd->status(0, NULL);
00113   else        nsd->status(1, &m_status);     //fucd
00114   // append to FullEventFragment
00115   nros->append(nrob);
00116   nsd->append(nros);
00117   re->append(nsd);
00118 }

bool Builder::expect ( ifstream f,
string  msg,
string  fname 
) [static, inherited]

Definition at line 28 of file Builder.cxx.

References deljobs::string.

Referenced by Builder::expectInt(), Builder::expectLong(), TofMcHitBuilder::initialize(), TofBuilder::initialize(), MucMcHitBuilder::initialize(), MdcMcHitBuilder::initialize(), initialize(), HltBuilder::initialize(), EmcMcHitBuilder::initialize(), and EmcBuilder::initialize().

00029 {
00030   string str;
00031   if( f.bad() ) 
00032   {
00033       cerr << "Error: file " << fname << " is bad" << endl;
00034       return false;
00035   }
00036   f >> str;
00037   if( str == msg )
00038     return true;
00039 
00040   cerr << "Error: expected `" << msg << "|" << str <<"` in " << fname << endl;
00041   return false;
00042 }

bool Builder::expectInt ( ifstream f,
string  msg,
string  fname,
uint32_t &  val1,
uint32_t &  val2 
) [static, inherited]

Definition at line 44 of file Builder.cxx.

References Builder::expect().

Referenced by TofMcHitBuilder::initialize(), TofBuilder::initialize(), MucMcHitBuilder::initialize(), MdcMcHitBuilder::initialize(), initialize(), HltBuilder::initialize(), EmcMcHitBuilder::initialize(), and EmcBuilder::initialize().

00045 {
00046   if( !expect( f, msg, fname ) || f.bad() )
00047     return false;
00048   f >> val1 >> val2;
00049   return true;
00050 }

bool Builder::expectLong ( ifstream f,
string  msg,
string  fname,
uint64_t &  val 
) [static, inherited]

Definition at line 52 of file Builder.cxx.

References Builder::expect().

Referenced by TofMcHitBuilder::initialize(), MucMcHitBuilder::initialize(), MdcMcHitBuilder::initialize(), and EmcMcHitBuilder::initialize().

00053 {
00054   if ( !expect(f, msg, fname) || f.bad() )
00055     return false;
00056   f >> val;
00057   return true;
00058 }

bool Builder::find ( ifstream f,
string  msg,
string  fname 
) [static, inherited]

Definition at line 60 of file Builder.cxx.

References deljobs::string.

Referenced by TofMcHitBuilder::initialize(), TofBuilder::initialize(), MucMcHitBuilder::initialize(), MdcMcHitBuilder::initialize(), initialize(), McParticleBuilder::initialize(), HltBuilder::initialize(), EmcMcHitBuilder::initialize(), and EmcBuilder::initialize().

00061 {
00062   if ( f.bad() ) {
00063     cerr << "Error: file " << fname << " bad checked" << endl;
00064     return false;
00065   }
00066 
00067   string str;
00068   while ( !f.eof() ) {
00069     f >> str;
00070     if ( str == msg ) return true;
00071   }
00072 
00073   return false;
00074 }

uint32_t MdcBuilder::getREID ( uint32_t  teid  )  [virtual]

Implements Builder.

Definition at line 194 of file MdcBuilder.cxx.

References m_te2reMap.

Referenced by pack().

00195 {
00196   TE2REMAP::iterator itr = m_te2reMap.find(teid);
00197  
00198   if (itr == m_te2reMap.end()) {
00199       cout << "wrong teid in mdc " << teid << endl;
00200       exit(8);
00201   }
00202 
00203   return itr->second;
00204 }

virtual uint32_t MdcBuilder::getTEID ( uint32_t  reid  )  [inline, virtual]

Implements Builder.

Definition at line 16 of file MdcBuilder.h.

References m_re2te.

Referenced by MdcConverter::convert().

00016 { return m_re2te[reid]; }

StatusCode MdcBuilder::initialize ( string initFile  )  [virtual]

Reimplemented from Builder.

Definition at line 99 of file MdcBuilder.cxx.

References Builder::expect(), Builder::expectInt(), Builder::find(), MdcID::getAXIAL_LAYER_MAX(), MdcID::getAXIAL_WIRE_MAX(), MdcID::getIntID(), MdcID::getSTEREO_LAYER_MAX(), genRecEmupikp::i, m_dataIndex, m_dataMask, m_idIndex, m_idMask, m_overflowIndex, m_overflowMask, m_re2te, m_te2reMap, m_TQIndex, m_TQMask, and dchain::value_type().

Referenced by MdcBuilder().

00100 {
00101   ifstream f;
00102 
00103   uint32_t NRELAYERPOS, NREWIREPOS, NREEAWEPOS;
00104   uint32_t NRELAYERMASK, NREWIREMASK, NREEAWEMASK;
00105 
00106   
00107   //-----------------------------------------------------------
00108   // read initFile
00109   f.open( initFile.c_str());
00110   
00111   if( f.bad() ) {
00112      cerr << "Error: could not open file " << initFile << endl;
00113      return false;
00114   }
00115 
00116   if (!Builder::find( f, "##MdcDigiConf", initFile)) {
00117     cerr << "Error: could not find '##MdcDigiConf' in file " << initFile << endl;
00118     return StatusCode::FAILURE;
00119   }
00120 
00121   if( !Builder::expect( f, "#Index,mask", initFile) ||
00122       !Builder::expectInt( f, "id", initFile, m_idIndex, m_idMask) ||
00123       !Builder::expectInt( f, "data", initFile, m_dataIndex, m_dataMask) ||
00124       !Builder::expectInt( f, "Overflow", initFile, m_overflowIndex, m_overflowMask) ||
00125       !Builder::expectInt( f, "T/Q", initFile, m_TQIndex, m_TQMask) ||
00126       !Builder::expectInt( f, "Wire", initFile, NREWIREPOS, NREWIREMASK) ||
00127       !Builder::expectInt( f, "Layer", initFile, NRELAYERPOS, NRELAYERMASK) )
00128     return false; 
00129   
00130   f.close();
00131   //-----------------------------------------------------------
00132   //Build re2te table
00133   uint32_t  nRELayerPos, nREWirePos, nREEaWePos;  
00134   uint32_t  nRELayerMask, nREWireMask, nREEaWeMask;  
00135 
00136 
00137   uint32_t TELayerMax = MdcID::getAXIAL_LAYER_MAX()+MdcID::getSTEREO_LAYER_MAX()+1;
00138   uint32_t TEWireMax = MdcID::getAXIAL_WIRE_MAX();
00139 
00140   int i = 0; 
00141 
00142   uint32_t layer, wire;
00143         
00144   nRELayerPos =  NRELAYERPOS;
00145   nREWirePos =  NREWIREPOS;
00146   nRELayerMask = NRELAYERMASK;
00147   nREWireMask = NREWIREMASK; 
00148 
00149   for(uint32_t  TELayer = 0; TELayer <= TELayerMax; TELayer++ )
00150   {
00151     layer = TELayer + 1;
00152     // After Layer 32, there are changes in positions of Layers and wires
00153     if(layer >= 0x20) {
00154       layer = layer + i ;
00155       i++;   
00156       nRELayerMask = nRELayerMask&0xFFFFFBFF;
00157       nREWireMask = nREWireMask|0x00000400;
00158       TEWireMax = MdcID::getAXIAL_WIRE_MAX();
00159     }
00160     else {
00161       //When Layer is less than 32, the number of wire is less than 240 to prevent overflow;
00162       TEWireMax = 240;
00163     } 
00164 
00165     for(uint32_t TEWire = 0; TEWire <= TEWireMax; TEWire++ )
00166     {
00167       wire = TEWire + 1;
00168       uint32_t reid = (((layer<<nRELayerPos)&nRELayerMask)|
00169           ((wire<<nREWirePos)&nREWireMask))>>2;
00170       //cout << "TELayer" << hex << TELayer;
00171       //cout << " TEWire" << hex << TEWire;
00172       //cout << " layer" << hex << layer;
00173       //cout << " wire" << hex << wire;
00174 
00175       uint32_t teid = MdcID::getIntID(TELayer, TEWire);
00176 
00177       if( reid >= 16384 )
00178       {
00179         cerr << "Error: REID overflow !" << reid << endl;
00180         exit(8);
00181       }
00182       //cout << " reid" << hex << reid;
00183       //cout << " teid" << hex << teid << endl;
00184       m_re2te[reid] = teid;
00185       m_te2reMap.insert(TE2REMAP::value_type(teid, reid)) ;
00186     }
00187   }
00188 
00189    // return successful initialization
00190    return StatusCode::SUCCESS;
00191 }

StatusCode MdcBuilder::pack ( MdcDigiCol digiCol,
WriteRawEvent *&  re 
) [virtual]

Definition at line 35 of file MdcBuilder.cxx.

References Builder::append2event(), MdcID::getIntID(), getREID(), MdcID::layer(), Builder::m_buf, m_dataMask, m_idIndex, m_idMask, m_overflowIndex, m_overflowMask, m_TQIndex, m_TQMask, delete_small_size::size, and MdcID::wire().

Referenced by MdcConverter::convert().

00036 {
00037   if (digiCol == 0 ) {
00038     cerr << "MdcBuilder::pack can't get digiCol" << endl;
00039     return StatusCode::FAILURE;
00040   }
00041 
00042   uint32_t size = 0;
00043   uint32_t teid = 0, tetdc = 0, teadc = 0, reid = 0, redigi = 0, overflow = 0;
00044 
00045   MdcDigiCol::const_iterator pMdcDigi = digiCol->begin();
00046   for (pMdcDigi; pMdcDigi!= digiCol->end(); pMdcDigi++) {
00047     //zoujh+++++++++++, be consistent with DAQ raw data
00048     Identifier id = (*pMdcDigi)->identify();
00049     int layer = MdcID::layer(id), wire = MdcID::wire(id);
00050     if ( layer == 20 && wire < 8 ) {
00051         layer = 42;
00052     }
00053     else if ( layer == 42 && wire < 8 ) {
00054         layer = 20;
00055     }
00056     else if ( layer == 40 ) {
00057         if ( wire >= 200 && wire < 208 ) {
00058             wire += 8;
00059         }
00060         else if ( wire >= 208 && wire < 216 ) {
00061             wire -= 8;
00062         }
00063     }
00064     //teid  = (*pMdcDigi)->getIntId();
00065     teid = MdcID::getIntID(layer, wire);
00066     //zoujh-----------
00067     reid  = getREID(teid);
00068     tetdc = (*pMdcDigi)->getTimeChannel();
00069     teadc = (*pMdcDigi)->getChargeChannel();
00070     // overflow
00071     uint32_t overflow_tmp = (*pMdcDigi)->getOverflow();
00072     // set tdc
00073     if(tetdc!=0x7FFFFFFF){
00074       overflow = ((tetdc > m_dataMask) ? 1 : 0) | (overflow_tmp&1);
00075       redigi = (tetdc&m_dataMask)|
00076                ((reid<<m_idIndex)&m_idMask)|
00077                ((overflow<<m_overflowIndex)&m_overflowMask)|
00078                ((0<<m_TQIndex)&m_TQMask);
00079       m_buf[size++] = redigi;
00080     }
00081     // set adc
00082     if(teadc!=0x7FFFFFFF){
00083       overflow = ((teadc > m_dataMask) ? 1 : 0) | ((overflow_tmp>>1)&1);
00084       redigi = (teadc&m_dataMask)|
00085                ((reid<<m_idIndex)&m_idMask)|
00086                ((overflow<<m_overflowIndex)&m_overflowMask)|
00087                ((1<<m_TQIndex)&m_TQMask);
00088       m_buf[size++] = redigi;
00089     }
00090   }
00091 
00092   append2event(re, 0xa10000, size);
00093 
00094   return StatusCode::SUCCESS;
00095 }

void MdcBuilder::unPack ( uint32_t  reDigi,
uint32_t &  REId,
uint32_t &  TEData,
uint32_t &  overFlow,
uint32_t &  TorQ 
) [virtual]

Definition at line 22 of file MdcBuilder.cxx.

References m_dataMask, m_idIndex, m_idMask, m_overflowIndex, m_overflowMask, m_TQIndex, and m_TQMask.

Referenced by MdcConverter::convert().

00024 {
00025    REId = (reDigi&m_idMask)>>m_idIndex;
00026    //cout << "MdcBuilder::unPack  reDigi: 0x" << hex << reDigi << "  reid: 0x" << reid << dec << endl;
00027    TEData = reDigi&m_dataMask;
00028    overFlow = (reDigi&m_overflowMask)>>m_overflowIndex;
00029    TorQ = (reDigi&m_TQMask)>>m_TQIndex;
00030    //cout << "reid" << hex << reid << endl;
00031    //cout << "teid" << hex << TEId << endl;
00032    return;
00033 }


Member Data Documentation

uint32_t* Builder::m_buf [protected, inherited]

Definition at line 46 of file Builder.h.

Referenced by Builder::append2event(), Builder::Builder(), TofBuilder::pack(), MucBuilder::pack(), pack(), McParticleBuilder::pack(), HltBuilder::pack(), EmcBuilder::pack(), and Builder::~Builder().

string Builder::m_confFile [static, protected, inherited]

Definition at line 47 of file Builder.h.

Referenced by Builder::Builder(), EmcBuilder::EmcBuilder(), EmcMcHitBuilder::EmcMcHitBuilder(), HltBuilder::HltBuilder(), MdcBuilder(), MdcMcHitBuilder::MdcMcHitBuilder(), MucMcHitBuilder::MucMcHitBuilder(), TofBuilder::TofBuilder(), and TofMcHitBuilder::TofMcHitBuilder().

uint32_t MdcBuilder::m_dataIndex [private]

Definition at line 26 of file MdcBuilder.h.

Referenced by initialize().

uint32_t MdcBuilder::m_dataMask [private]

Definition at line 27 of file MdcBuilder.h.

Referenced by initialize(), pack(), and unPack().

uint32_t MdcBuilder::m_idIndex [private]

Definition at line 24 of file MdcBuilder.h.

Referenced by initialize(), pack(), and unPack().

uint32_t MdcBuilder::m_idMask [private]

Definition at line 25 of file MdcBuilder.h.

Referenced by initialize(), pack(), and unPack().

uint32_t MdcBuilder::m_overflowIndex [private]

Definition at line 28 of file MdcBuilder.h.

Referenced by initialize(), pack(), and unPack().

uint32_t MdcBuilder::m_overflowMask [private]

Definition at line 29 of file MdcBuilder.h.

Referenced by initialize(), pack(), and unPack().

PropertyMgr MdcBuilder::m_propMgr [private]

Reimplemented from Builder.

Definition at line 36 of file MdcBuilder.h.

uint32_t* MdcBuilder::m_re2te [private]

Definition at line 33 of file MdcBuilder.h.

Referenced by getTEID(), initialize(), MdcBuilder(), and ~MdcBuilder().

uint32_t Builder::m_status [protected, inherited]

Definition at line 49 of file Builder.h.

Referenced by Builder::append2event(), and Builder::Builder().

TE2REMAP MdcBuilder::m_te2reMap [private]

Definition at line 34 of file MdcBuilder.h.

Referenced by getREID(), and initialize().

uint32_t MdcBuilder::m_TQIndex [private]

Definition at line 30 of file MdcBuilder.h.

Referenced by initialize(), pack(), and unPack().

uint32_t MdcBuilder::m_TQMask [private]

Definition at line 31 of file MdcBuilder.h.

Referenced by initialize(), pack(), and unPack().


Generated on Tue Nov 29 23:20:08 2016 for BOSS_7.0.2 by  doxygen 1.4.7