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 
44 namespace omtf {
45 
47 public:
48 
50 
51  ~OmtfPacker() override {}
52 
53  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
54 
55  void produce(edm::Event & ev, const edm::EventSetup& es) override;
56 
57  void beginRun(const edm::Run &run, const edm::EventSetup& es) override;
58 
59 private:
60 
62  unsigned long theEventCounter;
63 
65 
67 
72 
76 
77 };
78 
80 {
81  theOutputTag = pset.getParameter<std::string>("outputTag");
82 
83  produces<FEDRawDataCollection>(theOutputTag);
84 
85  theRpcToken = consumes<RPCDigiCollection>(pset.getParameter<edm::InputTag>("rpcInputLabel"));
86  theCscToken = consumes<CSCCorrelatedLCTDigiCollection>(pset.getParameter<edm::InputTag>("cscInputLabel"));
87  theDtPhToken = consumes<L1MuDTChambPhContainer>(pset.getParameter<edm::InputTag>("dtPhInputLabel"));
88  theDtThToken = consumes<L1MuDTChambThContainer>(pset.getParameter<edm::InputTag>("dtThInputLabel"));
89 
90  theSkipDt = pset.getParameter<bool>("skipDt");
91  theSkipRpc = pset.getParameter<bool>("skipRpc");
92  theSkipCsc = pset.getParameter<bool>("skipCsc");
93 
94 }
95 
98  desc.add<edm::InputTag>("rpcInputLabel",edm::InputTag(""));
99  desc.add<edm::InputTag>("cscInputLabel",edm::InputTag(""));
100  desc.add<edm::InputTag>("dtPhInputLabel",edm::InputTag(""));
101  desc.add<edm::InputTag>("dtThInputLabel",edm::InputTag(""));
102  desc.add<bool>("skipRpc",false);
103  desc.add<bool>("skipCsc",false);
104  desc.add<bool>("skipDt",false);
105  desc.add<bool>("useRpcConnectionFile",false);
106  desc.add<std::string>("rpcConnectionFile","");
107  desc.add<std::string>("outputTag","");
108  descriptions.add("omtfPacker",desc);
109 }
110 
112 
113  //
114  // initialise RPC packer
115  //
116  if (!theSkipRpc) {
117  if (theConfig.getParameter<bool>("useRpcConnectionFile")) {
119  } else {
120  theRpcPacker.init(es);
121  }
122  }
123 
124  //
125  // init CSC Link map
126  //
127  if (!theSkipCsc) theCscPacker.init();
128 }
129 
130 
132 {
133  LogDebug ("OmtfPacker::produce") <<"Beginning To Pack Event: "<<++theEventCounter;
134 
135  //
136  // prepare FedAmcRawsMap structure to collect Word64 raws from digi packers
137  //
138  FedAmcRawsMap raws;
139  std::list<unsigned int> amcIds = { 1, 3, 5, 7, 9, 11};
140  std::list<unsigned int> fedIds = { 1380, 1381};
141  for (auto & fedId : fedIds) { for (auto & amcId : amcIds) { raws[std::make_pair(fedId, amcId)]; } }
142 
143  //
144  // DT raws
145  //
146  if (!theSkipDt) {
147  edm::Handle<L1MuDTChambPhContainer> digiCollectionDTPh;
148  ev.getByToken(theDtPhToken, digiCollectionDTPh);
149  edm::Handle<L1MuDTChambThContainer> digiCollectionDTTh;
150  ev.getByToken(theDtThToken, digiCollectionDTTh);
151  theDtPacker.pack(digiCollectionDTPh.product(),digiCollectionDTTh.product(), raws);
152  }
153 
154  //
155  // csc raws
156  //
157  if (!theSkipCsc) {
159  ev.getByToken(theCscToken,digiCollectionCSC);
160  theCscPacker.pack(digiCollectionCSC.product(), raws);
161  }
162 
163  //
164  // rpc raws
165  //
166  if (!theSkipRpc) {
167  edm::Handle< RPCDigiCollection > digiCollectionRPC;
168  ev.getByToken(theRpcToken,digiCollectionRPC);
169  theRpcPacker.pack( digiCollectionRPC.product(), raws);
170  }
171 
172  auto bxId = ev.bunchCrossing();
173  auto evtId = ev.id().event();
174  auto orbit = ev.eventAuxiliary().orbitNumber();
175  std::unique_ptr<FEDRawDataCollection> raw_coll(new FEDRawDataCollection());
176  for (auto & fedId : fedIds) {
177 
178  //
179  // assign formatted raws to feds
180  //
182  for (const auto & it : raws) {
183  if (fedId != it.first.first) continue;
184  const std::vector<Word64> & amcData = it.second;
185  unsigned int amcId = it.first.second;
186  for (const auto & raw : amcData) {
187  std::ostringstream dataStr;
188  if (DataWord64::csc == DataWord64::type(raw)) dataStr << CscDataWord64(raw);
189  if (DataWord64::dt == DataWord64::type(raw)) dataStr << DtDataWord64(raw);
190  if (DataWord64::rpc == DataWord64::type(raw)) dataStr << RpcDataWord64(raw);
191  if (DataWord64::omtf == DataWord64::type(raw)) dataStr << MuonDataWord64(raw);
192  LogTrace("")<<" fed: "<< fedId <<" amcId: "<<amcId<<" RAW DATA: " << dataStr.str() << std::endl;
193  }
194  amc13.add(amcId, 43981, evtId, orbit, bxId, amcData);
195  }
196 
197  FEDRawData& fed_data = raw_coll->FEDData(fedId);
198 
199  const unsigned int slinkHeaderSize = 8;
200  const unsigned int slinkTrailerSize = 8;
201  unsigned int size = (amc13.size()) * sizeof(Word64)+slinkHeaderSize+slinkTrailerSize;
202  fed_data.resize(size);
203  unsigned char * payload = fed_data.data();
204  unsigned char * payload_start = payload;
205 
206  FEDHeader header(payload);
207  const unsigned int evtType = 1;
208  header.set(payload, evtType, evtId, bxId, fedId);
209 
210  amc13.write(ev, payload, slinkHeaderSize, size - slinkHeaderSize - slinkTrailerSize);
211 
212  payload += slinkHeaderSize;
213  payload += amc13.size() * 8;
214 
215  FEDTrailer trailer(payload);
216  trailer.set(payload, size / 8, evf::compute_crc(payload_start, size), 0, 0);
217  }
218  ev.put(std::move(raw_coll), theOutputTag);
219 
220 
221 }
222 
223 }
224 using namespace omtf;
226 
#define LogDebug(id)
size
Write out results.
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:41
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
EventAuxiliary const & eventAuxiliary() const override
Definition: Event.h:93
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
unsigned int size() const
Definition: AMC13Spec.cc:200
int bunchCrossing() const
Definition: EventBase.h:66
void add(unsigned int amc_no, unsigned int board, unsigned int lv1id, unsigned int orbit, unsigned int bx, const std::vector< uint64_t > &load, unsigned int user=0)
Definition: AMC13Spec.cc:61
std::map< std::pair< unsigned int, unsigned int >, std::vector< Word64 > > FedAmcRawsMap
bool ev
void produce(edm::Event &ev, const edm::EventSetup &es) override
Definition: OmtfPacker.cc:131
bool write(const edm::Event &ev, unsigned char *ptr, unsigned int skip, unsigned int size) const
Definition: AMC13Spec.cc:218
DtPacker theDtPacker
Definition: OmtfPacker.cc:75
edm::ParameterSet theConfig
Definition: OmtfPacker.cc:61
void pack(const RPCDigiCollection *prod, FedAmcRawsMap &raws)
void beginRun(const edm::Run &run, const edm::EventSetup &es) override
Definition: OmtfPacker.cc:111
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:60
OmtfPacker(const edm::ParameterSet &pset)
Definition: OmtfPacker.cc:79
void resize(size_t newsize)
Definition: FEDRawData.cc:32
int orbitNumber() const
unsigned short compute_crc(unsigned char *buffer, unsigned int bufSize)
Definition: CRC16.h:67
edm::EDGetTokenT< RPCDigiCollection > theRpcToken
Definition: OmtfPacker.cc:68
void pack(const CSCCorrelatedLCTDigiCollection *prod, FedAmcRawsMap &raws)
void pack(const L1MuDTChambPhContainer *phCont, const L1MuDTChambThContainer *thCont, FedAmcRawsMap &raws)
Definition: OmtfDtPacker.cc:8
RpcPacker theRpcPacker
Definition: OmtfPacker.cc:74
Type type(const T &)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
#define LogTrace(id)
edm::EDGetTokenT< CSCCorrelatedLCTDigiCollection > theCscToken
Definition: OmtfPacker.cc:69
uint64_t Word64
CscPacker theCscPacker
Definition: OmtfPacker.cc:73
edm::EDGetTokenT< L1MuDTChambThContainer > theDtThToken
Definition: OmtfPacker.cc:70
T const * product() const
Definition: Handle.h:81
unsigned long theEventCounter
Definition: OmtfPacker.cc:62
void add(std::string const &label, ParameterSetDescription const &psetDescription)
edm::EDGetTokenT< L1MuDTChambPhContainer > theDtPhToken
Definition: OmtfPacker.cc:71
std::string theOutputTag
Definition: OmtfPacker.cc:64
~OmtfPacker() override
Definition: OmtfPacker.cc:51
edm::EventID id() const
Definition: EventBase.h:60
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
std::string fullPath() const
Definition: FileInPath.cc:197
static void set(unsigned char *header, uint8_t triggerType, uint32_t lvl1ID, uint16_t bxID, uint16_t sourceID, uint8_t version=0, bool moreHeaders=false)
Set all fields in the header.
Definition: FEDHeader.cc:47
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: OmtfPacker.cc:96
void init(const edm::EventSetup &es)
def move(src, dest)
Definition: eostools.py:510
Definition: Run.h:44