3 TOF DA for online calibration from pulser data
5 Contact: Chiara.Zampolli@bo.infn.it
6 Link: www.bo.infn.it/~zampolli
7 Run Type: CALIBRATION, PULSER - to be properly defined
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)
28 #include <AliTOFRawStream.h>
29 #include <AliRawReaderDate.h>
30 #include <AliRawReader.h>
31 #include <AliTOFGeometry.h>
33 #include <AliTOFHitData.h>
34 #include <AliTOFHitDataBuffer.h>
35 #include <AliTOFDecoder.h>
46 Arguments: list of DATE raw data files
48 int main(int argc, char **argv) {
50 AliTOFGeometry * geom = new AliTOFGeometry();
52 static const Int_t size = AliTOFGeometry::NPadXSector()*AliTOFGeometry::NSectors();
53 TH1F::AddDirectory(0);
54 TH1F * htofNoise = new TH1F("hTOFnoise","histo with signals on TOF during noise", size,-0.5,size-0.5);
55 for (Int_t ibin =1;ibin<=size;ibin++){
56 htofNoise->SetBinContent(ibin,-1);
62 /* log start of process */
63 printf("TOF DA started\n");
65 /* check that we got some arguments = list of files */
67 printf("Wrong number of arguments\n");
71 /* open result file */
73 fp=fopen("./result.txt","a");
75 printf("Failed to open file\n");
79 /* init some counters */
80 int nevents_physics=0;
83 /* read the data files */
85 for (n=1;n<argc;n++) {
87 status=monitorSetDataSource( argv[n] );
89 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
95 struct eventHeaderStruct *event;
99 status=monitorGetEventDynamic((void **)&event);
100 if (status==MON_ERR_EOF) break; /* end of monitoring file has been reached */
102 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
106 /* retry if got no event */
111 /* use event - here, just write event id to result file */
112 eventT=event->eventType;
114 if (eventT==PHYSICS_EVENT) {
115 //printf ("event %i \n", nevents_physics);
116 Int_t nPDBEntriesToT = 0;
117 Int_t nDBEntriesToT = 0;
118 AliTOFHitData *HitData;
121 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
122 AliTOFRawStream *rawStreamTOF = new AliTOFRawStream(rawReader);
123 AliTOFDecoder * decoderTOF = new AliTOFDecoder();
124 AliTOFHitDataBuffer *DataBuffer[72];
125 AliTOFHitDataBuffer *PackedDataBuffer[72];
126 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
127 DataBuffer[i]=new AliTOFHitDataBuffer();
128 PackedDataBuffer[i]=new AliTOFHitDataBuffer();
130 Int_t currentEquipment;
133 while(rawReader->ReadHeader()){
134 //printf ("ldcId = %i \n",ldcId);
135 ldcId = rawReader->GetLDCId();
137 //memory leak prevention (actually data should be always 0x0 here)
138 if (data != 0x0) delete [] data;
140 //get equipment infos
141 currentEquipment = rawReader->GetEquipmentId();
142 currentDDL = rawReader->GetDDLID();
144 if (currentDDL%2==0) {
150 Int_t * array = new Int_t[nchDDL];
151 decoderTOF->GetArrayDDL(array, currentDDL);
153 for (Int_t i=0;i<nchDDL;i++){
154 if (htofNoise->GetBinContent(array[i]+1)<0) htofNoise->SetBinContent(array[i]+1,0);
157 //printf(" Equipment = %i, and DDL = %i \n", currentEquipment,currentDDL);
158 const Int_t kDataSize = rawReader->GetDataSize();
159 const Int_t kDataWords = kDataSize / 4;
160 data = new UChar_t[kDataSize];
161 decoderTOF->SetDataBuffer(DataBuffer[currentDDL]);
162 decoderTOF->SetPackedDataBuffer(PackedDataBuffer[currentDDL]);
164 if (!rawReader->ReadNext(data, kDataSize)){
165 rawReader->AddMajorErrorLog(AliTOFRawStream::kDDLdataReading);
166 printf("Error while reading DDL data. Go to next equipment \n");
171 if (decoderTOF->Decode((UInt_t *)data, kDataWords) == kTRUE) {
172 rawReader->AddMajorErrorLog(AliTOFRawStream::kDDLDecoder,Form("DDL # = %d",currentDDL));
173 printf("Error while decoding DDL # %d: decoder returned with errors \n", currentDDL);
176 Int_t nDBEntries = DataBuffer[currentDDL]->GetEntries();
177 Int_t nPDBEntries = PackedDataBuffer[currentDDL]->GetEntries();
178 nPDBEntriesToT+=nPDBEntries;
179 nDBEntriesToT+=nDBEntries;
181 DataBuffer[currentDDL]->Reset();
183 /* read data buffer hits */
184 for (Int_t iHit = 0; iHit < nPDBEntries; iHit++){
185 HitData = PackedDataBuffer[currentDDL]->GetHit(iHit);
186 /* add volume information */
187 HitData->SetDDLID(currentDDL);
188 rawStreamTOF->EquipmentId2VolumeId(HitData, Volume);
193 Volume[4]==-1) continue;
196 Volume[3] = Volume[4];
198 Int_t index = geom->GetIndex(Volume);
199 Bool_t found =kFALSE;
200 // to check array indexes
202 for (Int_t j=0;j<nchDDL;j++){
203 if (index==array[j]) {
208 printf ("index = %i, found = %i\n",index, (Int_t)found);
210 //printf ("index = %i \n",index);
211 htofNoise->Fill(index); //channel index start from 0, bin index from 1
212 //debugging printings
213 //printf("sector %i, plate %i, strip %i, padz %i, padx %i \n",Volume[0],Volume[1],Volume[2],Volume[3],Volume[4]);
217 PackedDataBuffer[currentDDL]->Reset();
223 //printf(" Packed Hit Buffer Entries = %i \n",nPDBEntriesToT);
224 //printf(" Hit Buffer Entries = %i \n",nDBEntriesToT);
229 for (Int_t i=0;i<72;i++){
230 delete DataBuffer[i];
231 delete PackedDataBuffer[i];
251 Float_t time = nevents_physics*200*1E-9; // acquisition time in s
252 //printf(" Noise run lasted %f s \n",time);
253 for (Int_t ibin =1;ibin<=size;ibin++){
254 Float_t cont = htofNoise->GetBinContent(ibin);
256 //printf(" content = %f \n", cont);
257 htofNoise->SetBinContent(ibin,cont/time);
258 //printf(" scaled content = %f \n", cont/time);
262 //write the Run level file
264 sprintf(filename,"TOFoutNoiseLDC_%02i.root",ldcId);
265 TFile * fileRun = new TFile (filename,"RECREATE");
270 fprintf(fp,"Run #%s, received %d physics events out of %d\n",getenv("DATE_RUN_NUMBER"),nevents_physics,nevents_total);
272 /* close result file */
277 /* store the result file on FES */
278 status=daqDA_FES_storeFile(filename,filename);