]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/STEER/AliCTPRawData.cxx
CTP raw data simulation changed to Run2 payload.
[u/mrichter/AliRoot.git] / STEER / STEER / AliCTPRawData.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-2003, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 ////////////////////////////////////////////////////////////
17 //This class contains the methods to create raw data                //
18 //for CTP (trigger). The CTP data format is taken as                //
19 //described in the Trigger TDR - pages 134  and 135.                //
20 //The updated version of raw data is in:                            //
21 //http://epweb2.ph.bham.ac.uk/user/krivda/alice/ctp/ctp_readout1.pdf//
22 //////////////////////////////////////////////////////////
23
24 #include <TObject.h>
25 #include <TString.h>
26 #include <Riostream.h>
27 #include "AliCTPRawData.h"
28 #include "AliRunLoader.h"
29 #include "AliCentralTrigger.h"
30 #include "AliLog.h"
31 #include "AliDAQ.h"
32 #include "AliFstream.h"
33
34 ClassImp(AliCTPRawData)
35 ////////////////////////////////////////////////////////////////////////////////////////
36
37 //______________________________________________________________________________
38 AliCTPRawData::AliCTPRawData()
39 {
40   // Default constructor
41 }
42
43 //______________________________________________________________________________
44 AliCTPRawData::AliCTPRawData(const AliCTPRawData &source):
45   TObject(source)
46 {
47   // Copy Constructor
48 }
49
50 //______________________________________________________________________________
51 AliCTPRawData& AliCTPRawData::operator=(const AliCTPRawData &source)
52 {
53   // Assigment operator
54   if(this==&source) return *this;
55   ((TObject *)this)->operator=(source);
56  
57  return *this;
58 }
59
60 //______________________________________________________________________________
61 void AliCTPRawData::RawData()
62 {
63   // This method writes the CTP (trigger)
64   // raw data in a DDL file
65   // run1 payload
66   ULong64_t l2class = 0;
67   UChar_t l2cluster = 0;
68   UInt_t l0input = 0;
69   UInt_t l1input = 0;
70   UShort_t l2input=0;
71   AliInfo("Storing the CTP DDL raw data...");
72   AliRunLoader *runloader = AliRunLoader::Instance();
73   if (runloader) {
74     if (!runloader->LoadTrigger()) {
75       AliCentralTrigger *aCTP = runloader->GetTrigger();
76       if (AliDebugLevel() > 0)
77         aCTP->Dump();
78       // First get the trigger mask
79       l2class = aCTP->GetClassMask();
80       // Then get the detector cluster to be read out
81       l2cluster = aCTP->GetClusterMask();
82       // Then get the input cluster mask
83       l0input = aCTP->GetL0TriggerInputs();
84       l1input = aCTP->GetL1TriggerInputs();
85       l2input = aCTP->GetL2TriggerInputs();
86     }
87     else
88       AliWarning("No trigger can be loaded! Putting empty trigger class into the CTP raw data !");
89   }
90   else
91     AliError("No run loader is available! Putting empty trigger class into the CTP raw data !");
92
93   AliDebug(1,Form("CTP trigger mask = 0x%llx",l2class));
94   AliDebug(1,Form("CTP detector cluster = 0x%x",l2cluster));
95
96   TString fileName = AliDAQ::DdlFileName("TRG",0);
97   AliInfo(Form("Storing CTP raw data in %s",fileName.Data()));
98   AliFstream* outfile;         // logical name of the output file 
99   outfile = new AliFstream(fileName.Data());
100
101   // Writing CTP raw data here
102   // The format is taken as in
103   // dhttp://epweb2.ph.bham.ac.uk/user/krivda/alice/ctp/ctp_readout1.pdf
104
105   // If not 0, from where??
106   UInt_t bunchCross = 0;
107   UInt_t orbitId = 0;
108   Bool_t esr = 0; // Enable Segmented Readout flag
109
110   // First 3 words here - Bunch-crossing and orbit numbers
111   UInt_t word = 0;
112   word |= 0 << 15; // BlockID = 0 in case of CTP readout
113   word |= bunchCross & 0xFFF;
114   AliDebug(1,Form("CTP word1 = 0x%x",word));
115   outfile->WriteBuffer((char*)(&word),sizeof(UInt_t));
116
117   word = 0;
118   word |= 0 << 15; // BlockID = 0 in case of CTP readout
119   word |= (orbitId >> 12) & 0xFFF;
120   AliDebug(1,Form("CTP word2 = 0x%x",word));
121   outfile->WriteBuffer((char*)(&word),sizeof(UInt_t));
122   word = 0;
123   word |= 0 << 15; // BlockID = 0 in case of CTP readout
124   word |= orbitId & 0xFFF;
125   AliDebug(1,Form("CTP word3 = 0x%x",word));
126   outfile->WriteBuffer((char*)(&word),sizeof(UInt_t));
127
128   // Now the 4th word
129   word = 0;
130   word |= 0 << 15; // BlockID = 0 in case of CTP readout
131   word |= ((UInt_t)esr) << 10;
132   word |= 0 << 8; // L2SwC - physics trigger
133   word |= (l2cluster & 0x3F) << 2; // L2Cluster
134   word |= (UInt_t)((l2class >> 48) & 0x3);
135   AliDebug(1,Form("CTP word4 = 0x%x",word));
136   outfile->WriteBuffer((char*)(&word),sizeof(UInt_t));
137
138   // Then the  4 words with the trigger classes
139   word = 0;
140   word |= 0 << 15; // BlockID = 0 in case of CTP readout
141   word |= (UInt_t)((l2class >> 36) & 0xFFF);
142   AliDebug(1,Form("CTP word5 = 0x%x",word));
143   outfile->WriteBuffer((char*)(&word),sizeof(UInt_t));
144   word = 0;
145   word |= 0 << 15; // BlockID = 0 in case of CTP readout
146   word |= (UInt_t)((l2class >> 24) & 0xFFF);
147   AliDebug(1,Form("CTP word6 = 0x%x",word));
148   outfile->WriteBuffer((char*)(&word),sizeof(UInt_t));
149   word = 0;
150   word |= 0 << 15; // BlockID = 0 in case of CTP readout
151   word |= (UInt_t)((l2class >> 12) & 0xFFF);
152   AliDebug(1,Form("CTP word7 = 0x%x",word));
153   outfile->WriteBuffer((char*)(&word),sizeof(UInt_t));
154   word = 0;
155   word |= 0 << 15; // BlockID = 0 in case of CTP readout
156   word |= (UInt_t)(l2class & 0xFFF);
157   AliDebug(1,Form("CTP word8 = 0x%x",word));
158   outfile->WriteBuffer((char*)(&word),sizeof(UInt_t));
159
160   // The last 5 words with trigger inputs
161   word = 0;
162   word |= 0 << 15; // BlockID = 0 in case of CTP readout
163   word |= (UInt_t)((l0input >> 12) & 0xFFF);
164   AliDebug(1,Form("CTP word9 = 0x%x",word));
165   outfile->WriteBuffer((char*)(&word),sizeof(UInt_t));
166   word = 0;
167   word |= 0 << 15; // BlockID = 0 in case of CTP readout
168   word |= (UInt_t)((l0input >> 0) & 0xFFF);
169   AliDebug(1,Form("CTP word10 = 0x%x",word));
170   outfile->WriteBuffer((char*)(&word),sizeof(UInt_t));
171   word = 0;
172   word |= 0 << 15; // BlockID = 0 in case of CTP readout
173   word |= (UInt_t)((l1input >> 12) & 0xFFF);
174   AliDebug(1,Form("CTP word11 = 0x%x",word));
175   outfile->WriteBuffer((char*)(&word),sizeof(UInt_t));
176   word = 0;
177   word |= 0 << 15; // BlockID = 0 in case of CTP readout
178   word |= (UInt_t)((l1input >> 0) & 0xFFF);
179   AliDebug(1,Form("CTP word12 = 0x%x",word));
180   outfile->WriteBuffer((char*)(&word),sizeof(UInt_t));
181   word = 0;
182   word |= 0 << 15; // BlockID = 0 in case of CTP readout
183   word |= (UInt_t)((l2input >> 0) & 0xFFF);
184   AliDebug(1,Form("CTP word13 = 0x%x",word));
185   outfile->WriteBuffer((char*)(&word),sizeof(UInt_t));
186   
187   delete outfile;
188
189   return;
190 }
191 //______________________________________________________________________________
192 void AliCTPRawData::RawDataRun2()
193 {
194   // This method writes the CTP (trigger)
195   // raw data in a DDL file
196   // New payload for run2 50 more classes, 2 more clusters 
197   ULong64_t l2class = 0;
198   ULong64_t l2classNext50 = 0;
199   UChar_t l2cluster = 0;
200   UInt_t l0input = 0;
201   UInt_t l1input = 0;
202   UShort_t l2input=0;
203   AliInfo("Storing the CTP DDL raw data...");
204   AliRunLoader *runloader = AliRunLoader::Instance();
205   if (runloader) {
206     if (!runloader->LoadTrigger()) {
207       AliCentralTrigger *aCTP = runloader->GetTrigger();
208       if (AliDebugLevel() > 0)
209         aCTP->Dump();
210       // First get the trigger mask
211       l2class = aCTP->GetClassMask();
212       l2classNext50 = aCTP->GetClassMaskNext50();
213       // Then get the detector cluster to be read out
214       l2cluster = aCTP->GetClusterMask();
215       // Then get the input cluster mask
216       l0input = aCTP->GetL0TriggerInputs();
217       l1input = aCTP->GetL1TriggerInputs();
218       l2input = aCTP->GetL2TriggerInputs();
219     }
220     else
221       AliWarning("No trigger can be loaded! Putting empty trigger class into the CTP raw data !");
222   }
223   else
224     AliError("No run loader is available! Putting empty trigger class into the CTP raw data !");
225
226   AliDebug(1,Form("CTP trigger mask = 0x%llx",l2class));
227   AliDebug(1,Form("CTP detector cluster = 0x%x",l2cluster));
228
229   TString fileName = AliDAQ::DdlFileName("TRG",0);
230   AliInfo(Form("Storing CTP raw data in %s",fileName.Data()));
231   AliFstream* outfile;         // logical name of the output file 
232   outfile = new AliFstream(fileName.Data());
233
234   // Writing CTP raw data here
235   // The format is taken as in
236   // dhttp://epweb2.ph.bham.ac.uk/user/krivda/alice/ctp/ctp_readout1.pdf
237
238   // If not 0, from where??
239   UInt_t bunchCross = 0;
240   UInt_t orbitId = 0;
241   Bool_t esr = 0; // Enable Segmented Readout flag
242
243   // First 3 words here - Bunch-crossing and orbit numbers
244   UInt_t word = 0;
245   word |= 0 << 15; // BlockID = 0 in case of CTP readout
246   word |= bunchCross & 0xFFF;
247   AliDebug(1,Form("CTP word1 = 0x%x",word));
248   outfile->WriteBuffer((char*)(&word),sizeof(UInt_t));
249
250   word = 0;
251   word |= 0 << 15; // BlockID = 0 in case of CTP readout
252   word |= (orbitId >> 12) & 0xFFF;
253   AliDebug(1,Form("CTP word2 = 0x%x",word));
254   outfile->WriteBuffer((char*)(&word),sizeof(UInt_t));
255   word = 0;
256   word |= 0 << 15; // BlockID = 0 in case of CTP readout
257   word |= orbitId & 0xFFF;
258   AliDebug(1,Form("CTP word3 = 0x%x",word));
259   outfile->WriteBuffer((char*)(&word),sizeof(UInt_t));
260
261   // Now the 4th word
262   word = 0;
263   word |= 0 << 15; // BlockID = 0 in case of CTP readout
264   word |= 1<<11;   // version 1=run2
265   word |= ((UInt_t)esr) << 10;
266   word |= 0 << 8; // L2SwC - physics trigger
267   word |= (l2cluster & 0x3F) << 2; // L2Cluster 1-6
268   word |= (l2cluster & 0xc0) >> 6; // L2cluster 7-8
269   AliDebug(1,Form("CTP word4 = 0x%x",word));
270   outfile->WriteBuffer((char*)(&word),sizeof(UInt_t));
271
272   // Then the 9 words with the trigger classes
273   word = 0;
274   word |= 0 << 15; // BlockID = 0 in case of CTP readout
275   word |= (UInt_t)((l2classNext50 >>46) & 0xF);  //5 100..97
276   AliDebug(1,Form("CTP word5 = 0x%x",word));
277   outfile->WriteBuffer((char*)(&word),sizeof(UInt_t));
278   word = 0;
279   word |= 0 << 15; // BlockID = 0 in case of CTP readout
280   word |= (UInt_t)((l2classNext50 >> 44) & 0xFFF);  //6 96..85
281   AliDebug(1,Form("CTP word6 = 0x%x",word));
282   outfile->WriteBuffer((char*)(&word),sizeof(UInt_t));
283   word = 0;
284   word |= 0 << 15; // BlockID = 0 in case of CTP readout
285   word |= (UInt_t)((l2classNext50 >> 22) & 0xFFF);  //7 84..73
286   AliDebug(1,Form("CTP word7 = 0x%x",word));
287   outfile->WriteBuffer((char*)(&word),sizeof(UInt_t));
288   word = 0;
289   word |= 0 << 15; // BlockID = 0 in case of CTP readout
290   word |= (UInt_t)((l2classNext50 >> 10) & 0xFFF);   //8 72..61
291   AliDebug(1,Form("CTP word8 = 0x%x",word));
292   outfile->WriteBuffer((char*)(&word),sizeof(UInt_t));
293   word = 0;
294   word |= 0 << 15; // BlockID = 0 in case of CTP readout
295   word |= (UInt_t)(l2classNext50 & 0x7FF);   //9 61..51
296   word |= (UInt_t)((l2class >> 48) & 0x3);   //9 50..49
297   AliDebug(1,Form("CTP word9 = 0x%x",word));
298   outfile->WriteBuffer((char*)(&word),sizeof(UInt_t));
299   word = 0;
300   word |= 0 << 15; // BlockID = 0 in case of CTP readout
301   word |= (UInt_t)((l2class >> 36) & 0xFFF);   //10 48..37
302   AliDebug(1,Form("CTP word10 = 0x%x",word));
303   outfile->WriteBuffer((char*)(&word),sizeof(UInt_t));
304   word = 0;
305   word |= 0 << 15; // BlockID = 0 in case of CTP readout
306   word |= (UInt_t)((l2class >> 24) & 0xFFF);   //11 36..25 
307   AliDebug(1,Form("CTP word11 = 0x%x",word));
308   outfile->WriteBuffer((char*)(&word),sizeof(UInt_t));
309   word = 0;
310   word |= 0 << 15; // BlockID = 0 in case of CTP readout
311   word |= (UInt_t)((l2class >> 12) & 0xFFF);   //12 24-13 
312   AliDebug(1,Form("CTP word12 = 0x%x",word));
313   outfile->WriteBuffer((char*)(&word),sizeof(UInt_t));
314   word = 0;
315   word |= 0 << 15; // BlockID = 0 in case of CTP readout
316   word |= (UInt_t)(l2class & 0xFFF);   //13 12..1 
317   AliDebug(1,Form("CTP word13 = 0x%x",word));
318   outfile->WriteBuffer((char*)(&word),sizeof(UInt_t));
319
320   // The last 5 words with trigger inputs
321   word = 0;
322   word |= 0 << 15; // BlockID = 0 in case of CTP readout
323   word |= (UInt_t)((l0input >> 12) & 0xFFF);
324   AliDebug(1,Form("CTP word9 = 0x%x",word));
325   outfile->WriteBuffer((char*)(&word),sizeof(UInt_t));
326   word = 0;
327   word |= 0 << 15; // BlockID = 0 in case of CTP readout
328   word |= (UInt_t)((l0input >> 0) & 0xFFF);
329   AliDebug(1,Form("CTP word10 = 0x%x",word));
330   outfile->WriteBuffer((char*)(&word),sizeof(UInt_t));
331   word = 0;
332   word |= 0 << 15; // BlockID = 0 in case of CTP readout
333   word |= (UInt_t)((l1input >> 12) & 0xFFF);
334   AliDebug(1,Form("CTP word11 = 0x%x",word));
335   outfile->WriteBuffer((char*)(&word),sizeof(UInt_t));
336   word = 0;
337   word |= 0 << 15; // BlockID = 0 in case of CTP readout
338   word |= (UInt_t)((l1input >> 0) & 0xFFF);
339   AliDebug(1,Form("CTP word12 = 0x%x",word));
340   outfile->WriteBuffer((char*)(&word),sizeof(UInt_t));
341   word = 0;
342   word |= 0 << 15; // BlockID = 0 in case of CTP readout
343   word |= (UInt_t)((l2input >> 0) & 0xFFF);
344   AliDebug(1,Form("CTP word13 = 0x%x",word));
345   outfile->WriteBuffer((char*)(&word),sizeof(UInt_t));
346   
347   delete outfile;
348
349   return;
350 }