CMS 3D CMS Logo

OmtfPacker.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <iomanip>
3 #include <bitset>
4 #include <string>
5 #include <map>
6 
15 
21 
25 
31 
34 
37 
39 
43 
47 
48 namespace omtf {
49 
51  public:
53 
54  ~OmtfPacker() override {}
55 
56  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
57 
58  void produce(edm::Event& ev, const edm::EventSetup& es) override;
59 
60  void beginRun(const edm::Run& run, const edm::EventSetup& es) override;
61 
62  private:
64  unsigned long theEventCounter;
65 
67 
69 
74 
77 
81  };
82 
83  OmtfPacker::OmtfPacker(const edm::ParameterSet& pset) : theConfig(pset), theEventCounter(0) {
84  theOutputTag = pset.getParameter<std::string>("outputTag");
85 
86  produces<FEDRawDataCollection>(theOutputTag);
87 
88  theRpcToken = consumes<RPCDigiCollection>(pset.getParameter<edm::InputTag>("rpcInputLabel"));
89  theCscToken = consumes<CSCCorrelatedLCTDigiCollection>(pset.getParameter<edm::InputTag>("cscInputLabel"));
90  theDtPhToken = consumes<L1MuDTChambPhContainer>(pset.getParameter<edm::InputTag>("dtPhInputLabel"));
91  theDtThToken = consumes<L1MuDTChambThContainer>(pset.getParameter<edm::InputTag>("dtThInputLabel"));
92 
93  theSkipDt = pset.getParameter<bool>("skipDt");
94  theSkipRpc = pset.getParameter<bool>("skipRpc");
95  theSkipCsc = pset.getParameter<bool>("skipCsc");
96 
97  if (!theSkipRpc) {
98  theRPCEMapToken = esConsumes<edm::Transition::BeginRun>();
99  if (not theConfig.getParameter<bool>("useRpcConnectionFile")) {
100  theAmcMappingToken = esConsumes<edm::Transition::BeginRun>();
101  }
102  }
103  }
104 
107  desc.add<edm::InputTag>("rpcInputLabel", edm::InputTag(""));
108  desc.add<edm::InputTag>("cscInputLabel", edm::InputTag(""));
109  desc.add<edm::InputTag>("dtPhInputLabel", edm::InputTag(""));
110  desc.add<edm::InputTag>("dtThInputLabel", edm::InputTag(""));
111  desc.add<bool>("skipRpc", false);
112  desc.add<bool>("skipCsc", false);
113  desc.add<bool>("skipDt", false);
114  desc.add<bool>("useRpcConnectionFile", false);
115  desc.add<std::string>("rpcConnectionFile", "");
116  desc.add<std::string>("outputTag", "");
117  descriptions.add("omtfPacker", desc);
118  }
119 
121  //
122  // initialise RPC packer
123  //
124  if (!theSkipRpc) {
126  if (theConfig.getParameter<bool>("useRpcConnectionFile")) {
127  theRpcPacker.init(*readoutMapping,
128  edm::FileInPath(theConfig.getParameter<std::string>("rpcConnectionFile")).fullPath());
129  } else {
130  auto const& amcMapping = es.getData(theAmcMappingToken);
131  theRpcPacker.init(*readoutMapping, amcMapping);
132  }
133  }
134 
135  //
136  // init CSC Link map
137  //
138  if (!theSkipCsc)
139  theCscPacker.init();
140  }
141 
143  LogDebug("OmtfPacker::produce") << "Beginning To Pack Event: " << ++theEventCounter;
144 
145  //
146  // prepare FedAmcRawsMap structure to collect Word64 raws from digi packers
147  //
148  FedAmcRawsMap raws;
149  std::list<unsigned int> amcIds = {1, 3, 5, 7, 9, 11};
150  std::list<unsigned int> fedIds = {1380, 1381};
151  for (auto& fedId : fedIds) {
152  for (auto& amcId : amcIds) {
153  raws[std::make_pair(fedId, amcId)];
154  }
155  }
156 
157  //
158  // DT raws
159  //
160  if (!theSkipDt) {
161  edm::Handle<L1MuDTChambPhContainer> digiCollectionDTPh;
162  ev.getByToken(theDtPhToken, digiCollectionDTPh);
163  edm::Handle<L1MuDTChambThContainer> digiCollectionDTTh;
164  ev.getByToken(theDtThToken, digiCollectionDTTh);
165  theDtPacker.pack(digiCollectionDTPh.product(), digiCollectionDTTh.product(), raws);
166  }
167 
168  //
169  // csc raws
170  //
171  if (!theSkipCsc) {
173  ev.getByToken(theCscToken, digiCollectionCSC);
174  theCscPacker.pack(digiCollectionCSC.product(), raws);
175  }
176 
177  //
178  // rpc raws
179  //
180  if (!theSkipRpc) {
181  edm::Handle<RPCDigiCollection> digiCollectionRPC;
182  ev.getByToken(theRpcToken, digiCollectionRPC);
183  theRpcPacker.pack(digiCollectionRPC.product(), raws);
184  }
185 
186  auto bxId = ev.bunchCrossing();
187  auto evtId = ev.id().event();
188  auto orbit = ev.eventAuxiliary().orbitNumber();
189  std::unique_ptr<FEDRawDataCollection> raw_coll(new FEDRawDataCollection());
190  for (auto& fedId : fedIds) {
191  //
192  // assign formatted raws to feds
193  //
195  for (const auto& it : raws) {
196  if (fedId != it.first.first)
197  continue;
198  const std::vector<Word64>& amcData = it.second;
199  unsigned int amcId = it.first.second;
200  for (const auto& raw : amcData) {
201  std::ostringstream dataStr;
202  if (DataWord64::csc == DataWord64::type(raw))
203  dataStr << CscDataWord64(raw);
204  if (DataWord64::dt == DataWord64::type(raw))
205  dataStr << DtDataWord64(raw);
206  if (DataWord64::rpc == DataWord64::type(raw))
207  dataStr << RpcDataWord64(raw);
209  dataStr << MuonDataWord64(raw);
210  LogTrace("") << " fed: " << fedId << " amcId: " << amcId << " RAW DATA: " << dataStr.str() << std::endl;
211  }
212  amc13.add(amcId, 43981, evtId, orbit, bxId, amcData);
213  }
214 
215  FEDRawData& fed_data = raw_coll->FEDData(fedId);
216 
217  const unsigned int slinkHeaderSize = 8;
218  const unsigned int slinkTrailerSize = 8;
219  unsigned int size = (amc13.size()) * sizeof(Word64) + slinkHeaderSize + slinkTrailerSize;
220  fed_data.resize(size);
221  unsigned char* payload = fed_data.data();
222  unsigned char* payload_start = payload;
223 
225  const unsigned int evtType = 1;
226  header.set(payload, evtType, evtId, bxId, fedId);
227 
228  amc13.write(ev, payload, slinkHeaderSize, size - slinkHeaderSize - slinkTrailerSize);
229 
230  payload += slinkHeaderSize;
231  payload += amc13.size() * 8;
232 
233  FEDTrailer trailer(payload);
234  trailer.set(payload, size / 8, evf::compute_crc(payload_start, size), 0, 0);
235  }
236  ev.put(std::move(raw_coll), theOutputTag);
237  }
238 
239 } // namespace omtf
240 using namespace omtf;
FEDNumbering.h
omtf::OmtfPacker::theOutputTag
std::string theOutputTag
Definition: OmtfPacker.cc:66
omtf::OmtfPacker::theAmcMappingToken
edm::ESGetToken< RPCAMCLinkMap, RPCOMTFLinkMapRcd > theAmcMappingToken
Definition: OmtfPacker.cc:76
omtf::OmtfPacker::theDtPacker
DtPacker theDtPacker
Definition: OmtfPacker.cc:80
CSCCorrelatedLCTDigiCollection.h
MessageLogger.h
edm::Handle::product
T const * product() const
Definition: Handle.h:70
ESHandle.h
edm::Run
Definition: Run.h:45
edm::EDGetTokenT< RPCDigiCollection >
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89301
omtf::CscPacker
Definition: OmtfCscPacker.h:16
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
OmtfCscDataWord64.h
omtf::OmtfPacker::~OmtfPacker
~OmtfPacker() override
Definition: OmtfPacker.cc:54
omtf::Word64
uint64_t Word64
Definition: OmtfDataWord64.h:11
omtf::OmtfPacker::theEventCounter
unsigned long theEventCounter
Definition: OmtfPacker.cc:64
omtf::DataWord64::csc
Definition: OmtfDataWord64.h:16
EDProducer.h
CSCCorrelatedLCTDigi.h
amc13
Definition: AMC13Spec.h:14
omtf::OmtfPacker::theSkipDt
bool theSkipDt
Definition: OmtfPacker.cc:68
omtf::DataWord64::omtf
Definition: OmtfDataWord64.h:16
omtf::OmtfPacker::OmtfPacker
OmtfPacker(const edm::ParameterSet &pset)
Definition: OmtfPacker.cc:83
L1MuDTChambThContainer.h
FEDRawData.h
edm::Handle< L1MuDTChambPhContainer >
omtf::RpcPacker
Definition: OmtfRpcPacker.h:18
omtf::OmtfPacker::theSkipRpc
bool theSkipRpc
Definition: OmtfPacker.cc:68
RPCEMapRcd.h
FEDRawData::data
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:24
FEDRawData
Definition: FEDRawData.h:19
AMC13Spec.h
edm::FileInPath
Definition: FileInPath.h:61
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
amc13::Packet
Definition: AMC13Spec.h:69
omtf::OmtfPacker
Definition: OmtfPacker.cc:50
omtf::OmtfPacker::theSkipCsc
bool theSkipCsc
Definition: OmtfPacker.cc:68
EcalFEDMonitor_cfi.FEDRawDataCollection
FEDRawDataCollection
Definition: EcalFEDMonitor_cfi.py:6
jets_cff.payload
payload
Definition: jets_cff.py:32
omtf::OmtfPacker::theConfig
edm::ParameterSet theConfig
Definition: OmtfPacker.cc:63
omtf::RpcPacker::init
void init(const RPCEMap &readoutMapping, const RPCAMCLinkMap &linkMap)
Definition: OmtfRpcPacker.cc:19
omtf::RpcPacker::pack
void pack(const RPCDigiCollection *prod, FedAmcRawsMap &raws)
Definition: OmtfRpcPacker.cc:33
OmtfDtPacker.h
omtf::OmtfPacker::beginRun
void beginRun(const edm::Run &run, const edm::EventSetup &es) override
Definition: OmtfPacker.cc:120
omtf::FedAmcRawsMap
std::map< std::pair< unsigned int, unsigned int >, std::vector< Word64 > > FedAmcRawsMap
Definition: OmtfDataWord64.h:13
evf::compute_crc
unsigned short compute_crc(unsigned char *buffer, unsigned int bufSize)
Definition: CRC16.h:46
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
omtf::OmtfPacker::theRpcPacker
RpcPacker theRpcPacker
Definition: OmtfPacker.cc:79
omtf::DataWord64::dt
Definition: OmtfDataWord64.h:16
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
OmtfRpcDataWord64.h
edm::ParameterSet
Definition: ParameterSet.h:47
FEDTrailer
Definition: FEDTrailer.h:14
Event.h
omtf::MuonDataWord64
Definition: OmtfMuonDataWord64.h:8
omtf::DtPacker
Definition: OmtfDtPacker.h:13
omtf::OmtfPacker::theRpcToken
edm::EDGetTokenT< RPCDigiCollection > theRpcToken
Definition: OmtfPacker.cc:70
OmtfDtDataWord64.h
omtf::DtDataWord64
Definition: OmtfDtDataWord64.h:9
FEDRawDataCollection.h
omtf::DataWord64::type
Type type(const T &)
omtf::RpcDataWord64
Definition: OmtfRpcDataWord64.h:9
edm::stream::EDProducer
Definition: EDProducer.h:36
edm::EventSetup
Definition: EventSetup.h:58
l1tstage2_dqm_sourceclient-live_cfg.fedId
fedId
Definition: l1tstage2_dqm_sourceclient-live_cfg.py:89
FEDTrailer::set
static void set(unsigned char *trailer, uint32_t lenght, uint16_t crc, uint8_t evt_stat, uint8_t tts, bool moreTrailers=false)
Set all fields in the trailer.
Definition: FEDTrailer.cc:31
L1MuDTChambPhContainer.h
edm::EventSetup::getTransientHandle
ESTransientHandle< T > getTransientHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:166
edm::ESGetToken< RPCEMap, RPCEMapRcd >
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
omtf::OmtfPacker::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: OmtfPacker.cc:105
edm::ESTransientHandle
Definition: ESTransientHandle.h:41
InputTag.h
RPCOMTFLinkMapRcd.h
edm::EventSetup::getData
bool getData(T &iHolder) const
Definition: EventSetup.h:127
OmtfRpcPacker.h
omtf::OmtfPacker::theDtPhToken
edm::EDGetTokenT< L1MuDTChambPhContainer > theDtPhToken
Definition: OmtfPacker.cc:73
omtf::DtPacker::pack
void pack(const L1MuDTChambPhContainer *phCont, const L1MuDTChambThContainer *thCont, FedAmcRawsMap &raws)
Definition: OmtfDtPacker.cc:8
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
writedatasetfile.run
run
Definition: writedatasetfile.py:27
omtf::OmtfPacker::theRPCEMapToken
edm::ESGetToken< RPCEMap, RPCEMapRcd > theRPCEMapToken
Definition: OmtfPacker.cc:75
ev
bool ev
Definition: Hydjet2Hadronizer.cc:97
FEDRawData::resize
void resize(size_t newsize)
Definition: FEDRawData.cc:28
OmtfDataWord64.h
OmtfCscPacker.h
L1TStage2BMTF_cff.fedIds
fedIds
Definition: L1TStage2BMTF_cff.py:10
EventSetup.h
RPCDigiCollection.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
omtf::CscPacker::pack
void pack(const CSCCorrelatedLCTDigiCollection *prod, FedAmcRawsMap &raws)
Definition: OmtfCscPacker.cc:11
omtf::CscDataWord64
Definition: OmtfCscDataWord64.h:9
RecoTauValidation_cfi.header
header
Definition: RecoTauValidation_cfi.py:291
AMCSpec.h
omtf::CscPacker::init
void init()
Definition: OmtfCscPacker.cc:9
RPCEMap.h
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:234
ParameterSet.h
OmtfMuonDataWord64.h
FEDHeader
Definition: FEDHeader.h:14
edm::Event
Definition: Event.h:73
omtf::DataWord64::rpc
Definition: OmtfDataWord64.h:16
FEDHeader.h
omtf::OmtfPacker::produce
void produce(edm::Event &ev, const edm::EventSetup &es) override
Definition: OmtfPacker.cc:142
omtf
Definition: OmtfCscDataWord64.h:7
edm::InputTag
Definition: InputTag.h:15
omtf::OmtfPacker::theCscToken
edm::EDGetTokenT< CSCCorrelatedLCTDigiCollection > theCscToken
Definition: OmtfPacker.cc:71
edm::FileInPath::fullPath
std::string fullPath() const
Definition: FileInPath.cc:161
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
omtf::OmtfPacker::theDtThToken
edm::EDGetTokenT< L1MuDTChambThContainer > theDtThToken
Definition: OmtfPacker.cc:72
omtf::OmtfPacker::theCscPacker
CscPacker theCscPacker
Definition: OmtfPacker.cc:78
CRC16.h
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
FEDTrailer.h