CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
BlockFormatter.cc
Go to the documentation of this file.
1 #include <memory>
2 
3 // user include files
4 
5 
10 
11 
12 using namespace std;
13 
15 }
16 
18 }
19 
20 
22 
23  pcounter_ = (base -> GetCounter());
24  debug_ = base -> GetDebug();
25  porbit_number_ = (base -> GetOrbit());
26  plv1_ = (base -> GetLV1());
27  pbx_ = (base -> GetBX());
28  prunnumber_ = (base -> GetRunNumber());
29  doBarrel_ = base -> GetDoBarrel();
30  doEndCap_ = base -> GetDoEndCap();
31  plistDCCId_ = base -> GetListDCCId();
32  doTCC_ = base -> GetDoTCC();
33  doSR_ = base -> GetDoSR();
34  doTower_ = base -> GetDoTower();
35 
36 }
37 
38 
40 
41  int run_number = *prunnumber_;
42  int orbit_number_ = *porbit_number_;
43  int bx = *pbx_;
44  int lv1 = *plv1_;
45 
46  if (debug_) cout << "in BlockFormatter::DigiToRaw run_number orbit_number bx lv1 " << dec << run_number << " " <<
47  orbit_number_ << " " << bx << " " << lv1 << endl;
48 
49  for (int idcc=1; idcc <= 54; idcc++) {
50  if ( (! doBarrel_) &&
52  if ( (! doEndCap_) &&
53  (idcc <= EcalElectronicsId::MAX_DCCID_EEM || idcc >= EcalElectronicsId::MIN_DCCID_EEP)) continue;
54 
55  int FEDid = FEDNumbering::MINECALFEDID + idcc;
56  FEDRawData& rawdata = productRawData -> FEDData(FEDid);
57  unsigned char * pData;
58  short int DCC_ERRORS = 0;
59 
60  if (rawdata.size() == 0) {
61  rawdata.resize(8);
62  pData = rawdata.data();
63 
64  Word64 word = 0x18 + ((FEDid & 0xFFF)<<8)
65  + ((Word64)((Word64)bx & 0xFFF)<<20)
66  + ((Word64)((Word64)lv1 & 0xFFFFFF)<<32)
67  + (Word64)((Word64)0x51<<56);
68  Word64* pw = reinterpret_cast<Word64*>(const_cast<unsigned char*>(pData));
69  *pw = word; // DAQ header
70 
71  rawdata.resize(rawdata.size() + 8*8); // DCC header
72  pData = rawdata.data();
73  pData[11] = DCC_ERRORS & 0xFF;
74  pData[12] = run_number & 0xFF;
75  pData[13] = (run_number >>8) & 0xFF;
76  pData[14] = (run_number >> 16) & 0xFF;
77  pData[15] = 0x01;
78 
79  for (int i=16; i <= 22; i++) {
80  pData[i] = 0; // to be filled for local data taking or calibration
81  }
82  pData[23] = 0x02;
83  pData[24] = orbit_number_ & 0xFF;
84  pData[25] = (orbit_number_ >>8) & 0xFF;
85  pData[26] = (orbit_number_ >>16) & 0xFF;
86  pData[27] = (orbit_number_ >>24) & 0xFF;
87  int SRenable_ = 1;
88  int SR = SRenable_;
89  int ZS = 0;
90  int TZS = 0;
91  // int SR_CHSTATUS = 0;
92  pData[28] = (SR&0x1) + ((ZS&0x1)<<1) + ((TZS&0x1)<<2);
93  pData[31] = 0x03;
94 
95  for (int i=0; i<=4; i++) {
96  for (int j=0; j<7; j++) {
97  pData[32 +8*i + j] = 0;
98  }
99  pData[32 +8*i + 7] = 0x04;
100  }
101 
102  } // endif rawdatasize == 0
103  } // loop on id
104 
105 }
106 
107 
108 
110  int size = rawdata.size();
111  cout << "Print RawData size " << dec << size << endl;
112  unsigned char* pData = rawdata.data();
113 
114  int n = size/8;
115  for (int i=0; i < n; i++) {
116  for (int j=7; j>=0; j--) {
117  if (8*i+j <= size) cout << hex << (int)pData[8*i+j] << " ";
118  }
119  cout << endl;
120  }
121 }
122 
123 
124 
126  map<int, map<int,int> >* FEDorder ) {
127 
128 
129  for (int id=0; id < 36 + 18; id++) {
130  if ( (! doBarrel_) && (id >= 9 && id <= 44)) continue;
131  if ( (! doEndCap_) && (id <= 8 || id >= 45)) continue;
132 
133  int FEDid = FEDNumbering::MINECALFEDID + id +1;
134  FEDRawData& rawdata = productRawData -> FEDData(FEDid);
135 
136  // ---- if raw need not be made for a given fed, set its size to empty and return
137  if ( find( (*plistDCCId_).begin(), (*plistDCCId_).end(), (id+1) ) == (*plistDCCId_).end() )
138  {
139  rawdata.resize( 0 );
140  continue;
141  }
142 
143  // ---- Add the trailer word
144  int lastline = rawdata.size();
145  rawdata.resize( lastline + 8);
146  unsigned char * pData = rawdata.data();
147  int event_length = (lastline + 8) / 8; // in 64 bits words
148 
149  pData[lastline+7] = 0xa0;
150  // pData[lastline+4] = event_length & 0xFFFFFF;
151  pData[lastline+4] = event_length & 0xFF;
152  pData[lastline+5] = (event_length >> 8) & 0xFF;
153  pData[lastline+6] = (event_length >> 16) & 0xFF;
154  int event_status = 0;
155  pData[lastline+1] = event_status & 0x0F;
156  int tts = 0 <<4;
157  pData[lastline] = tts & 0xF0;
158 
159  // ---- Write the event length in the DCC header
160  // pData[8] = event_length & 0xFFFFFF;
161  pData[8] = event_length & 0xFF;
162  pData[9] = (event_length >> 8) & 0xFF;
163  pData[10] = (event_length >> 16) & 0xFF;
164 
165  // cout << " in BlockFormatter::CleanUp. FEDid = " << FEDid << " event_length*8 " << dec << event_length*8 << endl;
166 
167  map<int, map<int,int> >::iterator fen = FEDorder -> find(FEDid);
168 
169  bool FED_has_data = true;
170  if (fen == FEDorder->end()) FED_has_data = false;
171  if (debug_ && (! FED_has_data)) cout << " FEDid is not in FEDorder ! " << endl;
172  if ( ! FED_has_data) {
173  int ch_status = 7;
174  for (int iFE=1; iFE <= 68; iFE++) {
175  int irow = (iFE-1) / 14;
176  int kval = ( (iFE-1) % 14) / 2;
177  if (iFE % 2 ==1) pData[32 + 8*irow + kval] |= ch_status & 0xFF;
178  else pData[32 + 8*irow + kval] |= ((ch_status <<4) & 0xFF);
179  }
180  }
181 
182  if (FED_has_data) {
183  map<int, int>& FEorder = (*fen).second;
184 
185  for (int iFE=1; iFE <= 68; iFE++) {
186  map<int,int>::iterator fe = FEorder.find(iFE);
187  int ch_status = 0;
188  if (fe == FEorder.end()) // FE not present due to SRP, update CH_status
189  ch_status = 7; // CH_SUPPRESS
190  int irow = (iFE-1) / 14;
191  int kval = ( (iFE-1) % 14) / 2;
192  if (iFE % 2 ==1) pData[32 + 8*irow + kval] |= ch_status & 0xFF;
193  else pData[32 + 8*irow + kval] |= ((ch_status <<4) & 0xFF);
194 
195  }
196  }
197 
198  }
199 }
200 
201 
203 
204 
205  for (int id=0; id < 36 + 18; id++) {
206 
207  // if ( (! doBarrel_) && (id >= 9 && id <= 44)) continue;
208  // if ( (! doEndCap_) && (id <= 8 || id >= 45)) continue;
209 
210 
211  int FEDid = FEDNumbering::MINECALFEDID + id;
212  FEDRawData& rawdata = productRawData -> FEDData(FEDid);
213  if (rawdata.size() > 0)
214  cout << "Size of FED id " << dec << FEDid << " is : " << dec << rawdata.size() << endl;
215 
216  }
217 }
218 
219 
tuple base
Main Program
Definition: newFWLiteAna.py:92
int i
Definition: DBlmapReader.cc:9
void DigiToRaw(FEDRawDataCollection *productRawData)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
void print(FEDRawData &rawdata)
void CleanUp(FEDRawDataCollection *productRawData, std::map< int, std::map< int, int > > *FEDorder)
void PrintSizes(FEDRawDataCollection *productRawData)
void resize(size_t newsize)
Definition: FEDRawData.cc:32
static const int MAX_DCCID_EBP
static const int MIN_DCCID_EBM
int j
Definition: DBlmapReader.cc:9
uint64_t Word64
void SetParam(EcalDigiToRaw *base)
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
tuple cout
Definition: gather_cfg.py:121
dictionary rawdata
Definition: lumiPlot.py:393
tuple size
Write out results.
static const int MIN_DCCID_EEP