1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
/**
* \class L1GtTextToRaw
*
*
* Description: generate raw data from dumped text file.
*
* Implementation:
* <TODO: enter implementation details>
*
* \author: Vasile Mihai Ghete - HEPHY Vienna
*
*
*/
// this class header
#include "EventFilter/L1GlobalTriggerRawToDigi/interface/L1GtTextToRaw.h"
// system include files
#include <vector>
#include <iostream>
#include <iomanip>
// user include files
#include "DataFormats/FEDRawData/interface/FEDNumbering.h"
#include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/MessageLogger/interface/MessageDrop.h"
#include "FWCore/Utilities/interface/typedefs.h"
// constructor(s)
L1GtTextToRaw::L1GtTextToRaw(const edm::ParameterSet& pSet) {
m_textFileType = pSet.getUntrackedParameter<std::string>("TextFileType", "VmeSpyDump");
LogDebug("L1GtTextToRaw") << "\nText file type: " << m_textFileType << "\n" << std::endl;
m_textFileName = pSet.getUntrackedParameter<std::string>("TextFileName", "gtfe.dmp");
LogDebug("L1GtTextToRaw") << "\nText file name: " << m_textFileName << "\n" << std::endl;
// event size
m_rawDataSize = pSet.getUntrackedParameter<int>("RawDataSize");
LogDebug("L1GtTextToRaw") << "\nRaw data size (units of 8 bits): " << m_rawDataSize
<< "\n If negative value, the size is retrieved from the trailer."
<< "\n"
<< std::endl;
// FED Id for GT DAQ record
// default value defined in DataFormats/FEDRawData/src/FEDNumbering.cc
// default value: assume the DAQ record is the last GT record
m_daqGtFedId = pSet.getUntrackedParameter<int>("DaqGtFedId", FEDNumbering::MAXTriggerGTPFEDID);
LogDebug("L1GtTextToRaw") << "\nFED Id for DAQ GT record: " << m_daqGtFedId << " \n" << std::endl;
// open test file
m_textFile.open(m_textFileName.c_str(), std::ios::in);
if (!m_textFile.good()) {
throw cms::Exception("NotFound") << "\nError: failed to open text file = " << m_textFileName << "\n" << std::endl;
}
//
produces<FEDRawDataCollection>();
}
// destructor
L1GtTextToRaw::~L1GtTextToRaw() {
// empty now
}
// member functions
// beginning of job stuff
void L1GtTextToRaw::beginJob() { cleanTextFile(); }
// clean the text file, if needed
void L1GtTextToRaw::cleanTextFile() { LogDebug("L1GtTextToRaw") << "\nCleaning the text file\n" << std::endl; }
// get the size of the record
int L1GtTextToRaw::getDataSize() {
LogDebug("L1GtTextToRaw") << "\nComputing raw data size with getRecordSize() method." << std::endl;
int rawDataSize = 0;
LogDebug("L1GtTextToRaw") << "\nComputed raw data size: " << rawDataSize << std::endl;
return rawDataSize;
}
// method called to produce the data
void L1GtTextToRaw::produce(edm::Event& iEvent, const edm::EventSetup& evSetup) {
// get the size of the record
int rawDataSize = 0;
if (m_rawDataSize < 0) {
rawDataSize = getDataSize();
} else {
rawDataSize = m_rawDataSize;
}
// define new FEDRawDataCollection
// it contains ALL FEDs in an event
std::unique_ptr<FEDRawDataCollection> fedRawColl(new FEDRawDataCollection);
FEDRawData& rawData = fedRawColl->FEDData(m_daqGtFedId);
// resize, GT raw data record has variable length,
// depending on active boards (read in GTFE)
rawData.resize(rawDataSize);
LogDebug("L1GtTextToRaw") << "\n Size of raw data: " << rawData.size() << "\n" << std::endl;
// read the text file
// the file must have one 64 bits per line (usually in hex format)
// events are separated by empty lines
std::string lineString;
cms_uint64_t lineInt = 0ULL;
int sizeL = sizeof(lineInt);
int fedBlockSize = 8; // block size in bits for FedRawData
int maskBlock = 0xff; // fedBlockSize and maskBlock must be consistent
int iLine = 0;
while (std::getline(m_textFile, lineString)) {
if (lineString.empty()) {
break;
}
// convert string to int
std::istringstream iss(lineString);
iss >> std::hex >> lineInt;
LogTrace("L1GtTextToRaw") << std::dec << std::setw(4) << std::setfill('0') << iLine << ": " << std::hex
<< std::setw(sizeL * 2) << lineInt << std::dec << std::setfill(' ') << std::endl;
// copy data
for (int j = 0; j < sizeL; j++) {
char blockContent = (lineInt >> (fedBlockSize * j)) & maskBlock;
rawData.data()[iLine * sizeL + j] = blockContent;
}
++iLine;
}
// put the raw data in the event
iEvent.put(std::move(fedRawColl));
}
//
void L1GtTextToRaw::endJob() {
// empty now
}
// static class members
|