CMS 3D CMS Logo

SourceCardTextToRctDigi.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: SourceCardTextToRctDigi
4 // Class: SourceCardTextToRctDigi
5 //
13 //
14 // Original Author: Alex Tapper
15 // Created: Fri Mar 9 19:11:51 CET 2007
16 //
17 //
18 
20 #include "FWCore/ServiceRegistry/interface/Service.h" // Framework services
22 
23 using namespace edm;
24 using namespace std;
25 
26 // Set constants
27 const static unsigned NUM_LINES_PER_EVENT = 63;
28 const static int NUM_RCT_CRATES = 18;
29 
31  : m_textFileName(iConfig.getParameter<std::string>("TextFileName")),
32  m_fileEventOffset(iConfig.getParameter<int>("fileEventOffset")),
33  m_nevt(0) {
34  // Produces collections
35  produces<L1CaloEmCollection>();
36  produces<L1CaloRegionCollection>();
37 
38  // Open the input file
39  m_file.open(m_textFileName.c_str(), std::ios::in);
40 
41  if (!m_file.good()) {
42  throw cms::Exception("SourceCardTextToRctDigiTextFileOpenError")
43  << "SourceCardTextToRctDigi::SourceCardTextToRctDigi : "
44  << " couldn't open the file " << m_textFileName << " for reading" << std::endl;
45  }
46 
47  // Make a SC routing object
49 }
50 
52  // Close the input file
53  m_file.close();
54 }
55 
58  std::unique_ptr<L1CaloEmCollection> em(new L1CaloEmCollection);
59  std::unique_ptr<L1CaloRegionCollection> rgn(new L1CaloRegionCollection);
60  for (int i = 0; i < NUM_RCT_CRATES; i++) {
61  for (int j = 0; j < 4; j++) {
62  em->push_back(L1CaloEmCand(0, i, true));
63  em->push_back(L1CaloEmCand(0, i, false));
64  }
65  for (int j = 0; j < 14; j++)
66  rgn->push_back(L1CaloRegion(0, false, false, false, false, i, j / 2, j % 2));
67  for (unsigned j = 0; j < 8; j++)
68  rgn->push_back(L1CaloRegion(0, true, i, j));
69  }
70  iEvent.put(std::move(em));
71  iEvent.put(std::move(rgn));
72 }
73 
74 // ------------ method called to produce the data ------------
76  // Skip event if required
77  if (m_nevt < m_fileEventOffset) {
78  // std::string tmp;
79  // for (unsigned i=0;i<NUM_LINES_PER_EVENT;i++){
80  // getline(m_file,tmp);
81  //}
83  m_nevt++;
84  return;
85  } else if (m_nevt == 0 && m_fileEventOffset < 0) {
86  // skip first fileEventOffset input events
88  for (int i = 0; i < abs(m_fileEventOffset); i++)
89  for (unsigned line = 0; line < NUM_LINES_PER_EVENT; line++)
90  if (!getline(m_file, tmp)) {
91  throw cms::Exception("SourceCardTextToRctDigiTextFileReadError")
92  << "SourceCardTextToRctDigi::produce() : "
93  << " couldn't read from the file " << m_textFileName << std::endl;
94  }
95  }
96 
97  // New collections
98  std::unique_ptr<L1CaloEmCollection> em(new L1CaloEmCollection);
99  std::unique_ptr<L1CaloRegionCollection> rgn(new L1CaloRegionCollection);
100 
101  // General variables
102  unsigned long VHDCI[2][2];
103  int routingMode;
104  int crate;
105  std::string dataString;
106  unsigned short eventNumber;
107  unsigned short logicalCardID;
108 
109  // Arrays to hold electron variables
110  unsigned short eIsoRank[18][4];
111  unsigned short eIsoCardId[18][4];
112  unsigned short eIsoRegionId[18][4];
113  unsigned short eNonIsoRank[18][4];
114  unsigned short eNonIsoCardId[18][4];
115  unsigned short eNonIsoRegionId[18][4];
116 
117  // Arrays to hold region variables
118  unsigned short RC[18][7][2];
119  unsigned short RCof[18][7][2];
120  unsigned short RCtau[18][7][2];
121  unsigned short MIPbits[18][7][2];
122  unsigned short Qbits[18][7][2];
123  unsigned short HF[18][4][2];
124  unsigned short HFQ[18][4][2];
125 
126  // Check we're not at the end of the file
127  if (m_file.eof()) {
128  throw cms::Exception("SourceCardTextToRctDigiTextFileReadError")
129  << "SourceCardTextToRctDigi::produce : "
130  << " unexpected end of file " << m_textFileName << std::endl;
131  }
132 
133  int thisEventNumber = -1;
134  // Read in file one line at a time
135  for (unsigned line = 0; line < NUM_LINES_PER_EVENT; line++) {
136  if (!getline(m_file, dataString)) {
137  throw cms::Exception("SourceCardTextToRctDigiTextFileReadError")
138  << "SourceCardTextToRctDigi::SourceCardTextToRctDigi : "
139  << " couldn't read from the file " << m_textFileName << std::endl;
140  }
141 
142  // Convert the string to useful info
143  m_scRouting.STRINGtoVHDCI(logicalCardID, eventNumber, dataString, VHDCI);
144 
145  // Check crossing number
146  if (line != 0)
147  assert(eventNumber == thisEventNumber);
148  thisEventNumber = eventNumber;
149 
150  // Are we looking at electrons or regions
151  m_scRouting.LogicalCardIDtoRoutingMode(logicalCardID, routingMode, crate);
152 
153  if (routingMode == 0) {
154  // Electrons
155  m_scRouting.VHDCItoEMU(eIsoRank[crate],
156  eIsoCardId[crate],
157  eIsoRegionId[crate],
158  eNonIsoRank[crate],
159  eNonIsoCardId[crate],
160  eNonIsoRegionId[crate],
161  MIPbits[crate],
162  Qbits[crate],
163  VHDCI);
164 
165  } else if (routingMode == 1) {
166  // Regions
167  m_scRouting.VHDCItoRC56HF(RC[crate], RCof[crate], RCtau[crate], HF[crate], HFQ[crate], VHDCI);
168 
169  } else if (routingMode == 2) {
170  // Regions
171  m_scRouting.VHDCItoRC012(RC[crate], RCof[crate], RCtau[crate], VHDCI);
172 
173  } else if (routingMode == 3) {
174  // Regions
176  RC[crate], RCof[crate], RCtau[crate], RC[crate + 9], RCof[crate + 9], RCtau[crate + 9], VHDCI);
177 
178  } else {
179  // Something went wrong
180  throw cms::Exception("SourceCardtextToRctDigiError") << "SourceCardTextToRctDigi::produce : "
181  << " unknown routing mode=" << routingMode << std::endl;
182  }
183  }
184 
185  // Make RCT digis
186  for (crate = 0; crate < NUM_RCT_CRATES; crate++) {
187  // Make EM collections
188  for (int i = 0; i < 4; i++) {
189  em->push_back(L1CaloEmCand(eIsoRank[crate][i], eIsoRegionId[crate][i], eIsoCardId[crate][i], crate, true, i, 0));
190  em->push_back(
191  L1CaloEmCand(eNonIsoRank[crate][i], eNonIsoRegionId[crate][i], eNonIsoCardId[crate][i], crate, false, i, 0));
192  }
193 
194  // Make region collections
195  for (int i = 0; i < 7; i++) { // Receiver card
196  for (int j = 0; j < 2; j++) { // Region
197  rgn->push_back(L1CaloRegion::makeHBHERegion(RC[crate][i][j],
198  RCof[crate][i][j],
199  RCtau[crate][i][j],
200  MIPbits[crate][i][j],
201  Qbits[crate][i][j],
202  crate,
203  i,
204  j));
205  }
206  }
207 
208  // Make HF region collections
209  for (int i = 0; i < 4; i++) { // Eta bin
210  for (int j = 0; j < 2; j++) { // HF0, HF1
211  rgn->push_back(L1CaloRegion::makeHFRegion(HF[crate][i][j],
212  HFQ[crate][i][j],
213  crate,
214  i + (4 * j))); // region=eta+4*phi for eta 0-3
215  }
216  }
217  }
218 
219  // Debug info
220  for (L1CaloEmCollection::const_iterator iem = em->begin(); iem != em->end(); iem++) {
221  LogDebug("Electrons") << (*iem);
222  }
223 
224  for (L1CaloRegionCollection::const_iterator irgn = rgn->begin(); irgn != rgn->end(); irgn++) {
225  LogDebug("HFRegions") << (*irgn);
226  }
227 
228  iEvent.put(std::move(em));
229  iEvent.put(std::move(rgn));
230 
231  m_nevt++;
232 }
std::vector< L1CaloEmCand > L1CaloEmCollection
void VHDCItoRC234(unsigned short(&RC)[7][2], unsigned short(&RCof)[7][2], unsigned short(&RCtau)[7][2], unsigned short(&sisterRC)[7][2], unsigned short(&sisterRCof)[7][2], unsigned short(&sisterRCtau)[7][2], unsigned long(&VHDCI)[2][2]) const
void putEmptyDigi(edm::Event &)
Create empty digi collection.
void LogicalCardIDtoRoutingMode(unsigned short &logicalCardID, int &RoutingMode, int &RCTCrateNumber) const
SourceCardTextToRctDigi(const edm::ParameterSet &)
std::string m_textFileName
Name out input file.
static L1CaloRegion makeHBHERegion(const unsigned et, const bool overFlow, const bool tauVeto, const bool mip, const bool quiet, const unsigned crate, const unsigned card, const unsigned rgn)
constructor HB/HE region from components
Definition: L1CaloRegion.cc:49
Level-1 Region Calorimeter Trigger EM candidate.
Definition: L1CaloEmCand.h:17
assert(be >=bs)
void VHDCItoRC56HF(unsigned short(&RC)[7][2], unsigned short(&RCof)[7][2], unsigned short(&RCtau)[7][2], unsigned short(&HF)[4][2], unsigned short(&HFQ)[4][2], unsigned long(&VHDCI)[2][2]) const
int iEvent
Definition: GenABIO.cc:224
std::ifstream m_file
file handle
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void VHDCItoRC012(unsigned short(&RC)[7][2], unsigned short(&RCof)[7][2], unsigned short(&RCtau)[7][2], unsigned long(&VHDCI)[2][2]) const
void STRINGtoVHDCI(unsigned short &logicalCardID, unsigned short &eventNumber, std::string &dataString, unsigned long(&VHDCI)[2][2]) const
int m_fileEventOffset
Number of events to skip at the start of the file.
static const int NUM_RCT_CRATES
HLT enums.
SourceCardRouting m_scRouting
source card router
void VHDCItoEMU(unsigned short(&eIsoRank)[4], unsigned short(&eIsoCardId)[4], unsigned short(&eIsoRegionId)[4], unsigned short(&eNonIsoRank)[4], unsigned short(&eNonIsoCardId)[4], unsigned short(&eNonIsoRegionId)[4], unsigned short(&MIPbits)[7][2], unsigned short(&Qbits)[7][2], unsigned long(&VHDCI)[2][2]) const
static L1CaloRegion makeHFRegion(const unsigned et, const bool fineGrain, const unsigned crate, const unsigned rgn)
construct HF region from components
Definition: L1CaloRegion.cc:59
A calorimeter trigger region (sum of 4x4 trigger towers)
Definition: L1CaloRegion.h:21
static const unsigned NUM_LINES_PER_EVENT
std::vector< L1CaloRegion > L1CaloRegionCollection
void produce(edm::Event &, const edm::EventSetup &) override
tmp
align.sh
Definition: createJobs.py:716
def move(src, dest)
Definition: eostools.py:511
#define LogDebug(id)