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