]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ZDC/ZDCMAPPINGda.cxx
Class updated (2 understand something more from retrieved DCS DP)
[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 It computes the average event size and populates local "./result.txt" file with the 
6 result.
7
8 The program reports about its processing progress.
9
10 Messages on stdout are exported to DAQ log system.
11
12 DA for ZDC standalone pedestal runs
13
14 Contact: Chiara.Oppedisano@to.infn.it
15 Link: 
16 Run Type: PHYSICS, STANDALONE_BC, STANDALONE_COSMIC, STANDALONE_CENTRAL, 
17           STANDALONE_MB, STANDALONE_SEMICENTRAL
18 DA Type: LDC
19 Number of events needed: no constraint 
20 Input Files:  
21 Output Files: ZDCChMapping.dat
22 Trigger Types Used: 
23
24 */
25 #define MAPDATA_FILE  "ZDCChMapping.dat"
26
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <Riostream.h>
30
31 // DATE
32 #include <event.h>
33 #include <monitor.h>
34 #include <daqDA.h>
35
36 //ROOT
37 #include <TFile.h>
38
39 //AliRoot
40 #include <AliRawReaderDate.h>
41 #include <AliRawEventHeaderBase.h>
42 #include <AliZDCRawStream.h>
43
44
45 /* Main routine
46       Arguments: list of DATE raw data files
47 */
48 int main(int argc, char **argv) {
49   
50   int status = 0;
51
52   /* log start of process */
53   printf("\nZDC 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   /* open result file */
62   FILE *fp=NULL;
63   fp=fopen("./result.txt","a");
64   if (fp==NULL) {
65     printf("Failed to open file\n");
66     return -1;
67   }
68   
69   FILE *mapFile4Shuttle;
70   
71   /* report progress */
72   daqDA_progressReport(10);
73
74
75   /* init some counters */
76   int nevents_physics=0;
77   int nevents_total=0;
78
79   /* read the data files */
80   int n;
81   for(n=1;n<argc;n++){
82    
83     status=monitorSetDataSource( argv[n] );
84     if (status!=0) {
85       printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
86       return -1;
87     }
88
89     /* report progress */
90     /* in this example, indexed on the number of files */
91     daqDA_progressReport(10+80*n/argc);
92
93     /* read the file */
94     for(;;) {
95       struct eventHeaderStruct *event;
96       eventTypeType eventT;
97
98       /* get next event */
99       status=monitorGetEventDynamic((void **)&event);
100       if(status==MON_ERR_EOF) break; /* end of monitoring file has been reached */
101       if(status!=0) {
102         printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
103         return -1;
104       }
105
106       /* retry if got no event */
107       if(event==NULL) {
108         break;
109       }
110       
111       // Initalize raw-data reading and decoding
112       AliRawReader *reader = new AliRawReaderDate((void*)event);
113       reader->Select("ZDC");
114       // --- Reading event header
115       //UInt_t evtype = reader->GetType();
116       //printf("\n\t ZDCPEDESTALda -> ev. type %d\n",evtype);
117       //printf("\t ZDCPEDESTALda -> run # %d\n",reader->GetRunNumber());
118       //
119       AliZDCRawStream *rawStreamZDC = new AliZDCRawStream(reader);
120         
121
122       /* use event - here, just write event id to result file */
123       eventT=event->eventType;
124       
125       Int_t ich=0, adcMod[48], adcCh[48], sigCode[48], det[48], sec[48];
126       if(eventT==START_OF_DATA){
127                 
128         if(!rawStreamZDC->Next()) printf(" \t No raw data found!! \n");
129         else{
130           while(rawStreamZDC->Next()){
131             if(rawStreamZDC->IsChMapping()){
132               adcMod[ich] = rawStreamZDC->GetADCModFromMap(ich);
133               adcCh[ich] = rawStreamZDC->GetADCChFromMap(ich);
134               sigCode[ich] = rawStreamZDC->GetADCSignFromMap(ich);
135               det[ich] = rawStreamZDC->GetDetectorFromMap(ich);
136               sec[ich] = rawStreamZDC->GetTowerFromMap(ich);
137               ich++;
138             }
139           }
140         }
141         // --------------------------------------------------------
142         // --- Writing ascii data file for the Shuttle preprocessor
143         mapFile4Shuttle = fopen(MAPDATA_FILE,"w");
144         for(Int_t i=0; i<ich; i++){
145            fprintf(mapFile4Shuttle,"\t%d\t%d\t%d\t%d\t%d\t%d\n",i,
146              adcMod[i],adcCh[i],sigCode[i],det[i],sec[i]);
147            //
148            //printf("ZDCPEDESTALDA.cxx ->  ch.%d mod %d, ch %d, code %d det %d, sec %d\n",
149            //      i,adcMod[i],adcCh[i],sigCode[i],det[i],sec[i]);
150         }
151         fclose(mapFile4Shuttle);
152       }
153
154       nevents_total++;
155
156       /* free resources */
157       free(event);
158     
159     }
160   }  
161   
162   /* write report */
163   fprintf(fp,"Run #%s, received %d physics events out of %d\n",getenv("DATE_RUN_NUMBER"),nevents_physics,nevents_total);
164
165   /* close result file */
166   fclose(fp);
167   
168   /* report progress */
169   daqDA_progressReport(90);
170
171   /* store the result files on FES */
172   status = daqDA_FES_storeFile(MAPDATA_FILE, MAPDATA_FILE);
173   if(status){
174     printf("Failed to export file : %d\n",status);
175     return -1;
176   }
177
178   /* report progress */
179   daqDA_progressReport(100);
180
181   return status;
182 }