Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
#include "EventFilter/EcalRawToDigi/interface/DCCEETCCBlock.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "EventFilter/EcalRawToDigi/interface/EcalElectronicsMapper.h"
#include "EventFilter/EcalRawToDigi/interface/DCCDataUnpacker.h"

DCCEETCCBlock::DCCEETCCBlock(DCCDataUnpacker* u, EcalElectronicsMapper* m, DCCEventBlock* e, bool unpack)
    : DCCTCCBlock(u, m, e, unpack) {
  blockLength_ = 0;
}

void DCCEETCCBlock::updateCollectors() {
  tps_ = unpacker_->ecalTpsCollection();
  pss_ = unpacker_->ecalPSsCollection();
}

void DCCEETCCBlock::addTriggerPrimitivesToCollection() {
  //point to trigger data
  data_++;

  bool processTPG2(true);
  unsigned int psInputCounter(0);

  const uint16_t* tccP_ = reinterpret_cast<const uint16_t*>(data_);

  int dccFOV = event_->fov();
  if (!(dccFOV == dcc_FOV_0 || dccFOV == dcc_FOV_1 || dccFOV == dcc_FOV_2)) {
    if (!DCCDataUnpacker::silentMode_) {
      edm::LogWarning("IncorrectEvent") << "\n FOV value in data is: " << dccFOV << "At event: " << event_->l1A()
                                        << " with bx " << event_->bx() << " in fed <<" << mapper_->getActiveDCC()
                                        << "\n TCC id " << tccId_ << " FOV " << dccFOV
                                        << " which is not a foreseen value. Setting it to: " << dcc_FOV_2;
    }
    dccFOV = dcc_FOV_2;
  }

  /////////////////////////
  // MC raw data based on CMS NOTE 2005/021
  // (and raw data when FOV was unassigned, earlier than mid 2008)
  if (dccFOV == dcc_FOV_0) {
    // Unpack TPG1 pseudostrip input block
    if (ps_) {
      for (unsigned int i = 1; i <= NUMB_PSEUDOSTRIPS; i++, tccP_++, psInputCounter++) {
        pPS_ = mapper_->getPSInputDigiPointer(tccId_, psInputCounter);
        if (!pPS_)
          continue;
        pPS_->setSampleValue(0, *tccP_);
        (*pss_)->push_back(*pPS_);
      }
    }

    // Unpack TPG1 trigger primitive block
    // loop over tp_counter=i and navigate forward in raw (tccP_)
    for (unsigned int i = 1; i <= NUMB_TTS_TPG1; i++, tccP_++) {  //16

      if (i <= nTTs_) {
        pTP_ = mapper_->getTPPointer(tccId_, i);  // pointer to tp digi container
        if (pTP_)
          pTP_->setSample(0, *tccP_);  // fill it
      } else {
        processTPG2 = false;
        break;
      }
      // adding trigger primitive digi to the collection
      if (pTP_)
        (*tps_)->push_back(*pTP_);
      else
        edm::LogError("IncorrectBlock") << "trigger primitive digi was not aquired";
    }

    if (processTPG2) {
      // Unpack TPG2 pseudostrip input block
      if (ps_) {
        for (unsigned int i = 1; i <= NUMB_PSEUDOSTRIPS; i++, tccP_++, psInputCounter++) {
          if (i <= NUMB_TTS_TPG2_DUPL)
            continue;
          //fill pseudostrip container
          pPS_ = mapper_->getPSInputDigiPointer(tccId_, psInputCounter);
          if (!pPS_)
            continue;
          pPS_->setSampleValue(0, *tccP_);
          (*pss_)->push_back(*pPS_);
        }
      }

      // Unpack TPG2 trigger primitive block
      for (unsigned int i = 1; i <= NUMB_TTS_TPG2; i++, tccP_++) {  //12
        unsigned int tt = i + NUMB_TTS_TPG1;

        if (tt <= nTTs_) {
          pTP_ = mapper_->getTPPointer(tccId_, tt);
          if (pTP_)
            pTP_->setSample(0, *tccP_);
        } else
          break;
        // adding trigger primitive digi to the collection
        (*tps_)->push_back(*pTP_);
      }

    }  // end if(processTPG2)

  }  // end FOV==0

  ///////////////////////////
  // real data since ever FOV was initialized; only 2 used >= June 09
  else if (dccFOV == dcc_FOV_1 || dccFOV == dcc_FOV_2) {
    // Unpack TPG1 pseudostrip input block
    if (ps_) {
      for (unsigned int i = 1; i <= NUMB_PSEUDOSTRIPS; i++, tccP_++, psInputCounter++) {
        pPS_ = mapper_->getPSInputDigiPointer(tccId_, psInputCounter);
        if (!pPS_)
          continue;
        pPS_->setSampleValue(0, *tccP_);
        (*pss_)->push_back(*pPS_);
      }
    }

    int offset(0);
    // Unpack TPG1 trigger primitive block
    // loop over tp_counter=i and navigate forward in raw (tccP_)
    for (unsigned int i = 1; i <= NUMB_TTS_TPG1; i++, tccP_++) {  //16

      if (i <= nTTs_) {
        if (mapper_->isTCCExternal(tccId_)) {
          if (i > 8 && i <= 16)
            continue;  // skip blank tp's [9,16]
          if (i > 8)
            offset = 8;  //
          if (i > 24)
            continue;  // skip blank tp's [25, 28]
        }

        pTP_ = mapper_->getTPPointer(tccId_, i - offset);  // pointer to tp digi container
        if (pTP_)
          pTP_->setSample(0, *tccP_);  // fill it

      } else {
        processTPG2 = false;
        break;
      }
      // adding trigger primitive digi to the collection
      if (pTP_)
        (*tps_)->push_back(*pTP_);
      else
        edm::LogError("IncorrectBlock") << "trigger primitive digi was not aquired";
    }

    if (processTPG2) {
      // Unpack TPG2 pseudostrip input block
      if (ps_) {
        for (unsigned int i = 1; i <= NUMB_PSEUDOSTRIPS; i++, tccP_++, psInputCounter++) {
          if (i <= NUMB_TTS_TPG2_DUPL)
            continue;
          //fill pseudostrip container
          pPS_ = mapper_->getPSInputDigiPointer(tccId_, psInputCounter);
          if (!pPS_)
            continue;
          pPS_->setSampleValue(0, *tccP_);
          (*pss_)->push_back(*pPS_);
        }
      }

      // Unpack TPG2 trigger primitive block
      for (unsigned int i = 1; i <= NUMB_TTS_TPG2; i++, tccP_++) {  //12
        unsigned int tt = i + NUMB_TTS_TPG1;

        if (i <= nTTs_) {
          if (mapper_->isTCCExternal(tccId_)) {
            if (tt > 8 && tt <= 16)
              continue;  // skip blank tp's [9,16]
            if (tt > 8)
              offset = 8;  //
            if (tt > 24)
              continue;  // skip blank tp's [25, 28]
          }

          pTP_ = mapper_->getTPPointer(tccId_, tt - offset);
          if (pTP_)
            pTP_->setSample(0, *tccP_);
        } else
          break;
        // adding trigger primitive digi to the collection
        (*tps_)->push_back(*pTP_);
      }
    }  // end if(processTPG2)
  }  // end FOV==1 or 2
}

bool DCCEETCCBlock::checkTccIdAndNumbTTs() {
  bool tccFound(false);
  bool errorOnNumbOfTTs(false);
  const int activeDCC = mapper_->getActiveSM();
  std::vector<unsigned int>* m = mapper_->getTccs(activeDCC);
  std::vector<unsigned int>::iterator it;
  for (it = m->begin(); it != m->end(); it++) {
    if ((*it) == tccId_) {
      tccFound = true;

      /*
            expNumbTTs_= 28; //separate from inner and outer tcc 
            For inner TCCs you expect 28 TTs (4 in phi, 7 in eta).
            For outer TCCs you expect 16 TTs (4 in phi, 4 in eta).
            to implement : map tccid-> number of tts

            Pascal P.: For outer board, only 16 TPs are meaningful but 28 are sent.
            - [1,8] are meaningful 
            - [9,16] are empty ie should be skipped by unpacker 
            - [17, 24] are meaningful 
            - [25, 28] are empty ie should be skipped by unpacker 
          */

      if (nTTs_ != 28 && nTTs_ != 16) {
        if (!DCCDataUnpacker::silentMode_) {
          edm::LogWarning("IncorrectBlock")
              << "Error on event " << event_->l1A() << " with bx " << event_->bx() << " in fed <<"
              << mapper_->getActiveDCC() << "\n TCC id " << tccId_ << " has " << nTTs_
              << " Trigger Towers (only 28 or 16 are the expected values in EE)"
              << "\n => Skipping to next fed block...";
          errorOnNumbOfTTs = true;
          //todo : add to error collection
        }
      }
    }
  }

  if (!tccFound) {
    if (!DCCDataUnpacker::silentMode_) {
      edm::LogWarning("IncorrectBlock") << "Error on event " << event_->l1A() << " with bx " << event_->bx()
                                        << " in fed <<" << mapper_->getActiveDCC() << "\n TCC id " << tccId_
                                        << " is not valid for this dcc "
                                        << "\n => Skipping to next fed block...";
      //todo : add to error collection
    }
  }

  return (tccFound || errorOnNumbOfTTs);
}

unsigned int DCCEETCCBlock::getLength() {
  const uint64_t* temp = data_;
  temp++;

  ps_ = (*temp >> TCC_PS_B) & B_MASK;

  unsigned int numbTps = (NUMB_TTS_TPG1 + NUMB_TTS_TPG2);
  if (ps_) {
    numbTps += 2 * NUMB_PSEUDOSTRIPS;
  }

  unsigned int length = numbTps / 4 + 2;  //header and trailer
  if (numbTps % 4)
    length++;

  return length;
}