]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliCTPRawData.cxx
Moving the tag cut classes to base
[u/mrichter/AliRoot.git] / 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 ////////////////////////////////////////////////////////////
21
22 #include <TObject.h>
23 #include <TString.h>
24 #include <Riostream.h>
25 #include "AliCTPRawData.h"
26 #include "AliRunLoader.h"
27 #include "AliCentralTrigger.h"
28 #include "AliRawDataHeader.h"
29 #include "AliLog.h"
30 #include "AliDAQ.h"
31 #include "AliFstream.h"
32
33 ClassImp(AliCTPRawData)
34 ////////////////////////////////////////////////////////////////////////////////////////
35
36 //______________________________________________________________________________
37 AliCTPRawData::AliCTPRawData()
38 {
39   // Default constructor
40 }
41
42 //______________________________________________________________________________
43 AliCTPRawData::AliCTPRawData(const AliCTPRawData &source):
44   TObject(source)
45 {
46   // Copy Constructor
47 }
48
49 //______________________________________________________________________________
50 AliCTPRawData& AliCTPRawData::operator=(const AliCTPRawData &source)
51 {
52   // Assigment operator
53   if(this==&source) return *this;
54   ((TObject *)this)->operator=(source);
55  
56  return *this;
57 }
58
59 //______________________________________________________________________________
60 void AliCTPRawData::RawData()
61 {
62   // This method writes the CTP (trigger)
63   // raw data in a DDL file
64   ULong64_t l2class = 0;
65   UChar_t l2cluster = 0;
66   AliInfo("Storing the CTP DDL raw data...");
67   AliRunLoader *runloader = AliRunLoader::GetRunLoader();
68   if (runloader) {
69     if (!runloader->LoadTrigger()) {
70       AliCentralTrigger *aCTP = runloader->GetTrigger();
71       if (AliDebugLevel() > 0)
72         aCTP->Dump();
73       // First get the trigger mask
74       l2class = aCTP->GetClassMask();
75       // Then get the detector cluster to be read out
76       l2cluster = aCTP->GetClusterMask();
77     }
78     else
79       AliWarning("No trigger can be loaded! Putting empty trigger class into the CTP raw data !");
80   }
81   else
82     AliError("No run loader is available! Putting empty trigger class into the CTP raw data !");
83
84   AliDebug(1,Form("CTP trigger mask = 0x%llx",l2class));
85   AliDebug(1,Form("CTP detector cluster = 0x%x",l2cluster));
86
87   char  fileName[15];
88   strcpy(fileName,AliDAQ::DdlFileName("TRG",0));
89   AliInfo(Form("Storing CTP raw data in %s",fileName));
90   AliFstream* outfile;         // logical name of the output file 
91   outfile = new AliFstream(fileName);
92
93   AliRawDataHeader header;
94   // Write a dummy header
95   UInt_t dataHeaderPosition=outfile->Tellp();
96   outfile->WriteBuffer((char*)(&header),sizeof(header));
97
98   // Writing CTP raw data here
99   // The format is taken as in
100   // pages 134 and 135 of the
101   // Trigger TDR
102
103   // If not 0, from where??
104   UInt_t bunchCross = 0;
105   UInt_t orbitId = 0;
106   Bool_t esr = 0; // Enable Segmented Readout flag
107
108   // First 3 words here - Bunch-crossing and orbit numbers
109   UInt_t word = 0;
110   word |= 0 << 13; // BlockID = 0 in case of CTP readout
111   word |= bunchCross & 0xFFF;
112   AliDebug(1,Form("CTP word1 = 0x%x",word));
113   outfile->WriteBuffer((char*)(&word),sizeof(UInt_t));
114
115   word = 0;
116   word |= 0 << 13; // BlockID = 0 in case of CTP readout
117   word |= (orbitId >> 12) & 0xFFF;
118   AliDebug(1,Form("CTP word2 = 0x%x",word));
119   outfile->WriteBuffer((char*)(&word),sizeof(UInt_t));
120   word = 0;
121   word |= 0 << 13; // BlockID = 0 in case of CTP readout
122   word |= orbitId & 0xFFF;
123   AliDebug(1,Form("CTP word3 = 0x%x",word));
124   outfile->WriteBuffer((char*)(&word),sizeof(UInt_t));
125
126   // Now the 4th word
127   word = 0;
128   word |= 0 << 13; // BlockID = 0 in case of CTP readout
129   word |= ((UInt_t)esr) << 10;
130   word |= 0 << 8; // L2SwC - physics trigger
131   word |= (l2cluster & 0x3F) << 2; // L2Cluster
132   word |= (UInt_t)((l2class >> 48) & 0x3);
133   AliDebug(1,Form("CTP word4 = 0x%x",word));
134   outfile->WriteBuffer((char*)(&word),sizeof(UInt_t));
135
136   // Then the last 4 words with the trigger classes
137   word = 0;
138   word |= 0 << 13; // BlockID = 0 in case of CTP readout
139   word |= (UInt_t)((l2class >> 36) & 0xFFF);
140   AliDebug(1,Form("CTP word5 = 0x%x",word));
141   outfile->WriteBuffer((char*)(&word),sizeof(UInt_t));
142   word = 0;
143   word |= 0 << 13; // BlockID = 0 in case of CTP readout
144   word |= (UInt_t)((l2class >> 24) & 0xFFF);
145   AliDebug(1,Form("CTP word6 = 0x%x",word));
146   outfile->WriteBuffer((char*)(&word),sizeof(UInt_t));
147   word = 0;
148   word |= 0 << 13; // BlockID = 0 in case of CTP readout
149   word |= (UInt_t)((l2class >> 12) & 0xFFF);
150   AliDebug(1,Form("CTP word7 = 0x%x",word));
151   outfile->WriteBuffer((char*)(&word),sizeof(UInt_t));
152   word = 0;
153   word |= 0 << 13; // BlockID = 0 in case of CTP readout
154   word |= (UInt_t)(l2class & 0xFFF);
155   AliDebug(1,Form("CTP word8 = 0x%x",word));
156   outfile->WriteBuffer((char*)(&word),sizeof(UInt_t));
157
158   // Write the real data header
159   UInt_t currentFilePosition=outfile->Tellp();
160   outfile->Seekp(dataHeaderPosition);
161   header.fSize=currentFilePosition-dataHeaderPosition;
162   header.SetAttribute(0);  // valid data
163   header.SetTriggerClass(l2class);
164   outfile->WriteBuffer((char*)(&header),sizeof(header));
165   delete outfile;
166
167   return;
168 }