CMS 3D CMS Logo

RawToText.cc
Go to the documentation of this file.
1 
3 
4 // system
5 #include <fstream>
6 #include <iomanip>
7 #include <iostream>
8 #include <string>
9 // framework
12 // raw data collection
14 
16  : inputLabel_(iConfig.getParameter<edm::InputTag>("inputLabel")),
17  fedId_(iConfig.getUntrackedParameter<int>("fedId", 745)),
18  filename_(iConfig.getUntrackedParameter<std::string>("filename",
19  "slinkOutput.txt")),
20  nevt_(0) {
21  edm::LogInfo("TextToDigi")
22  << "Creating ASCII dump " << filename_ << std::endl;
23 }
24 
26 
28  const edm::EventSetup &iSetup) {
29 
30  nevt_++;
31 
32  // get raw data collection
34  iEvent.getByLabel(inputLabel_, feds);
35  const FEDRawData &gctRcd = feds->FEDData(fedId_);
36 
37  edm::LogInfo("GCT") << "Upacking FEDRawData of size " << std::dec
38  << gctRcd.size() << std::endl;
39 
40  // do a simple check of the raw data
41  if (gctRcd.size() < 16) {
42  edm::LogWarning("Invalid Data")
43  << "Empty/invalid GCT raw data, size = " << gctRcd.size() << std::endl;
44  return;
45  }
46 
47  const unsigned char *data = gctRcd.data();
48 
49  int eventSize = gctRcd.size() / 4;
50 
51  unsigned long d = 0;
52  for (int i = 0; i < eventSize; i++) {
53  d = 0;
54  // d = data[i*4+0] + (data[i*4+1]<<8) + (data[i*4+2]<<16) +
55  // (data[i*4+3]<<24);
56  for (int j = 0; j < 4; j++) {
57  d += ((data[i * 4 + j] & 0xff) << (8 * j));
58  }
59  file_ << std::setw(8) << std::setfill('0') << std::hex << d << std::endl;
60  }
61  file_ << std::flush << std::endl;
62 }
63 
65 
66  // open VME file
67  file_.open(filename_.c_str(), std::ios::out);
68 
69  if (!file_.good()) {
70  edm::LogInfo("RawToText")
71  << "Failed to open ASCII file " << filename_ << std::endl;
72  }
73 }
74 
75 void RawToText::endJob() { file_.close(); }
~RawToText() override
Definition: RawToText.cc:25
int fedId_
Definition: RawToText.h:39
void beginJob() override
Definition: RawToText.cc:64
RawToText(const edm::ParameterSet &)
Definition: RawToText.cc:15
std::ofstream file_
Definition: RawToText.h:43
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
std::string filename_
Definition: RawToText.h:42
int iEvent
Definition: GenABIO.cc:224
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:480
edm::InputTag inputLabel_
Definition: RawToText.h:36
int nevt_
Definition: RawToText.h:45
HLT enums.
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
void endJob() override
Definition: RawToText.cc:75
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: RawToText.cc:27