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