CMS 3D CMS Logo

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