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 //
15 //
16 
18 #include "FWCore/ServiceRegistry/interface/Service.h" // Framework services
20 
21 using namespace edm;
22 using namespace std;
23 
24 // Set constants
25 const static unsigned NUM_LINES_PER_EVENT = 63;
26 const static int NUM_RCT_CRATES = 18;
27 
29  m_textFileName(iConfig.getParameter<std::string>("TextFileName")),
30  m_fileEventOffset(iConfig.getParameter<int>("fileEventOffset")),
31  m_nevt(0)
32 {
33  // Produces collections
34  produces<L1CaloEmCollection>();
35  produces<L1CaloRegionCollection>();
36 
37  // Open the input file
38  m_file.open(m_textFileName.c_str(),std::ios::in);
39 
40  if(!m_file.good())
41  {
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 }
51 
53 {
54  // Close the input file
55  m_file.close();
56 }
57 
60  std::auto_ptr<L1CaloEmCollection> em (new L1CaloEmCollection);
61  std::auto_ptr<L1CaloRegionCollection> rgn (new L1CaloRegionCollection);
62  for (int i=0; i<NUM_RCT_CRATES; i++){
63  for (int j=0; j<4; j++) {
64  em->push_back(L1CaloEmCand(0, i, true));
65  em->push_back(L1CaloEmCand(0, i, false));
66  }
67  for (int j=0; j<14; j++)
68  rgn->push_back(L1CaloRegion(0,false,false,false,false,i,j/2,j%2));
69  for (unsigned j=0; j<8; j++)
70  rgn->push_back(L1CaloRegion(0,true,i,j));
71  }
72  iEvent.put(em);
73  iEvent.put(rgn);
74 }
75 
76 // ------------ method called to produce the data ------------
78 {
79  // Skip event if required
81  // std::string tmp;
82  // for (unsigned i=0;i<NUM_LINES_PER_EVENT;i++){
83  //getline(m_file,tmp);
84  //}
85  putEmptyDigi(iEvent);
86  m_nevt++;
87  return;
88  } else if (m_nevt==0 && m_fileEventOffset<0) {
89  //skip first fileEventOffset input events
91  for(int i=0;i<abs(m_fileEventOffset); i++)
92  for (unsigned line=0; line<NUM_LINES_PER_EVENT; line++)
93  if(!getline(m_file,tmp))
94  {
95  throw cms::Exception("SourceCardTextToRctDigiTextFileReadError")
96  << "SourceCardTextToRctDigi::produce() : "
97  << " couldn't read from the file " << m_textFileName << std::endl;
98  }
99  }
100 
101 
102  // New collections
103  std::auto_ptr<L1CaloEmCollection> em (new L1CaloEmCollection);
104  std::auto_ptr<L1CaloRegionCollection> rgn (new L1CaloRegionCollection);
105 
106  // General variables
107  unsigned long VHDCI[2][2];
108  int routingMode;
109  int crate;
110  std::string dataString;
111  unsigned short eventNumber;
112  unsigned short logicalCardID;
113 
114  // Arrays to hold electron variables
115  unsigned short eIsoRank[18][4];
116  unsigned short eIsoCardId[18][4];
117  unsigned short eIsoRegionId[18][4];
118  unsigned short eNonIsoRank[18][4];
119  unsigned short eNonIsoCardId[18][4];
120  unsigned short eNonIsoRegionId[18][4];
121 
122  // Arrays to hold region variables
123  unsigned short RC[18][7][2];
124  unsigned short RCof[18][7][2];
125  unsigned short RCtau[18][7][2];
126  unsigned short MIPbits[18][7][2];
127  unsigned short Qbits[18][7][2];
128  unsigned short HF[18][4][2];
129  unsigned short HFQ[18][4][2];
130 
131  // Check we're not at the end of the file
132  if(m_file.eof())
133  {
134  throw cms::Exception("SourceCardTextToRctDigiTextFileReadError")
135  << "SourceCardTextToRctDigi::produce : "
136  << " unexpected end of file " << m_textFileName << std::endl;
137  }
138 
139  int thisEventNumber=-1;
140  // Read in file one line at a time
141  for (unsigned line=0; line<NUM_LINES_PER_EVENT; line++){
142 
143  if(!getline(m_file,dataString))
144  {
145  throw cms::Exception("SourceCardTextToRctDigiTextFileReadError")
146  << "SourceCardTextToRctDigi::SourceCardTextToRctDigi : "
147  << " couldn't read from the file " << m_textFileName << std::endl;
148  }
149 
150  // Convert the string to useful info
151  m_scRouting.STRINGtoVHDCI(logicalCardID,eventNumber,dataString,VHDCI);
152 
153  // Check crossing number
154  if(line!=0) assert(eventNumber==thisEventNumber);
155  thisEventNumber = eventNumber;
156 
157  // Are we looking at electrons or regions
158  m_scRouting.LogicalCardIDtoRoutingMode(logicalCardID,routingMode,crate);
159 
160  if (routingMode==0){
161 
162  // Electrons
163  m_scRouting.VHDCItoEMU(eIsoRank[crate],eIsoCardId[crate],eIsoRegionId[crate],
164  eNonIsoRank[crate],eNonIsoCardId[crate],eNonIsoRegionId[crate],
165  MIPbits[crate],Qbits[crate],VHDCI);
166 
167  } else if (routingMode==1) {
168 
169  // Regions
170  m_scRouting.VHDCItoRC56HF(RC[crate],RCof[crate],RCtau[crate],HF[crate],HFQ[crate],VHDCI);
171 
172  } else if (routingMode==2) {
173 
174  // Regions
175  m_scRouting.VHDCItoRC012(RC[crate],RCof[crate],RCtau[crate],VHDCI);
176 
177  } else if (routingMode==3) {
178 
179  // Regions
180  m_scRouting.VHDCItoRC234(RC[crate],RCof[crate],RCtau[crate],RC[crate+9],RCof[crate+9],RCtau[crate+9],VHDCI);
181 
182  } else {
183  // Something went wrong
184  throw cms::Exception("SourceCardtextToRctDigiError")
185  << "SourceCardTextToRctDigi::produce : "
186  << " unknown routing mode=" << routingMode << std::endl;
187  }
188  }
189 
190  // Make RCT digis
191  for (crate=0; crate<NUM_RCT_CRATES; crate++){
192 
193  // Make EM collections
194  for (int i=0; i<4; i++){
195  em->push_back(L1CaloEmCand(eIsoRank[crate][i],eIsoRegionId[crate][i],eIsoCardId[crate][i],crate,true,i,0));
196  em->push_back(L1CaloEmCand(eNonIsoRank[crate][i],eNonIsoRegionId[crate][i],eNonIsoCardId[crate][i],crate,false,i,0));
197  }
198 
199  // Make region collections
200  for (int i=0; i<7; i++){// Receiver card
201  for (int j=0; j<2; j++){// Region
202  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));
203  }
204  }
205 
206  // Make HF region collections
207  for (int i=0; i<4; i++){// Eta bin
208  for (int j=0; j<2; j++){// HF0, HF1
209  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
210  }
211  }
212  }
213 
214  // Debug info
215  for (L1CaloEmCollection::const_iterator iem=em->begin(); iem!=em->end(); iem++){
216  LogDebug("Electrons") << (*iem);
217  }
218 
219  for (L1CaloRegionCollection::const_iterator irgn=rgn->begin(); irgn!=rgn->end(); irgn++){
220  LogDebug("HFRegions") << (*irgn);
221  }
222 
223  iEvent.put(em);
224  iEvent.put(rgn);
225 
226  m_nevt++;
227 }
228 
#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.
assert(m_qm.get())
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
Level-1 Region Calorimeter Trigger EM candidate.
Definition: L1CaloEmCand.h:18
int const HF
Definition: Constants.h:86
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
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
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
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