]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ZDC/ZDCMAPPINGda.cxx
Protection added until code in STEER won't be updated
[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 kNChannels = 24;
49   int const kNScChannels = 32;
50
51   /* log start of process */
52   printf("\nZDC MAPPING program started\n");  
53
54   /* check that we got some arguments = list of files */
55   if (argc<2) {
56     printf("Wrong number of arguments\n");
57     return -1;
58   }
59   
60   FILE *mapFile4Shuttle;
61
62   /* read the data files */
63   int n;
64   for(n=1;n<argc;n++){
65    
66     status=monitorSetDataSource( argv[n] );
67     if (status!=0) {
68       printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
69       return -1;
70     }
71     
72     /* declare monitoring program */
73     status=monitorDeclareMp( __FILE__ );
74     if (status!=0) {
75       printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
76       return -1;
77     }
78     monitorSetNowait();
79     monitorSetNoWaitNetworkTimeout(1000);
80
81     struct eventHeaderStruct *event;
82     eventTypeType eventT;
83
84     Int_t iev = 0;
85     Bool_t sodRead = kFALSE;
86     while(!sodRead && iev<1000){
87  
88       /* check shutdown condition */
89       if (daqDA_checkShutdown()) {break;}
90
91       /* get next event */
92       status=monitorGetEventDynamic((void **)&event);
93       if(status==MON_ERR_EOF){
94         printf ("End of File detected\n");
95         break; /* end of monitoring file has been reached */
96       }
97       if(status!=0) {
98         printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
99         return -1;
100       }
101
102       /* retry if got no event */
103       if(event==NULL) continue;
104       
105       // Initalize raw-data reading and decoding
106       AliRawReader *reader = new AliRawReaderDate((void*)event);
107       reader->Select("ZDC");
108       // --- Reading event header
109       //UInt_t evtype = reader->GetType();
110       //printf("\t ZDCMAPPINGda -> run # %d\n",reader->GetRunNumber());
111       //
112       AliZDCRawStream *rawStreamZDC = new AliZDCRawStream(reader);
113         
114         
115       /* use event - here, just write event id to result file */
116       eventT=event->eventType;
117       
118   
119       Int_t ich=0;
120       Int_t adcMod[2*kNChannels], adcCh[2*kNChannels], sigCode[2*kNChannels];
121       Int_t det[2*kNChannels], sec[2*kNChannels];
122       for(Int_t y=0; y<2*kNChannels; y++){
123         adcMod[y]=adcCh[y]=sigCode[y]=det[y]=sec[y]=0;
124       }
125       
126       Int_t iScCh=0;
127       Int_t scMod[kNScChannels], scCh[kNScChannels], scSigCode[kNScChannels];
128       Int_t scDet[kNScChannels], scSec[kNScChannels];
129       for(Int_t y=0; y<kNScChannels; y++){
130         scMod[y]=scCh[y]=scSigCode[y]=scDet[y]=scSec[y]=0;
131       }
132       //
133       Int_t modNum=-1, modType=-1;
134       
135       if(eventT==START_OF_DATA){
136                 
137         rawStreamZDC->SetSODReading(kTRUE);
138         
139         // --------------------------------------------------------
140         // --- Writing ascii data file for the Shuttle preprocessor
141         mapFile4Shuttle = fopen(MAPDATA_FILE,"w");
142         if(!rawStreamZDC->Next()) printf(" \t No raw data found!! \n");
143         else{
144           while((rawStreamZDC->Next())){
145             if(rawStreamZDC->IsHeaderMapping()){ // mapping header
146                modNum = rawStreamZDC->GetADCModule();
147                modType = rawStreamZDC->GetModType();
148             }
149             if(rawStreamZDC->IsChMapping()){ 
150               if(modType==1){ // ADC mapping ----------------------
151                 adcMod[ich]  = rawStreamZDC->GetADCModFromMap(ich);
152                 adcCh[ich]   = rawStreamZDC->GetADCChFromMap(ich);
153                 sigCode[ich] = rawStreamZDC->GetADCSignFromMap(ich);
154                 det[ich]     = rawStreamZDC->GetDetectorFromMap(ich);
155                 sec[ich]     = rawStreamZDC->GetTowerFromMap(ich);
156                 //
157                 fprintf(mapFile4Shuttle,"\t%d\t%d\t%d\t%d\t%d\t%d\n",
158                   ich,adcMod[ich],adcCh[ich],sigCode[ich],det[ich],sec[ich]);
159                 //
160                 //printf("  Mapping DA -> %d ADC: mod %d ch %d, code %d det %d, sec %d\n",
161                 //  ich,adcMod[ich],adcCh[ich],sigCode[ich],det[ich],sec[ich]);
162                 //
163                 ich++;
164               }
165               else if(modType==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                 //
172                 fprintf(mapFile4Shuttle,"\t%d\t%d\t%d\t%d\t%d\t%d\n",
173                   iScCh,scMod[iScCh],scCh[iScCh],scSigCode[iScCh],scDet[iScCh],scSec[iScCh]);
174                 //
175                 //printf("  Mapping DA -> %d Scaler: mod %d ch %d, code %d det %d, sec %d\n",
176                 //  iScCh,scMod[iScCh],scCh[iScCh],scSigCode[iScCh],scDet[iScCh],scSec[iScCh]);
177                 //
178                 iScCh++;
179               }
180             }
181           }
182         }
183         fclose(mapFile4Shuttle);
184       }// SOD event
185       else{ 
186         if(sodRead){
187           printf("\t SOR read -> exiting from DA\n");
188           break;
189         }
190         else continue;
191       }
192       
193       iev++; 
194
195       /* free resources */
196       free(event);
197     }    
198       
199   }
200   
201   /* store the result files on FES */
202   status = daqDA_FES_storeFile(MAPDATA_FILE, "MAPPING");
203   if(status){
204     printf("Failed to export file : %d\n",status);
205     return -1;
206   }
207
208   return status;
209 }