CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/L1Trigger/GlobalCaloTrigger/src/L1GctWheelEnergyFpga.cc

Go to the documentation of this file.
00001 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctWheelEnergyFpga.h"
00002 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctWheelJetFpga.h"
00003 
00004 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctJetLeafCard.h"
00005 
00006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00007 
00008 using std::vector;
00009 using std::ostream;
00010 using std::endl;
00011 
00012 //DEFINE STATICS
00013 const unsigned int L1GctWheelEnergyFpga::MAX_LEAF_CARDS = L1GctWheelJetFpga::MAX_LEAF_CARDS;
00014 
00015 L1GctWheelEnergyFpga::L1GctWheelEnergyFpga(int id, const std::vector<L1GctJetLeafCard*>& leafCards) :
00016   L1GctProcessor(),
00017   m_id(id),
00018   m_inputLeafCards(leafCards),
00019   m_inputEx(MAX_LEAF_CARDS),
00020   m_inputEy(MAX_LEAF_CARDS),
00021   m_inputEt(MAX_LEAF_CARDS),
00022   m_inputHt(MAX_LEAF_CARDS),
00023   m_outputEx(0), m_outputEy(0), m_outputEt(0), m_outputHt(0),
00024   m_setupOk(true),
00025   m_outputExPipe(), m_outputEyPipe(), m_outputEtPipe(), m_outputHtPipe()
00026 {
00027   //Check wheelEnergyFpga setup
00028   if(m_id != 0 && m_id != 1)
00029     {
00030       m_setupOk = false;
00031       if (m_verbose) {
00032         edm::LogWarning("L1GctSetupError")
00033           << "L1GctWheelEnergyFpga::L1GctWheelEnergyFpga() : Wheel Energy Fpga ID " << m_id << " has been incorrectly constructed!\n"
00034           << "ID number should be 0 or 1.\n";
00035       } 
00036     }
00037   
00038   if(m_inputLeafCards.size() != MAX_LEAF_CARDS)
00039     {
00040       m_setupOk = false;
00041       if (m_verbose) {
00042         edm::LogWarning("L1GctSetupError")
00043           << "L1GctWheelEnergyFpga::L1GctWheelEnergyFpga() : Wheel Energy Fpga ID " << m_id << " has been incorrectly constructed!\n"
00044           << "This class needs " << MAX_LEAF_CARDS << " leaf card pointers, yet only " << m_inputLeafCards.size()
00045           << " leaf card pointers are present.\n";
00046       }
00047     }
00048   
00049   for(unsigned int i = 0; i < m_inputLeafCards.size(); ++i)
00050     {
00051       if(m_inputLeafCards.at(i) == 0)
00052         {
00053           m_setupOk = false;
00054           if (m_verbose) {
00055             edm::LogWarning("L1GctSetupError")
00056               << "L1GctWheelEnergyFpga::L1GctWheelEnergyFpga() : Wheel Energy Fpga ID " << m_id << " has been incorrectly constructed!\n"
00057               << "Input Leaf card pointer " << i << " has not been set!\n";
00058           }
00059         }
00060     }
00061   if (!m_setupOk && m_verbose) {
00062     edm::LogError("L1GctSetupError") << "L1GctWheelEnergyFpga has been incorrectly constructed";
00063   }
00064 }
00065 
00066 L1GctWheelEnergyFpga::~L1GctWheelEnergyFpga()
00067 {
00068 }
00069 
00070 ostream& operator << (ostream& os, const L1GctWheelEnergyFpga& fpga)
00071 {
00072   os << "===L1GctWheelEnergyFPGA===" << endl;
00073   os << "ID : " << fpga.m_id << endl;
00074   os << "No. of Input Leaf Cards " << fpga.m_inputLeafCards.size() << endl;
00075   for(unsigned i=0; i < fpga.m_inputLeafCards.size(); i++)
00076     {
00077       os << "LeafCard* " << i << " = " << fpga.m_inputLeafCards.at(i) << endl;
00078     } 
00079   os << "Input Ex " << endl;
00080   for(unsigned i=0; i < fpga.m_inputEx.size(); i++)
00081     {
00082       os << fpga.m_inputEx.at(i) << endl;
00083     } 
00084   os << "Input Ey " << endl;
00085   for(unsigned i=0; i < fpga.m_inputEy.size(); i++)
00086     {
00087       os << fpga.m_inputEy.at(i) << endl;
00088     } 
00089   os << "Input Et " << endl;
00090   for(unsigned i=0; i < fpga.m_inputEt.size(); i++)
00091     {
00092       os << fpga.m_inputEt.at(i) << endl;
00093     } 
00094   os << "Input Ht " << endl;
00095   for(unsigned i=0; i < fpga.m_inputHt.size(); i++)
00096     {
00097       os << (fpga.m_inputHt.at(i)) << endl;
00098     } 
00099   os << "Output Ex " << fpga.m_outputEx << endl;
00100   os << "Output Ey " << fpga.m_outputEy << endl;
00101   os << "Output Et " << fpga.m_outputEt << endl;
00102   os << "Output Ht " << fpga.m_outputHt << endl;
00103   os << endl;
00104   return os;
00105 }
00106 
00107 void L1GctWheelEnergyFpga::resetProcessor()
00108 {
00109   for (unsigned int i=0; i<MAX_LEAF_CARDS; i++) {
00110     m_inputEx.at(i).reset();
00111     m_inputEy.at(i).reset();
00112     m_inputEt.at(i).reset();
00113     m_inputHt.at(i).reset();
00114   }
00115   m_outputEx.reset();
00116   m_outputEy.reset();
00117   m_outputEt.reset();
00118   m_outputHt.reset();
00119 }
00120 
00121 void L1GctWheelEnergyFpga::resetPipelines()
00122 {
00123   m_outputExPipe.reset(numOfBx());
00124   m_outputEyPipe.reset(numOfBx());
00125   m_outputEtPipe.reset(numOfBx());
00126   m_outputHtPipe.reset(numOfBx());
00127 }
00128 
00129 void L1GctWheelEnergyFpga::fetchInput()
00130 {
00131   if (m_setupOk) {
00132     // Fetch the output values from each of our input leaf cards.
00133     for (unsigned int i=0; i<MAX_LEAF_CARDS; i++) {
00134       m_inputEx.at(i) = m_inputLeafCards.at(i)->getOutputEx();
00135       m_inputEy.at(i) = m_inputLeafCards.at(i)->getOutputEy();
00136       m_inputEt.at(i) = m_inputLeafCards.at(i)->getOutputEt();
00137       m_inputHt.at(i) = m_inputLeafCards.at(i)->getOutputHt();
00138     }
00139   }
00140 }
00141 
00142 void L1GctWheelEnergyFpga::process()
00143 {
00144   if (m_setupOk) {
00145     m_outputEx = m_inputEx.at(0) + m_inputEx.at(1) + m_inputEx.at(2);
00146     m_outputEy = m_inputEy.at(0) + m_inputEy.at(1) + m_inputEy.at(2);
00147     m_outputEt = m_inputEt.at(0) + m_inputEt.at(1) + m_inputEt.at(2);
00148     m_outputHt = m_inputHt.at(0) + m_inputHt.at(1) + m_inputHt.at(2);
00149     if (m_outputEt.overFlow()) m_outputEt.setValue(etTotalMaxValue);
00150     if (m_outputHt.overFlow()) m_outputHt.setValue(htTotalMaxValue);
00151 
00152     m_outputExPipe.store( m_outputEx, bxRel());
00153     m_outputEyPipe.store( m_outputEy, bxRel());
00154     m_outputEtPipe.store( m_outputEt, bxRel());
00155     m_outputHtPipe.store( m_outputHt, bxRel());
00156   }
00157 }
00158 
00159 
00162 void L1GctWheelEnergyFpga::setInputEnergy(unsigned i, int ex, int ey, unsigned et, unsigned ht)
00163 {
00164   // Set the three input values from this Leaf card
00165   if (i<MAX_LEAF_CARDS) { // i >= 0, since i is unsigned
00166     m_inputEx.at(i).setValue(ex);
00167     m_inputEy.at(i).setValue(ey);
00168     m_inputEt.at(i).setValue(et);
00169     m_inputHt.at(i).setValue(ht);
00170   }
00171 
00172 }
00173 
00175 std::vector< L1GctInternEtSum  > L1GctWheelEnergyFpga::getInternalEtSums() const
00176 {
00177 
00178   std::vector< L1GctInternEtSum > result;
00179   for (int bx=0; bx<numOfBx(); bx++) {
00180     result.push_back( L1GctInternEtSum::fromEmulatorMissEtxOrEty( m_outputExPipe.contents.at(bx).value(),
00181                                                                   m_outputExPipe.contents.at(bx).overFlow(),
00182                                                                   static_cast<int16_t> (bx-bxMin()) ) );
00183     result.push_back( L1GctInternEtSum::fromEmulatorMissEtxOrEty( m_outputEyPipe.contents.at(bx).value(),
00184                                                                   m_outputEyPipe.contents.at(bx).overFlow(),
00185                                                                   static_cast<int16_t> (bx-bxMin()) ) );
00186     result.push_back( L1GctInternEtSum::fromEmulatorTotalEtOrHt( m_outputEtPipe.contents.at(bx).value(),
00187                                                                  m_outputEtPipe.contents.at(bx).overFlow(),
00188                                                                  static_cast<int16_t> (bx-bxMin()) ) );
00189     result.push_back( L1GctInternEtSum::fromEmulatorTotalEtOrHt( m_outputHtPipe.contents.at(bx).value(),
00190                                                                  m_outputHtPipe.contents.at(bx).overFlow(),
00191                                                                  static_cast<int16_t> (bx-bxMin()) ) );
00192   }
00193   return result;
00194 }