CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/DataFormats/HcalDigi/src/HcalTTPDigi.cc

Go to the documentation of this file.
00001 #include "DataFormats/HcalDigi/interface/HcalTTPDigi.h"
00002 
00003 HcalTTPDigi::HcalTTPDigi() : identifier_(0), samples_(0), presamples_(0), fwVersion_(0), algorithm_(0), lPipe_(0) {
00004     for (int i=0; i<8; i++) {
00005         algoDepend_[i] = 0 ; triggerOutput_[i] = 0 ;
00006         for (int j=0; j<5; j++) triggerInputs_[j*8+i] = 0 ;
00007     }
00008 }
00009 
00010 HcalTTPDigi::HcalTTPDigi(int identifier, int samples, int presamples,
00011                          unsigned int fwVersion, int algorithm, unsigned int lPipe) :
00012     identifier_(identifier),
00013     samples_(samples),
00014     presamples_(presamples),
00015     fwVersion_(fwVersion),
00016     algorithm_(algorithm),
00017     lPipe_(lPipe) {
00018     for (int i=0; i<8; i++) {
00019         algoDepend_[i] = 0x0 ; triggerOutput_[i] = 0x0 ;
00020         for (int j=0; j<5; j++) triggerInputs_[i*5+j] = 0x0 ;
00021     }
00022 }
00023 
00024 void HcalTTPDigi::setSample(int relativeSample,
00025                             const uint16_t* triggerInputs,
00026                             const uint32_t algodep,
00027                             const uint8_t outputTrigger) {
00028 
00029     int linSample=presamples_+relativeSample;
00030     if (linSample>=0 && linSample<samples_) {
00031         // Trigger input: 72 bits
00032         for (int i=0; i<4; i++)
00033             triggerInputs_[5*linSample+i] = triggerInputs[i] ;
00034         triggerInputs_[5*linSample+4] = triggerInputs[4]&0xFF ;
00035         // Algo dependency: 20 bits
00036         algoDepend_[linSample] = algodep&0xFFFFF ;
00037         // Trigger output: 4 bits
00038         triggerOutput_[linSample] = outputTrigger&0xF ;        
00039     }
00040 }
00041 
00042 std::vector<bool> HcalTTPDigi::inputPattern(int relativeSample) const {
00043   std::vector<bool> retval;
00044   int linSample=presamples_+relativeSample;
00045   if (linSample>=0 && linSample<samples_) {
00046     
00047     for (int i=0; i<72; i++) {
00048       int ioff=i/16;
00049       retval.push_back(triggerInputs_[linSample*5+ioff]&(1<<(i%16)));
00050     }
00051   }
00052   return retval ; 
00053 }
00054 
00055 uint8_t HcalTTPDigi::triggerOutput(int relativeSample) const {
00056   int linSample=presamples_+relativeSample;
00057   if (linSample>=0 && linSample<samples_) return triggerOutput_[linSample];
00058   else return 0;
00059 }
00060 
00061 uint32_t HcalTTPDigi::algorithmWord(int relativeSample) const {
00062   int linSample=presamples_+relativeSample;
00063   if (linSample>=0 && linSample<samples_) return algoDepend_[linSample];
00064   else return 0;
00065 }
00066 
00067 bool HcalTTPDigi::operator==(const HcalTTPDigi& digi) const {
00068 
00069     if (samples_ != digi.size() || presamples_ != digi.presamples()) return false ;
00070     int relativeSize = digi.size() - digi.presamples() ; 
00071     for (int i=-this->presamples(); i<relativeSize; i++) {
00072         if (this->inputPattern(i) != digi.inputPattern(i)) return false ; 
00073         if (this->algorithmWord(i) != digi.algorithmWord(i)) return false ; 
00074         if (this->triggerOutput(i) != digi.triggerOutput(i)) return false ; 
00075     }
00076     return true ;
00077 }
00078 
00079 std::ostream& operator<<(std::ostream& out, const HcalTTPDigi& digi) {
00080 
00081     out << "HcalTTPDigi " << digi.id() 
00082         << " with " << digi.size() << " samples, "
00083         << digi.presamples() << " presamples. "
00084         << std::endl ;
00085     out << "Firmware version " << digi.fwVersion() << " and flavor/algo " << digi.algorithm() ; 
00086     out << "; pipeline length " << digi.pipelineLength() << std::endl ;  
00087     int relativeSize = digi.size() - digi.presamples() ; 
00088     for (int i=-digi.presamples(); i<relativeSize; i++) {
00089         for (unsigned int j=digi.inputPattern(i).size(); j>0; j--) {
00090             if ( !(j%16) ) out << " " ;
00091             out << digi.inputPattern(i).at(j-1) ;
00092         }
00093         if (i < 0) out << " (PRE)" ; // Indicates presamples 
00094         out << std::endl ; 
00095         out << "ALGO: " ; 
00096         for (int j=19; j>=0; j--) out << bool((digi.algorithmWord(i))&(1<<j)) ;
00097 
00098         out << "  TRIG: " ;
00099         for (int j=3; j>=0; j--) out << bool((digi.triggerOutput(i))&(1<<j)) ; 
00100         out << std::endl ; 
00101     }
00102 
00103     return out ; 
00104 }
00105