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