L1Trigger
TextToDigi
plugins
TextToRaw.cc
Go to the documentation of this file.
1
2
3
#include "
L1Trigger/TextToDigi/plugins/TextToRaw.h
"
4
5
// system
6
#include <fstream>
7
#include <iostream>
8
#include <string>
9
#include <vector>
10
11
// framework
12
#include "
FWCore/MessageLogger/interface/MessageLogger.h
"
13
14
#include "
FWCore/Utilities/interface/Exception.h
"
15
16
// Raw data collection
17
#include "
DataFormats/FEDRawData/interface/FEDRawDataCollection.h
"
18
19
using
std::cerr
;
20
using
std::cout
;
21
using
std::endl;
22
using
std::ios;
23
using
std::string
;
24
using
std::vector
;
25
26
const
unsigned
TextToRaw::EVT_MAX_SIZE
;
27
28
TextToRaw::TextToRaw
(
const
edm::ParameterSet
&iConfig)
29
: fedId_(iConfig.getUntrackedParameter<
int
>(
"fedId"
, 745)),
30
filename_(iConfig.getUntrackedParameter<
std
::
string
>(
"filename"
,
"slinkOutput.txt"
)),
31
fileEventOffset_(iConfig.getUntrackedParameter<
int
>(
"FileEventOffset"
, 0)),
32
nevt_(0) {
33
edm::LogInfo
(
"TextToDigi"
) <<
"Reading ASCII dump from "
<<
filename_
<< std::endl;
34
35
// register the products
36
produces<FEDRawDataCollection>();
37
}
38
39
TextToRaw::~TextToRaw
() {
40
// do anything here that needs to be done at desctruction time
41
// (e.g. close files, deallocate resources etc.)
42
}
43
45
void
TextToRaw::putEmptyDigi
(
edm::Event
&
iEvent
) {
46
std::unique_ptr<FEDRawDataCollection> rawColl(
new
FEDRawDataCollection
());
47
// FEDRawData& feddata=rawColl->FEDData(fedId_);
48
// feddata.data()[0] = 0;
49
iEvent
.put(
std::move
(rawColl));
50
}
51
52
// ------------ method called to produce the data ------------
53
void
TextToRaw::produce
(
edm::Event
&
iEvent
,
const
edm::EventSetup
&iSetup) {
54
using namespace
edm
;
55
56
// Skip event if required
57
if
(
nevt_
<
fileEventOffset_
) {
58
putEmptyDigi
(
iEvent
);
59
nevt_
++;
60
return
;
61
}
else
if
(
nevt_
== 0 &&
fileEventOffset_
< 0) {
62
std::string
line
;
63
// skip first fileEventOffset input crossings
64
for
(
unsigned
i
= 0;
i
< (unsigned)
abs
(
fileEventOffset_
);
i
++) {
65
unsigned
iline
= 0;
66
while
(getline(
file_
,
line
) && !
line
.empty()) {
67
iline
++;
68
if
(
iline
* 4 >=
EVT_MAX_SIZE
)
69
throw
cms::Exception
(
"TextToRawEventSizeOverflow"
) <<
"TextToRaw::produce() : "
70
<<
" read too many lines ("
<<
iline
<<
": "
<<
line
<<
")"
71
<<
", maximum event size is "
<<
EVT_MAX_SIZE
<< std::endl;
72
}
73
}
74
}
75
76
nevt_
++;
77
78
// read file
79
std::string
line
;
80
unsigned
i
= 0;
// count 32-bit words
81
82
// while not encountering dumb errors
83
while
(getline(
file_
,
line
) && !
line
.empty()) {
84
// bail if we reached the EVT_MAX_SIZE
85
if
(
i
* 4 >=
EVT_MAX_SIZE
) {
86
throw
cms::Exception
(
"TextToRaw"
) <<
"Read too many lines from file. Maximum event size is "
<<
EVT_MAX_SIZE
87
<<
" lines"
<< std::endl;
88
}
89
90
// convert string to int
91
std::istringstream iss(
line
);
92
unsigned
long
d
;
93
iss >> std::hex >>
d
;
94
95
// copy data
96
for
(
int
j
= 0;
j
< 4;
j
++) {
97
if
((
i
* 4 +
j
) <
EVT_MAX_SIZE
) {
98
char
c
= (
d
>> (8 *
j
)) & 0xff;
99
data_
[
i
* 4 +
j
] =
c
;
100
}
101
}
102
103
++
i
;
104
105
// bail if we reached the EVT_MAX_SIZE
106
if
(
i
>=
EVT_MAX_SIZE
) {
107
throw
cms::Exception
(
"TextToRaw"
) <<
"Read too many lines from file. Maximum event size is "
<<
EVT_MAX_SIZE
108
<<
" lines"
<< std::endl;
109
}
110
}
111
112
unsigned
evtSize =
i
* 4;
113
114
// create the collection
115
std::unique_ptr<FEDRawDataCollection> rawColl(
new
FEDRawDataCollection
());
116
// retrieve the target buffer
117
FEDRawData
&feddata = rawColl->FEDData(
fedId_
);
118
// Allocate space for header+trailer+payload
119
feddata.
resize
(evtSize);
120
121
// fill FEDRawData object
122
for
(
unsigned
i
= 0;
i
< evtSize; ++
i
) {
123
feddata.
data
()[
i
] =
data_
[
i
];
124
}
125
126
// put the collection in the event
127
iEvent
.put(
std::move
(rawColl));
128
}
129
130
// ------------ method called once each job just before starting event loop
131
// ------------
132
void
TextToRaw::beginJob
() {
133
// open VME file
134
file_
.open(
filename_
.c_str(),
std::ios::in
);
135
if
(!
file_
.good()) {
136
edm::LogInfo
(
"TextToDigi"
) <<
"Failed to open ASCII file "
<<
filename_
<< std::endl;
137
}
138
}
139
140
// ------------ method called once each job just after ending the event loop
141
// ------------
142
void
TextToRaw::endJob
() {
file_
.close(); }
TextToRaw::data_
char data_[EVT_MAX_SIZE]
Definition:
TextToRaw.h:61
mps_fire.i
i
Definition:
mps_fire.py:428
MessageLogger.h
TextToRaw::TextToRaw
TextToRaw(const edm::ParameterSet &)
Definition:
TextToRaw.cc:28
edm
HLT enums.
Definition:
AlignableModifier.h:19
gather_cfg.cout
cout
Definition:
gather_cfg.py:144
edm::LogInfo
Log< level::Info, false > LogInfo
Definition:
MessageLogger.h:125
TextToRaw::EVT_MAX_SIZE
static const unsigned EVT_MAX_SIZE
Definition:
TextToRaw.h:60
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
EcalFEDMonitor_cfi.FEDRawDataCollection
FEDRawDataCollection
Definition:
EcalFEDMonitor_cfi.py:6
TextToRaw::fedId_
int fedId_
Definition:
TextToRaw.h:53
TextToRaw::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition:
TextToRaw.cc:53
edm::ParameterSet
Definition:
ParameterSet.h:47
TextToRaw::nevt_
int nevt_
Definition:
TextToRaw.h:64
TextToRaw::putEmptyDigi
void putEmptyDigi(edm::Event &)
Append empty digi collection.
Definition:
TextToRaw.cc:45
recoMuon::in
Definition:
RecoMuonEnumerators.h:6
createfilelist.int
int
Definition:
createfilelist.py:10
TextToRaw::endJob
void endJob() override
Definition:
TextToRaw.cc:142
iEvent
int iEvent
Definition:
GenABIO.cc:224
ntuplemaker.iline
iline
Definition:
ntuplemaker.py:186
FEDRawDataCollection.h
trackerHitRTTI::vector
Definition:
trackerHitRTTI.h:21
edm::EventSetup
Definition:
EventSetup.h:58
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition:
AlCaHLTBitMon_QueryRunRegistry.py:256
TextToRaw::beginJob
void beginJob() override
Definition:
TextToRaw.cc:132
eostools.move
def move(src, dest)
Definition:
eostools.py:511
std
Definition:
JetResolutionObject.h:76
TextToRaw::filename_
std::string filename_
Definition:
TextToRaw.h:56
TextToRaw::~TextToRaw
~TextToRaw() override
Definition:
TextToRaw.cc:39
Exception
Definition:
hltDiff.cc:245
FEDRawData::resize
void resize(size_t newsize)
Definition:
FEDRawData.cc:28
Exception.h
ztail.d
d
Definition:
ztail.py:151
funct::abs
Abs< T >::type abs(const T &t)
Definition:
Abs.h:22
c
auto & c
Definition:
CAHitNtupletGeneratorKernelsImpl.h:56
dqmiolumiharvest.j
j
Definition:
dqmiolumiharvest.py:66
edm::Event
Definition:
Event.h:73
mps_splice.line
line
Definition:
mps_splice.py:76
EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.cerr
cerr
Definition:
EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.py:8
TextToRaw.h
TextToRaw::file_
std::ifstream file_
Definition:
TextToRaw.h:57
TextToRaw::fileEventOffset_
int fileEventOffset_
Definition:
TextToRaw.h:63
Generated for CMSSW Reference Manual by
1.8.16