#include <EventFilter/GctRawToDigi/src/GctRawToDigi.cc>
Public Member Functions | |
GctRawToDigi (const edm::ParameterSet &) | |
~GctRawToDigi () | |
Private Member Functions | |
void | addError (const unsigned code) |
bool | autoDetectRequiredFormatTranslator (const unsigned char *data) |
Looks at the firmware version header in the S-Link packet and instantiates relevant format translator. | |
virtual void | beginJob () |
void | checkHeaders () |
check block headers for consistency | |
void | doVerboseOutput (const GctBlockHeaderCollection &bHdrs, const GctUnpackCollections *const colls) const |
Prints out a list of blocks and the various numbers of trigger objects that have been unpacked from them. | |
virtual void | endJob () |
method called at job end - use to print summary report | |
virtual void | produce (edm::Event &, const edm::EventSetup &) |
void | unpack (const FEDRawData &d, edm::Event &e, GctUnpackCollections *const colls) |
Unpacks the raw data. | |
Private Attributes | |
GctBlockHeaderCollection | blockHeaders_ |
const bool | checkHeaders_ |
If true, check block headers for synchronisation. | |
std::vector< unsigned > | errorCounters_ |
Counts number of errors for each code (index) | |
L1TriggerErrorCollection * | errors_ |
pointer to error collection | |
int | fedId_ |
GCT FED ID. | |
GctFormatTranslateBase * | formatTranslator_ |
pointer to the block-to-digi converter | |
const unsigned | formatVersion_ |
Defines unpacker verison to be used (e.g.: "Auto-detect", "MCLegacy", "V35", etc). | |
const bool | hltMode_ |
If true, only outputs the GCT data sent to the GT (number of BXs defined by numberOfGctSamplesToUnpack_) | |
edm::InputTag | inputLabel_ |
FED collection label. | |
const unsigned | numberOfGctSamplesToUnpack_ |
Number of BXs of GCT data to unpack (assuming they are in the raw data) | |
const unsigned | numberOfRctSamplesToUnpack_ |
Number of BXs of RCT data to unpack (assuming they are in the raw data) | |
unsigned | unpackFailures_ |
To count the total number of GCT unpack failures. | |
const bool | unpackSharedRegions_ |
Commissioning option: if true, where applicable the shared RCT calo regions will also be unpacked. | |
const bool | verbose_ |
If true, then debug print out for each event. | |
Static Private Attributes | |
static const unsigned | MAX_BLOCKS = 256 |
The maximum number of blocks we will try to unpack before thinking something is wrong. | |
static const unsigned | MAX_ERR_CODE = 6 |
Description: Produce GCT digis from raw data
Implementation: <Notes on="" implementation>="">
Definition at line 45 of file GctRawToDigi.h.
GctRawToDigi::GctRawToDigi | ( | const edm::ParameterSet & | iConfig | ) | [explicit] |
Register Products
Definition at line 34 of file GctRawToDigi.cc.
References fedId_, formatTranslator_, formatVersion_, hltMode_, LogDebug, numberOfGctSamplesToUnpack_, numberOfRctSamplesToUnpack_, and unpackSharedRegions_.
: inputLabel_(iConfig.getParameter<edm::InputTag>("inputLabel")), fedId_(iConfig.getUntrackedParameter<int>("gctFedId", FEDNumbering::MINTriggerGCTFEDID)), hltMode_(iConfig.getParameter<bool>("hltMode")), numberOfGctSamplesToUnpack_(iConfig.getParameter<unsigned>("numberOfGctSamplesToUnpack")), numberOfRctSamplesToUnpack_(iConfig.getParameter<unsigned>("numberOfRctSamplesToUnpack")), unpackSharedRegions_(iConfig.getParameter<bool>("unpackSharedRegions")), formatVersion_(iConfig.getParameter<unsigned>("unpackerVersion")), checkHeaders_(iConfig.getUntrackedParameter<bool>("checkHeaders",false)), verbose_(iConfig.getUntrackedParameter<bool>("verbose",false)), formatTranslator_(0), errors_(0), errorCounters_(MAX_ERR_CODE+1), // initialise with the maximum error codes! unpackFailures_(0) { LogDebug("GCT") << "GctRawToDigi will unpack FED Id " << fedId_; // If the GctFormatTranslate version has been forced from config file, instantiate the relevant one. /*** THIS OBVIOUSLY STINKS - NEED TO REPLACE WITH SOMETHING BETTER THAN MASSIVE IF-ELSE SOON ***/ /*** WHEN THIS MESS IS REMOVED REMEMBER THAT THE V38 FORMAT TRANSLATE HAS A DIFERENT CTOR TO THE OTHERS ***/ if(formatVersion_ == 0) { edm::LogInfo("GCT") << "The required GCT Format Translator will be automatically determined from the first S-Link packet header."; } else if(formatVersion_ == 1) { edm::LogInfo("GCT") << "You have selected to use GctFormatTranslateMCLegacy"; formatTranslator_ = new GctFormatTranslateMCLegacy(hltMode_, unpackSharedRegions_); } else if(formatVersion_ == 2) { edm::LogInfo("GCT") << "You have selected to use GctFormatTranslateV35"; formatTranslator_ = new GctFormatTranslateV35(hltMode_, unpackSharedRegions_); } else if(formatVersion_ == 3) { edm::LogInfo("GCT") << "You have selected to use GctFormatTranslateV38"; formatTranslator_ = new GctFormatTranslateV38(hltMode_, unpackSharedRegions_, numberOfGctSamplesToUnpack_, numberOfRctSamplesToUnpack_); } else { edm::LogWarning("GCT") << "You have requested a version of GctFormatTranslate that does not exist! Will attempt to auto-detect " "the required GCT Format Translator from the first S-Link packet header instead."; } if(hltMode_) { edm::LogInfo("GCT") << "HLT unpack mode selected: HLT unpack optimisations will be used."; } if(unpackSharedRegions_) { edm::LogInfo("GCT") << "You have selected to unpack shared RCT calo regions - be warned: " "this is for commissioning purposes only!"; } // GCT input collections produces<L1GctFibreCollection>(); produces<L1CaloEmCollection>(); produces<L1CaloRegionCollection>(); // GCT internal collections produces<L1GctInternEmCandCollection>(); produces<L1GctInternJetDataCollection>(); produces<L1GctInternEtSumCollection>(); produces<L1GctInternHFDataCollection>(); produces<L1GctInternHtMissCollection>(); // GCT output collections produces<L1GctEmCandCollection>("isoEm"); produces<L1GctEmCandCollection>("nonIsoEm"); produces<L1GctJetCandCollection>("cenJets"); produces<L1GctJetCandCollection>("forJets"); produces<L1GctJetCandCollection>("tauJets"); produces<L1GctHFBitCountsCollection>(); produces<L1GctHFRingEtSumsCollection>(); produces<L1GctEtTotalCollection>(); produces<L1GctEtHadCollection>(); produces<L1GctEtMissCollection>(); produces<L1GctHtMissCollection>(); produces<L1GctJetCountsCollection>(); // Deprecated (empty collection still needed by GT) // Error collection produces<L1TriggerErrorCollection>(); }
GctRawToDigi::~GctRawToDigi | ( | ) |
Definition at line 112 of file GctRawToDigi.cc.
References formatTranslator_.
{ // do anything here that needs to be done at destruction time // (e.g. close files, deallocate resources etc.) delete formatTranslator_; }
void GctRawToDigi::addError | ( | const unsigned | code | ) | [private] |
Definition at line 292 of file GctRawToDigi.cc.
References errorCounters_, errors_, fedId_, and MAX_ERR_CODE.
Referenced by autoDetectRequiredFormatTranslator(), produce(), and unpack().
{ // check this isn't going to break error handling if (code > MAX_ERR_CODE) { edm::LogError("GCT") << "Unknown error code : " << code; return; } // print message on first instance of this error if (errorCounters_.at(code) == 0) { std::ostringstream os; if (code == 1) os << "FED record empty or too short"; else if (code == 2) os << "Unknown raw data version"; else if (code == 3) os << "Detected unknown firmware version"; else if (code == 4) os << "Detected unknown data block"; else if (code == 5) os << "Block headers out of sync"; else if (code == 5) os << "Too many blocks"; edm::LogError("GCT") << "Unpacking error " << code << " : " << os.str(); } // increment error counter ++(errorCounters_.at(code)); // store error in event if possible if (errors_ != 0) { errors_->push_back(L1TriggerError(fedId_, code)); } else edm::LogError("GCT") << "Detected error (code=" << code << ") but no error collection available!"; }
bool GctRawToDigi::autoDetectRequiredFormatTranslator | ( | const unsigned char * | data | ) | [private] |
Looks at the firmware version header in the S-Link packet and instantiates relevant format translator.
Returns false if it fails to instantiate a Format Translator
Definition at line 229 of file GctRawToDigi.cc.
References addError(), formatTranslator_, hltMode_, LogDebug, numberOfGctSamplesToUnpack_, numberOfRctSamplesToUnpack_, and unpackSharedRegions_.
Referenced by produce().
{ LogDebug("GCT") << "About to auto-detect the required format translator from the firmware version header."; const uint32_t * p32 = reinterpret_cast<const uint32_t *>(d); unsigned firmwareHeader = p32[2]; /*** THIS OBVIOUSLY STINKS - NEED TO REPLACE WITH SOMETHING BETTER THAN MASSIVE IF-ELSE SOON ***/ /*** WHEN THIS MESS IS REMOVED REMEMBER THAT THE V38 FORMAT TRANSLATE HAS A DIFERENT CTOR TO THE OTHERS ***/ if( firmwareHeader >= 25 && firmwareHeader <= 35 ) { edm::LogInfo("GCT") << "Firmware Version V" << firmwareHeader << " detected: GctFormatTranslateV" << firmwareHeader << " will be used to unpack."; formatTranslator_ = new GctFormatTranslateV35(hltMode_, unpackSharedRegions_); return true; } else if( firmwareHeader == 38 ) { edm::LogInfo("GCT") << "Firmware Version V" << firmwareHeader << " detected: GctFormatTranslateV" << firmwareHeader << " will be used to unpack."; formatTranslator_ = new GctFormatTranslateV38(hltMode_, unpackSharedRegions_, numberOfGctSamplesToUnpack_, numberOfRctSamplesToUnpack_); return true; } else if( firmwareHeader == 0x00000000 ) { edm::LogInfo("GCT") << "Legacy Monte-Carlo data detected: GctFormatTranslateMCLegacy will be used to unpack."; formatTranslator_ = new GctFormatTranslateMCLegacy(hltMode_, unpackSharedRegions_); return true; } // these lines comments otherwise error is not reported!!! // else if(firmwareHeader == 0xdeadffff) { /* Driver detected unknown firmware version. L1TriggerError code? */ } // else if( firmwareHeader == 0xaaaaaaaa) { /* Before driver firmware version checks implemented. L1TriggerError code? */ } else { /* Totally unknown firmware header */ LogDebug("GCT") << "Failed to determine unpacker to use from the firmware version header! " "(firmware header = 0x" << hex << firmwareHeader << dec << ")"; addError(2); return false; } }
void GctRawToDigi::beginJob | ( | void | ) | [private, virtual] |
void GctRawToDigi::checkHeaders | ( | ) | [private] |
check block headers for consistency
Definition at line 271 of file GctRawToDigi.cc.
Referenced by produce().
{
// TODO : loop over block headers found this event and check for consistency
}
void GctRawToDigi::doVerboseOutput | ( | const GctBlockHeaderCollection & | bHdrs, |
const GctUnpackCollections *const | colls | ||
) | const [private] |
Prints out a list of blocks and the various numbers of trigger objects that have been unpacked from them.
Definition at line 278 of file GctRawToDigi.cc.
References formatTranslator_, GctFormatTranslateBase::getBlockDescription(), i, and findQualityFiles::size.
Referenced by produce().
{ std::ostringstream os; os << "Found " << bHdrs.size() << " GCT block headers" << endl; for (unsigned i=0, size = bHdrs.size(); i < size; ++i) { os << "GCT Raw Data Block : " << formatTranslator_->getBlockDescription(bHdrs[i]) << " : " << bHdrs[i] << endl; } os << *colls << endl; edm::LogVerbatim("GCT") << os.str(); }
void GctRawToDigi::endJob | ( | void | ) | [private, virtual] |
method called at job end - use to print summary report
Reimplemented from edm::EDProducer.
Definition at line 324 of file GctRawToDigi.cc.
References errorCounters_, i, MAX_ERR_CODE, and pileupDistInMC::total.
{ unsigned total=0; std::ostringstream os; for (unsigned i=0; i<MAX_ERR_CODE+1; ++i) { total+=errorCounters_.at(i); os << "Error " << i << " (" << errorCounters_.at(i) << ")"; } if (total>0) { edm::LogError("GCT") << "Encountered " << total << " unpacking errors. " << os; } }
void GctRawToDigi::produce | ( | edm::Event & | iEvent, |
const edm::EventSetup & | iSetup | ||
) | [private, virtual] |
Implements edm::EDProducer.
Definition at line 131 of file GctRawToDigi.cc.
References addError(), autoDetectRequiredFormatTranslator(), blockHeaders_, checkHeaders(), checkHeaders_, FEDRawData::data(), doVerboseOutput(), errors_, fedId_, formatTranslator_, edm::Event::get(), edm::Event::getByLabel(), inputLabel_, LogDebug, FEDRawData::size(), unpack(), and verbose_.
{ using namespace edm; // Instantiate all the collections the unpacker needs; puts them in event when this object goes out of scope. std::auto_ptr<GctUnpackCollections> colls(new GctUnpackCollections(iEvent)); errors_ = colls->errors(); // get raw data collection edm::Handle<FEDRawDataCollection> feds; iEvent.getByLabel(inputLabel_, feds); // if raw data collection is present, do the unpacking if (feds.isValid()) { const FEDRawData& gctRcd = feds->FEDData(fedId_); LogDebug("GCT") << "Upacking FEDRawData of size " << std::dec << gctRcd.size(); // check for empty events if(gctRcd.size() < 16) { LogDebug("GCT") << "Cannot unpack: empty/invalid GCT raw data (size = " << gctRcd.size() << "). Returning empty collections!"; addError(1); return; } // If no format translator yet set, need to auto-detect from header. // If auto format detection fails, we have no concrete format // translator instantiated... set error and bail if(!formatTranslator_) { if(!autoDetectRequiredFormatTranslator(gctRcd.data())) return; } // reset collection of block headers blockHeaders_.clear(); // do the unpacking unpack(gctRcd, iEvent, colls.get()); // check headers, if enabled if (checkHeaders_) checkHeaders(); // dump summary in verbose mode if(verbose_) { doVerboseOutput(blockHeaders_, colls.get()); } } }
void GctRawToDigi::unpack | ( | const FEDRawData & | d, |
edm::Event & | e, | ||
GctUnpackCollections *const | colls | ||
) | [private] |
Unpacks the raw data.
invalidDataFlag | - if true, then won't attempt unpack but just output empty collecions. |
Definition at line 182 of file GctRawToDigi.cc.
References addError(), blockHeaders_, GctBlockHeader::blockLength(), checkHeaders_, GctFormatTranslateBase::convertBlock(), FEDRawData::data(), runTheMatrix::data, formatTranslator_, GctFormatTranslateBase::generateBlockHeader(), LogDebug, MAX_BLOCKS, GctBlockHeader::nSamples(), GctFormatTranslateBase::setUnpackCollections(), FEDRawData::size(), and verbose_.
Referenced by produce().
{ // We should now have a valid formatTranslator pointer formatTranslator_->setUnpackCollections(colls); const unsigned char * data = d.data(); // The 8-bit wide raw-data array. // Data offset - starts at 16 as there is a 64-bit S-Link header followed // by a 64-bit software-controlled header (for pipeline format version // info that is not yet used). unsigned dPtr = 16; const unsigned dEnd = d.size() - 8; // End of payload is at (packet size - final slink header) // read blocks for (unsigned nb=0; dPtr<dEnd; ++nb) { if(nb >= MAX_BLOCKS) { LogDebug("GCT") << "Reached block limit - bailing out from this event!"; addError(6); break; } // read block header GctBlockHeader blockHeader = formatTranslator_->generateBlockHeader(&data[dPtr]); // unpack the block; dPtr+4 is to get to the block data. if(!formatTranslator_->convertBlock(&data[dPtr+4], blockHeader)) // Record if we had an unpack problem then skip rest of event. { LogDebug("GCT") << "Encountered block unpack error - bailing out from this event!"; addError(4); break; } // advance pointer dPtr += 4*(blockHeader.blockLength()*blockHeader.nSamples()+1); // *4 because blockLen is in 32-bit words, +1 for header // if verbose or checking block headers, store the header if (verbose_ || checkHeaders_) blockHeaders_.push_back(blockHeader); } }
Definition at line 100 of file GctRawToDigi.h.
const bool GctRawToDigi::checkHeaders_ [private] |
If true, check block headers for synchronisation.
Definition at line 93 of file GctRawToDigi.h.
std::vector<unsigned> GctRawToDigi::errorCounters_ [private] |
Counts number of errors for each code (index)
Definition at line 105 of file GctRawToDigi.h.
Referenced by addError(), and endJob().
L1TriggerErrorCollection* GctRawToDigi::errors_ [private] |
pointer to error collection
Definition at line 104 of file GctRawToDigi.h.
Referenced by addError(), and produce().
int GctRawToDigi::fedId_ [private] |
GCT FED ID.
Definition at line 86 of file GctRawToDigi.h.
Referenced by addError(), GctRawToDigi(), and produce().
pointer to the block-to-digi converter
Definition at line 97 of file GctRawToDigi.h.
Referenced by autoDetectRequiredFormatTranslator(), doVerboseOutput(), GctRawToDigi(), produce(), unpack(), and ~GctRawToDigi().
const unsigned GctRawToDigi::formatVersion_ [private] |
Defines unpacker verison to be used (e.g.: "Auto-detect", "MCLegacy", "V35", etc).
Definition at line 92 of file GctRawToDigi.h.
Referenced by GctRawToDigi().
const bool GctRawToDigi::hltMode_ [private] |
If true, only outputs the GCT data sent to the GT (number of BXs defined by numberOfGctSamplesToUnpack_)
Definition at line 88 of file GctRawToDigi.h.
Referenced by autoDetectRequiredFormatTranslator(), and GctRawToDigi().
edm::InputTag GctRawToDigi::inputLabel_ [private] |
const unsigned GctRawToDigi::MAX_BLOCKS = 256 [static, private] |
The maximum number of blocks we will try to unpack before thinking something is wrong.
Definition at line 82 of file GctRawToDigi.h.
Referenced by unpack().
const unsigned GctRawToDigi::MAX_ERR_CODE = 6 [static, private] |
Definition at line 103 of file GctRawToDigi.h.
Referenced by addError(), and endJob().
const unsigned GctRawToDigi::numberOfGctSamplesToUnpack_ [private] |
Number of BXs of GCT data to unpack (assuming they are in the raw data)
Definition at line 89 of file GctRawToDigi.h.
Referenced by autoDetectRequiredFormatTranslator(), and GctRawToDigi().
const unsigned GctRawToDigi::numberOfRctSamplesToUnpack_ [private] |
Number of BXs of RCT data to unpack (assuming they are in the raw data)
Definition at line 90 of file GctRawToDigi.h.
Referenced by autoDetectRequiredFormatTranslator(), and GctRawToDigi().
unsigned GctRawToDigi::unpackFailures_ [private] |
To count the total number of GCT unpack failures.
Definition at line 106 of file GctRawToDigi.h.
const bool GctRawToDigi::unpackSharedRegions_ [private] |
Commissioning option: if true, where applicable the shared RCT calo regions will also be unpacked.
Definition at line 91 of file GctRawToDigi.h.
Referenced by autoDetectRequiredFormatTranslator(), and GctRawToDigi().
const bool GctRawToDigi::verbose_ [private] |
If true, then debug print out for each event.
Definition at line 94 of file GctRawToDigi.h.