Skip to content

Commit

Permalink
Merge pull request #5433 from smorovic/tcds-readout-71X
Browse files Browse the repository at this point in the history
TCDS readout for 7_1_X
  • Loading branch information
davidlange6 committed Sep 19, 2014
2 parents bfc7c4d + dc145a7 commit 01b7144
Show file tree
Hide file tree
Showing 11 changed files with 384 additions and 26 deletions.
1 change: 1 addition & 0 deletions EventFilter/FEDInterface/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<export>
<use name="DataFormats/FEDRawData"/>
<lib name="1"/>
</export>
139 changes: 139 additions & 0 deletions EventFilter/FEDInterface/interface/FED1024.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
#ifndef EVF_FEDINTERFACE_FED1024_H
#define EVF_FEDINTERFACE_FED1024_H


#include <stddef.h>
#include "EventFilter/FEDInterface/interface/fed_header.h"
#include "EventFilter/FEDInterface/interface/FEDConstants.h"

namespace evf{
namespace evtn{

union sizes{
uint64_t sizeword;
struct{
const unsigned char headerSize;
const unsigned char summarySize;
const unsigned char L1AhistSize;
const unsigned char BSTSize;
const unsigned char reserved0;
const unsigned char reserved1;
const unsigned char reserved2;
const unsigned char BGOSize;
} size;
};

class TCDSHeader{
public:

union tcdsheader{
uint64_t words[11];
struct {
uint64_t macAddress;
uint32_t sw;
uint32_t fw;
uint32_t reserved0;
uint32_t format;
uint32_t runNumber;
uint32_t reserved1;
uint32_t activePartitions2;
uint32_t reserved2;
uint32_t activePartitions0;
uint32_t activePartitions1;
uint32_t nibble;
uint32_t lumiSection;
uint16_t reserved3;
uint16_t reserved4;
uint16_t reserved5;
uint16_t inputs;
uint16_t bcid;
uint16_t orbitLow;
uint32_t orbitHigh;
uint64_t triggerCount;
uint64_t eventNumber;
} header;
};

TCDSHeader(const unsigned char *p) :
s((sizes*)p),
h((tcdsheader*)(p+sizeof(uint64_t)))
{

}
const sizes &getSizes(){return *s;}
const tcdsheader &getData(){return *h;}
private:
sizes *s;
tcdsheader *h;
};
class TCDSL1AHistory{
public:
struct l1a{
uint16_t bxid;
uint16_t dummy0;
uint16_t dummy1;
unsigned char ind0;
uint32_t orbitlow;
uint16_t orbithigh;
unsigned char eventtype;
unsigned char ind1;
};
union l1h{
uint64_t words[32];
l1a hist[32];
};
TCDSL1AHistory(const unsigned char *p) : hist((l1h*)p){
}
const l1h &history(){return *hist;}
private:
l1h *hist;
};

class TCDSBST{
public:
struct bst{
uint32_t gpstimelow;
uint32_t gpstimehigh;
uint32_t low0;
uint32_t high0;
uint32_t low1;
uint32_t high1;
uint32_t low2;
uint32_t high2;
uint32_t low3;
uint32_t high3;
uint32_t low4;
uint32_t high4;
uint32_t low5;
uint32_t status;
};
TCDSBST(const unsigned char *p) : b((bst*)p){
}
const bst &getBST(){return *b;}
private:
bst *b;
};

class TCDSRecord{
public:
TCDSRecord(const unsigned char *p) :
h(p+sizeof(fedh_t)),
l1h(p+sizeof(fedh_t)+(h.getSizes().size.headerSize+1)*8),
b(p+sizeof(fedh_t)+(h.getSizes().size.headerSize+1)*8+
(h.getSizes().size.L1AhistSize)*8)
{

}
TCDSHeader &getHeader(){return h;}
TCDSL1AHistory &getHistory(){return l1h;}
TCDSBST &getBST(){return b;}
private:
TCDSHeader h;
TCDSL1AHistory l1h;
TCDSBST b;
};


}
}
#endif
7 changes: 6 additions & 1 deletion EventFilter/FEDInterface/interface/GlobalEventNumber.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,18 @@ namespace evf{
const unsigned int EVM_BOARDID_VALUE = 0x11;

const unsigned int EVM_GTFE_BLOCK_V0000 = 6; //size in 64-bit words
const unsigned int EVM_GTFE_BLOCK_V0011 = 9; //size in 64-bit words, new format, not yet in effect
const unsigned int EVM_GTFE_BLOCK_V0011 = 9; //size in 64-bit words, new format
const unsigned int EVM_GTFE_BSTGPS_OFFSET = 4; //offset in 32-bit words

const unsigned int EVM_TCS_BOARDID_VALUE = 0xcc07;
const unsigned int EVM_TCS_BLOCK = 5; //size in 64-bit words
const unsigned int EVM_TCS_TRIGNR_OFFSET = 5; //offset in 32-bit words
const unsigned int EVM_TCS_LSBLNR_OFFSET = 0; //offset in 32-bit words
const unsigned int EVM_TCS_BOARDID_OFFSET = 1; //offset in 32-bit words
const unsigned int EVM_TCS_ORBTNR_OFFSET = 6; //offset in 32-bit words
const unsigned int EVM_TCS_LSBLNR_MASK = 0x0000ffff; // 16 LSB
const unsigned int EVM_TCS_BOARDID_MASK = 0xffff0000; // 16 MSB
const unsigned int EVM_TCS_BOARDID_SHIFT = 16; // 16 MSB
const unsigned int EVM_TCS_EVNTYP_MASK = 0x00f00000; // 4 bits
const unsigned int EVM_TCS_EVNTYP_SHIFT = 20;
const unsigned int EVM_TCS_BCNRIN_MASK = 0x00000fff; // 12 LSB
Expand Down Expand Up @@ -65,6 +69,7 @@ namespace evf{
return (*(unsigned int*)(p + sizeof(fedh_t) + DAQ_BOARDID_OFFSET * SLINK_WORD_SIZE / 2) >> DAQ_BOARDID_SHIFT) == DAQ_BOARDID_VALUE;
}
bool evm_board_sense(const unsigned char *p, size_t size);
bool evm_tcs_board_sense(const unsigned char *p);
void evm_board_setformat(size_t size);

inline bool gtpe_board_sense(const unsigned char *p)
Expand Down
11 changes: 10 additions & 1 deletion EventFilter/FEDInterface/src/GlobalEventNumber.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ namespace evf{
}
return (*(const unsigned int*)(p + sizeof(fedh_t) + EVM_BOARDID_OFFSET * SLINK_WORD_SIZE / 2) >> EVM_BOARDID_SHIFT) == EVM_BOARDID_VALUE;
}
bool evm_tcs_board_sense(const unsigned char *p){
return (*(const unsigned int*)(p + sizeof(fedh_t) +
(EVM_GTFE_BLOCK*2 + EVM_TCS_BOARDID_OFFSET)
* SLINK_WORD_SIZE / 2)
>> EVM_TCS_BOARDID_SHIFT) == EVM_TCS_BOARDID_VALUE;

}

void evm_board_setformat(size_t size)
{
Expand Down Expand Up @@ -66,7 +72,10 @@ namespace evf{
}
unsigned int get(const unsigned char *p, bool evm)
{
return *(const unsigned int*)( p+offset(evm) );
if(evm && evm_tcs_board_sense(p))
return *(const unsigned int*)( p+offset(true));
else
return *(const unsigned int*)( p+offset(false)); // cover case of evm but invalid tcs info
}
unsigned int gtpe_get(const unsigned char *p)
{
Expand Down
15 changes: 15 additions & 0 deletions EventFilter/Utilities/interface/AuxiliaryMakers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef EVF_UTILITIES_AUXILIARYMAKERS_H
#define EVF_UTILITIES_AUXILIARYMAKERS_H

#include "DataFormats/Provenance/interface/EventAuxiliary.h"
#include "EventFilter/FEDInterface/interface/FED1024.h"

namespace evf{
namespace evtn{
edm::EventAuxiliary makeEventAuxiliary(TCDSRecord *record,
unsigned int runNumber,
unsigned int lumiSection,
std::string const &processGUID);
}
}
#endif
21 changes: 19 additions & 2 deletions EventFilter/Utilities/plugins/FRDStreamSource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "EventFilter/FEDInterface/interface/GlobalEventNumber.h"
#include "EventFilter/FEDInterface/interface/fed_header.h"
#include "EventFilter/FEDInterface/interface/fed_trailer.h"
#include "EventFilter/FEDInterface/interface/FED1024.h"

#include "EventFilter/Utilities/plugins/FRDStreamSource.h"

Expand Down Expand Up @@ -87,16 +88,29 @@ bool FRDStreamSource::setRunAndEventInfo(edm::EventID& id, edm::TimeValue_t& the

uint32_t eventSize = frdEventMsg->eventSize();
char* event = (char*)frdEventMsg->payload();
bool foundTCDSFED=false;
bool foundGTPFED=false;


while (eventSize > 0) {
eventSize -= sizeof(fedt_t);
const fedt_t* fedTrailer = (fedt_t*) (event + eventSize);
const uint32_t fedSize = FED_EVSZ_EXTRACT(fedTrailer->eventsize) << 3; //trailer length counts in 8 bytes
eventSize -= (fedSize - sizeof(fedh_t));
const fedh_t* fedHeader = (fedh_t *) (event + eventSize);
const uint16_t fedId = FED_SOID_EXTRACT(fedHeader->sourceid);
if (fedId == FEDNumbering::MINTriggerGTPFEDID) {
if (fedId == FEDNumbering::MINTCDSuTCAFEDID) {
foundTCDSFED=true;
evf::evtn::TCDSRecord record((unsigned char *)(event + eventSize ));
id = edm::EventID(frdEventMsg->run(),record.getHeader().getData().header.lumiSection,
record.getHeader().getData().header.eventNumber);
//evf::evtn::evm_board_setformat(fedSize);
uint64_t gpsh = record.getBST().getBST().gpstimehigh;
uint32_t gpsl = record.getBST().getBST().gpstimelow;
theTime = static_cast<edm::TimeValue_t>((gpsh << 32) + gpsl);
}

if (fedId == FEDNumbering::MINTriggerGTPFEDID && !foundTCDSFED) {
foundGTPFED=true;
const bool GTPEvmBoardSense=evf::evtn::evm_board_sense((unsigned char*) fedHeader,fedSize);
if (!useL1EventID_) {
Expand All @@ -110,8 +124,11 @@ bool FRDStreamSource::setRunAndEventInfo(edm::EventID& id, edm::TimeValue_t& the
const uint64_t gpsh = evf::evtn::getgpshigh((unsigned char*) fedHeader);
theTime = static_cast<edm::TimeValue_t>((gpsh << 32) + gpsl);
}



//take event ID from GTPE FED
if (fedId == FEDNumbering::MINTriggerEGTPFEDID && !foundGTPFED && !useL1EventID_) {
if (fedId == FEDNumbering::MINTriggerEGTPFEDID && !foundGTPFED && !foundTCDSFED && !useL1EventID_) {
if (evf::evtn::gtpe_board_sense((unsigned char*)fedHeader)) {
id = edm::EventID(frdEventMsg->run(), frdEventMsg->lumi(), evf::evtn::gtpe_get((unsigned char*) fedHeader));
}
Expand Down
44 changes: 32 additions & 12 deletions EventFilter/Utilities/plugins/FedRawDataInputSource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
#include <boost/algorithm/string.hpp>
#include <boost/filesystem/fstream.hpp>

#include "DataFormats/Provenance/interface/LuminosityBlockAuxiliary.h"
#include "DataFormats/Provenance/interface/EventAuxiliary.h"
#include "DataFormats/Provenance/interface/EventID.h"

#include "DataFormats/FEDRawData/interface/FEDNumbering.h"
#include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
Expand All @@ -39,6 +36,12 @@
#include "EventFilter/Utilities/interface/DataPointDefinition.h"
#include "EventFilter/Utilities/interface/FFFNamingSchema.h"

#include "EventFilter/Utilities/interface/AuxiliaryMakers.h"

#include "DataFormats/Provenance/interface/EventAuxiliary.h"
#include "DataFormats/Provenance/interface/EventID.h"


//JSON file reader
#include "EventFilter/Utilities/interface/reader.h"

Expand All @@ -63,6 +66,7 @@ FedRawDataInputSource::FedRawDataInputSource(edm::ParameterSet const& pset,
eventID_(),
processHistoryID_(),
currentLumiSection_(0),
tcds_pointer_(0),
eventsThisLumi_(0),
dpd_(nullptr)
{
Expand All @@ -75,7 +79,7 @@ FedRawDataInputSource::FedRawDataInputSource(edm::ParameterSet const& pset,
edm::LogInfo("FedRawDataInputSource") << "Test mode is ON!";

processHistoryID_ = daqProvenanceHelper_.daqInit(productRegistryUpdate(), processHistoryRegistryForUpdate());
setNewRun();
setNewRun();
setRunAuxiliary(new edm::RunAuxiliary(runNumber_, edm::Timestamp::beginOfTime(),
edm::Timestamp::invalidTimestamp()));

Expand Down Expand Up @@ -566,18 +570,31 @@ void FedRawDataInputSource::read(edm::EventPrincipal& eventPrincipal)
{
std::auto_ptr<FEDRawDataCollection> rawData(new FEDRawDataCollection);
edm::Timestamp tstamp = fillFEDRawDataCollection(rawData);

if (useL1EventID_)
if (useL1EventID_){
eventID_ = edm::EventID(eventRunNumber_, currentLumiSection_, L1EventID_);
else {
edm::EventAuxiliary aux(eventID_, processGUID(), tstamp, true,
edm::EventAuxiliary::PhysicsTrigger);
aux.setProcessHistoryID(processHistoryID_);
makeEvent(eventPrincipal, aux);
}
else if(tcds_pointer_==0){
assert(GTPEventID_);
eventID_ = edm::EventID(eventRunNumber_, currentLumiSection_, GTPEventID_);
edm::EventAuxiliary aux(eventID_, processGUID(), tstamp, true,
edm::EventAuxiliary::PhysicsTrigger);
aux.setProcessHistoryID(processHistoryID_);
makeEvent(eventPrincipal, aux);
}
else{
evf::evtn::TCDSRecord record((unsigned char *)(tcds_pointer_));
edm::EventAuxiliary aux = evf::evtn::makeEventAuxiliary(&record,
eventRunNumber_,currentLumiSection_,
processGUID());
aux.setProcessHistoryID(processHistoryID_);
makeEvent(eventPrincipal, aux);
}


edm::EventAuxiliary aux(eventID_, processGUID(), tstamp, true,
edm::EventAuxiliary::PhysicsTrigger);
aux.setProcessHistoryID(processHistoryID_);
makeEvent(eventPrincipal, aux);

edm::WrapperOwningHolder edp(new edm::Wrapper<FEDRawDataCollection>(rawData),
edm::Wrapper<FEDRawDataCollection>::getInterface());
Expand Down Expand Up @@ -624,14 +641,17 @@ edm::Timestamp FedRawDataInputSource::fillFEDRawDataCollection(std::auto_ptr<FED
uint32_t eventSize = event_->eventSize();
char* event = (char*)event_->payload();
GTPEventID_=0;

tcds_pointer_ = 0;
while (eventSize > 0) {
eventSize -= sizeof(fedt_t);
const fedt_t* fedTrailer = (fedt_t*) (event + eventSize);
const uint32_t fedSize = FED_EVSZ_EXTRACT(fedTrailer->eventsize) << 3; //trailer length counts in 8 bytes
eventSize -= (fedSize - sizeof(fedh_t));
const fedh_t* fedHeader = (fedh_t *) (event + eventSize);
const uint16_t fedId = FED_SOID_EXTRACT(fedHeader->sourceid);
if (fedId == FEDNumbering::MINTCDSuTCAFEDID) {
tcds_pointer_ = (unsigned char *)(event + eventSize );
}
if (fedId == FEDNumbering::MINTriggerGTPFEDID) {
if (evf::evtn::evm_board_sense((unsigned char*) fedHeader,fedSize))
GTPEventID_ = evf::evtn::get((unsigned char*) fedHeader,true);
Expand Down
5 changes: 5 additions & 0 deletions EventFilter/Utilities/plugins/FedRawDataInputSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "IOPool/Streamer/interface/FRDEventMessage.h"

#include "EventFilter/FEDInterface/interface/FED1024.h"

#include "DataFormats/Provenance/interface/LuminosityBlockAuxiliary.h"

class FEDRawDataCollection;
class InputSourceDescription;
class ParameterSet;
Expand Down Expand Up @@ -103,6 +107,7 @@ friend class InputChunk;
uint32_t eventRunNumber_=0;
uint32_t GTPEventID_ = 0;
uint32_t L1EventID_ = 0;
unsigned char *tcds_pointer_;
unsigned int eventsThisLumi_;
unsigned long eventsThisRun_ = 0;

Expand Down

0 comments on commit 01b7144

Please sign in to comment.