3 TOF DA for online calibration from pulser data
5 Contact: Chiara.Zampolli@bo.infn.it
6 Link: www.bo.infn.it/~zampolli
9 Number of events needed: 10000
10 Input Files: TOF<nrun>.raw, where <nrun> is the run number
11 Output Files: TOFoutPulserLDC_<LDCid>.root, where <LDCid> is the id of the LDC which is read (2 characters field, e.g. TOFoutPulserLDC_03.root),to be exported to the DAQ FXS
12 Trigger types used: PHYSICS_EVENT, for the time being
25 #include <AliTOFRawStream.h>
26 #include <AliRawReaderDate.h>
27 #include <AliRawReader.h>
28 #include <AliTOFGeometry.h>
30 #include <AliTOFHitData.h>
31 #include <AliTOFHitDataBuffer.h>
32 #include <AliTOFDecoder.h>
42 #include "TPluginManager.h"
45 Arguments: list of DATE raw data files
47 int main(int argc, char **argv) {
49 /* magic line from Rene */
50 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
56 AliTOFGeometry * geom = new AliTOFGeometry();
58 static const Int_t size = AliTOFGeometry::NPadXSector()*AliTOFGeometry::NSectors();
59 TH1F::AddDirectory(0);
60 TH1I * htofPulser = new TH1I("hTOFpulser","histo with signals on TOF during pulser", size,-0.5,size-0.5);
61 for (Int_t ibin =1;ibin<=size;ibin++){
62 htofPulser->SetBinContent(ibin,-1);
69 /* log start of process */
70 printf("TOF DA started\n");
72 /* check that we got some arguments = list of files */
74 printf("Wrong number of arguments\n");
78 /* open result file */
80 fp=fopen("./result.txt","a");
82 printf("Failed to open file\n");
86 /* init some counters */
87 int nevents_physics=0;
90 /* read the data files */
92 for (n=1;n<argc;n++) {
94 status=monitorSetDataSource( argv[n] );
96 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
102 struct eventHeaderStruct *event;
103 eventTypeType eventT;
106 status=monitorGetEventDynamic((void **)&event);
107 if (status==MON_ERR_EOF) break; /* end of monitoring file has been reached */
109 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
113 /* retry if got no event */
118 /* use event - here, just write event id to result file */
119 eventT=event->eventType;
121 if (eventT==PHYSICS_EVENT) {
122 //printf ("event %i \n", nevents_physics);
123 Int_t nPDBEntriesToT = 0;
124 Int_t nDBEntriesToT = 0;
125 AliTOFHitData *HitData;
128 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
129 AliTOFRawStream *rawStreamTOF = new AliTOFRawStream(rawReader);
130 AliTOFDecoder * decoderTOF = new AliTOFDecoder();
131 AliTOFHitDataBuffer *DataBuffer[72];
132 AliTOFHitDataBuffer *PackedDataBuffer[72];
133 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
134 DataBuffer[i]=new AliTOFHitDataBuffer();
135 PackedDataBuffer[i]=new AliTOFHitDataBuffer();
137 Int_t currentEquipment;
140 while(rawReader->ReadHeader()){
141 ldcId = rawReader->GetLDCId();
142 //printf ("ldcId = %i \n",ldcId);
144 //memory leak prevention (actually data should be always 0x0 here)
145 if (data != 0x0)delete [] data;
147 //get equipment infos
148 currentEquipment = rawReader->GetEquipmentId();
149 currentDDL = rawReader->GetDDLID();
151 if (currentDDL%2==0) {
157 Int_t * array = new Int_t[nchDDL];
158 decoderTOF->GetArrayDDL(array, currentDDL);
160 for (Int_t i=0;i<nchDDL;i++){
161 if (htofPulser->GetBinContent(array[i]+1)<0) htofPulser->SetBinContent(array[i]+1,0);
164 //printf(" Equipment = %i, and DDL = %i \n", currentEquipment,currentDDL);
165 const Int_t kDataSize = rawReader->GetDataSize();
166 const Int_t kDataWords = kDataSize / 4;
167 data = new UChar_t[kDataSize];
168 decoderTOF->SetDataBuffer(DataBuffer[currentDDL]);
169 decoderTOF->SetPackedDataBuffer(PackedDataBuffer[currentDDL]);
171 if (!rawReader->ReadNext(data, kDataSize)){
172 rawReader->AddMajorErrorLog(AliTOFRawStream::kDDLdataReading);
173 printf("Error while reading DDL data. Go to next equipment \n");
178 if (decoderTOF->Decode((UInt_t *)data, kDataWords) == kTRUE) {
179 rawReader->AddMajorErrorLog(AliTOFRawStream::kDDLDecoder,Form("DDL # = %d",currentDDL));
180 printf("Error while decoding DDL # %d: decoder returned with errors \n", currentDDL);
183 Int_t nDBEntries = DataBuffer[currentDDL]->GetEntries();
184 Int_t nPDBEntries = PackedDataBuffer[currentDDL]->GetEntries();
185 nPDBEntriesToT+=nPDBEntries;
186 nDBEntriesToT+=nDBEntries;
188 DataBuffer[currentDDL]->Reset();
190 /* read data buffer hits */
191 for (Int_t iHit = 0; iHit < nPDBEntries; iHit++){
192 HitData = PackedDataBuffer[currentDDL]->GetHit(iHit);
193 /* add volume information */
194 HitData->SetDDLID(currentDDL);
195 rawStreamTOF->EquipmentId2VolumeId(HitData, Volume);
200 Volume[4]==-1) continue;
203 Volume[3] = Volume[4];
205 Int_t index = geom->GetIndex(Volume);
206 //printf ("index = %i \n",index);
207 htofPulser->Fill(index); //channel index start from 0, bin index from 1
208 //debugging printings
209 //printf("sector %i, plate %i, strip %i, padz %i, padx %i \n",Volume[0],Volume[1],Volume[2],Volume[3],Volume[4]);
213 PackedDataBuffer[currentDDL]->Reset();
219 //printf(" Packed Hit Buffer Entries = %i \n",nPDBEntriesToT);
220 //printf(" Hit Buffer Entries = %i \n",nDBEntriesToT);
225 for (Int_t i=0;i<72;i++){
226 delete DataBuffer[i];
227 delete PackedDataBuffer[i];
247 //write the Run level file
249 sprintf(filename,"TOFoutPulserLDC_%02i.root",ldcId);
250 TFile * fileRun = new TFile (filename,"RECREATE");
255 fprintf(fp,"Run #%s, received %d physics events out of %d\n",getenv("DATE_RUN_NUMBER"),nevents_physics,nevents_total);
257 /* close result file */
260 /* store the result file on FES */
261 status=daqDA_FES_storeFile(filename,"PULSER");