CMS 3D CMS Logo

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