]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ZDC/ZDCMAPPINGda.cxx
fixing compilation bug
[u/mrichter/AliRoot.git] / ZDC / ZDCMAPPINGda.cxx
1 /*
2
3 This program reads the DAQ data files passed as argument using the monitoring library.
4
5 The program reports about its processing progress.
6
7 Messages on stdout are exported to DAQ log system.
8
9 DA to write mapping for ADC modules and VME scaler
10
11 Contact: Chiara.Oppedisano@to.infn.it
12 Link: 
13 Run Type: PHYSICS, CALIBRATION_BC, CALIBRATION_CENTRAL, 
14           CALIBRATION_MB, CALIBRATION_SEMICENTRAL, CALIBRATION_COSMIC
15 DA Type: MON
16 Number of events needed: 1 (SOD is read) 
17 Input Files:  none
18 Output Files: ZDCChMapping.dat
19 Trigger Types Used: different trigger types are used
20
21 */
22
23 #define MAPDATA_FILE  "ZDCChMapping.dat"
24
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <Riostream.h>
28
29 // DATE
30 #include <event.h>
31 #include <monitor.h>
32 #include <daqDA.h>
33
34 //ROOT
35 #include <TFile.h>
36
37 //AliRoot
38 #include <AliRawReaderDate.h>
39 #include <AliRawEventHeaderBase.h>
40 #include <AliZDCRawStream.h>
41
42 int main(int argc, char **argv) {
43
44   const Char_t* tableSOD[]  = {"ALL", "no", "SOD", "all", NULL, NULL};
45   monitorDeclareTable(const_cast<char**>(tableSOD));
46   
47   int status = 0;
48   int const kNModules = 10;
49   int const kNChannels = 24;
50   int const kNScChannels = 32;
51
52   /* log start of process */
53   printf("\n ZDC MAPPING program started\n");  
54
55   /* check that we got some arguments = list of files */
56   if (argc<2) {
57     printf("Wrong number of arguments\n");
58     return -1;
59   }
60   
61   FILE *mapFile4Shuttle;
62
63   /* read the data files */
64   int n;
65   for(n=1;n<argc;n++){
66    
67     status=monitorSetDataSource( argv[n] );
68     if (status!=0) {
69       printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
70       return -1;
71     }
72     
73     /* declare monitoring program */
74     status=monitorDeclareMp( __FILE__ );
75     if (status!=0) {
76       printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
77       return -1;
78     }
79     monitorSetNowait();
80     monitorSetNoWaitNetworkTimeout(1000);
81
82     struct eventHeaderStruct *event;
83     eventTypeType eventT;
84
85     Int_t iev = 0;
86     Bool_t sodRead = kFALSE;
87     while(!sodRead && iev<1000){
88  
89       /* check shutdown condition */
90       if (daqDA_checkShutdown()) {break;}
91
92       /* get next event */
93       status=monitorGetEventDynamic((void **)&event);
94       if(status==MON_ERR_EOF){
95         printf ("End of File detected\n");
96         break; /* end of monitoring file has been reached */
97       }
98       if(status!=0) {
99         printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
100         return -1;
101       }
102
103       /* retry if got no event */
104       if(event==NULL) continue;
105       
106       // Initalize raw-data reading and decoding
107       AliRawReader *reader = new AliRawReaderDate((void*)event);
108       reader->Select("ZDC");
109       // --- Reading event header
110       //UInt_t evtype = reader->GetType();
111       //printf("\t ZDCMAPPINGda -> run # %d\n",reader->GetRunNumber());
112       //
113       AliZDCRawStream *rawStreamZDC = new AliZDCRawStream(reader);
114         
115         
116       /* use event - here, just write event id to result file */
117       eventT=event->eventType;
118       
119       if(eventT==START_OF_DATA){
120                 
121       
122       Int_t iMod=-1;
123       Int_t modGeo[kNModules], modType[kNModules],modNCh[kNModules];
124       for(Int_t kl=0; kl<kNModules; kl++){
125          modGeo[kl]=modType[kl]=modNCh[kl]=0;
126       }
127   
128       Int_t ich=0;
129       Int_t adcMod[2*kNChannels], adcCh[2*kNChannels], sigCode[2*kNChannels];
130       Int_t det[2*kNChannels], sec[2*kNChannels];
131       for(Int_t y=0; y<2*kNChannels; y++){
132         adcMod[y]=adcCh[y]=sigCode[y]=det[y]=sec[y]=0;
133       }
134       
135       Int_t iScCh=0;
136       Int_t scMod[kNScChannels], scCh[kNScChannels], scSigCode[kNScChannels];
137       Int_t scDet[kNScChannels], scSec[kNScChannels];
138       for(Int_t y=0; y<kNScChannels; y++){
139         scMod[y]=scCh[y]=scSigCode[y]=scDet[y]=scSec[y]=0;
140       }
141         
142         rawStreamZDC->SetSODReading(kTRUE);
143         
144         // --------------------------------------------------------
145         // --- Writing ascii data file for the Shuttle preprocessor
146         mapFile4Shuttle = fopen(MAPDATA_FILE,"w");
147         if(!rawStreamZDC->Next()) printf(" \t No raw data found!! \n");
148         else{
149           while((rawStreamZDC->Next())){
150             if(rawStreamZDC->IsHeaderMapping()){ // mapping header
151                iMod++;
152                modGeo[iMod]  = rawStreamZDC->GetADCModule();
153                modType[iMod] = rawStreamZDC->GetModType();
154                modNCh[iMod]  = rawStreamZDC->GetADCNChannels();
155             }
156             if(rawStreamZDC->IsChMapping()){ 
157               if(modType[iMod]==1){ // ADC mapping ----------------------
158                 adcMod[ich]  = rawStreamZDC->GetADCModFromMap(ich);
159                 adcCh[ich]   = rawStreamZDC->GetADCChFromMap(ich);
160                 sigCode[ich] = rawStreamZDC->GetADCSignFromMap(ich);
161                 det[ich]     = rawStreamZDC->GetDetectorFromMap(ich);
162                 sec[ich]     = rawStreamZDC->GetTowerFromMap(ich);
163                 ich++;
164               }
165               else if(modType[iMod]==2){ //VME scaler mapping --------------------
166                 scMod[iScCh]     = rawStreamZDC->GetScalerModFromMap(iScCh);
167                 scCh[iScCh]      = rawStreamZDC->GetScalerChFromMap(iScCh);
168                 scSigCode[iScCh] = rawStreamZDC->GetScalerSignFromMap(iScCh);
169                 scDet[iScCh]     = rawStreamZDC->GetScDetectorFromMap(iScCh);
170                 scSec[iScCh]     = rawStreamZDC->GetScTowerFromMap(iScCh);
171                 iScCh++;
172               }
173             }
174           }
175           // Writing data on output FXS file
176           for(Int_t is=0; is<2*kNChannels; is++){
177              fprintf(mapFile4Shuttle,"\t%d\t%d\t%d\t%d\t%d\t%d\n",
178                is,adcMod[is],adcCh[is],sigCode[is],det[is],sec[is]);
179              //printf("  Mapping DA -> %d ADC: mod %d ch %d, code %d det %d, sec %d\n",
180              //  is,adcMod[is],adcCh[is],sigCode[is],det[is],sec[is]);
181           }
182           for(Int_t is=0; is<kNScChannels; is++){
183              fprintf(mapFile4Shuttle,"\t%d\t%d\t%d\t%d\t%d\t%d\n",
184                is,scMod[is],scCh[is],scSigCode[is],scDet[is],scSec[is]);
185              //if(scMod[is]!=0) printf("  Mapping DA -> %d Scaler: mod %d ch %d, code %d det %d, sec %d\n",
186              //  is,scMod[is],scCh[is],scSigCode[is],scDet[is],scSec[is]);
187           }
188           for(Int_t is=0; is<kNModules; is++){
189              fprintf(mapFile4Shuttle,"\t%d\t%d\t%d\n",
190              modGeo[is],modType[is],modNCh[is]);
191              //printf("  Mapping DA -> Module mapping: geo %d type %d #ch %d\n",
192              //  modGeo[is],modType[is],modNCh[is]);
193           }
194           
195         }
196         fclose(mapFile4Shuttle);
197       }// SOD event
198       else{ 
199         if(sodRead){
200           printf("\t SOR read -> exiting from DA\n");
201           break;
202         }
203         else continue;
204       }
205       
206       iev++; 
207
208       /* free resources */
209       free(event);
210     }    
211       
212   }
213   
214   /* store the result files on FES */
215   status = daqDA_FES_storeFile(MAPDATA_FILE, "MAPPING");
216   if(status){
217     printf("Failed to export file : %d\n",status);
218     return -1;
219   }
220
221   return status;
222 }