]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ZDC/ZDCMAPPINGda.cxx
Correct accessing tower equalization coefficient array
[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 to write mapping for the ZDC ADCs
13
14 Contact: Chiara.Oppedisano@to.infn.it
15 Link: 
16 Run Type: PHYSICS, CALIBRATION_BC, CALIBRATION_CENTRAL, 
17           CALIBRATION_MB, CALIBRATION_SEMICENTRAL, CALIBRATION_COSMIC
18 DA Type: MON
19 Number of events needed: 1 (SOD is read) 
20 Input Files:  none
21 Output Files: ZDCChMapping.dat
22 Trigger Types Used: different trigger types are used
23
24 */
25
26 #define MAPDATA_FILE  "ZDCChMapping.dat"
27
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <Riostream.h>
31
32 // DATE
33 #include <event.h>
34 #include <monitor.h>
35 #include <daqDA.h>
36
37 //ROOT
38 #include <TFile.h>
39
40 //AliRoot
41 #include <AliRawReaderDate.h>
42 #include <AliRawEventHeaderBase.h>
43 #include <AliZDCRawStream.h>
44
45 int main(int argc, char **argv) {
46
47   const Char_t* tableSOD[]  = {"ALL", "no", "SOD", "all", NULL, NULL};
48   monitorDeclareTable(const_cast<char**>(tableSOD));
49   
50   int status = 0;
51   int const kNChannels = 24;
52
53   /* log start of process */
54   printf("\nZDC MAPPING program started\n");  
55
56   /* check that we got some arguments = list of files */
57   if (argc<2) {
58     printf("Wrong number of arguments\n");
59     return -1;
60   }
61   
62   FILE *mapFile4Shuttle;
63
64   /* read the data files */
65   int n;
66   for(n=1;n<argc;n++){
67    
68     status=monitorSetDataSource( argv[n] );
69     if (status!=0) {
70       printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
71       return -1;
72     }
73     
74     /* declare monitoring program */
75     status=monitorDeclareMp( __FILE__ );
76     if (status!=0) {
77       printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
78       return -1;
79     }
80     monitorSetNowait();
81     monitorSetNoWaitNetworkTimeout(1000);
82
83     struct eventHeaderStruct *event;
84     eventTypeType eventT;
85
86     Int_t iev = 0;
87     Bool_t sodRead = kFALSE;
88     while(!sodRead && iev<1000){
89  
90       /* check shutdown condition */
91       if (daqDA_checkShutdown()) {break;}
92
93       /* get next event */
94       status=monitorGetEventDynamic((void **)&event);
95       if(status==MON_ERR_EOF){
96         printf ("End of File detected\n");
97         break; /* end of monitoring file has been reached */
98       }
99       if(status!=0) {
100         printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
101         return -1;
102       }
103
104       /* retry if got no event */
105       if(event==NULL) continue;
106       
107       // Initalize raw-data reading and decoding
108       AliRawReader *reader = new AliRawReaderDate((void*)event);
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       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       
123       if(eventT==START_OF_DATA){
124         sodRead = kTRUE;
125         rawStreamZDC->SetSODReading(kTRUE);
126         
127         // --------------------------------------------------------
128         // --- Writing ascii data file for the Shuttle preprocessor
129         mapFile4Shuttle = fopen(MAPDATA_FILE,"w");
130         if(!rawStreamZDC->Next()) printf(" \t No raw data found!! \n");
131         else{
132           while((rawStreamZDC->Next()) && (ich<2*kNChannels)){
133             if(rawStreamZDC->IsChMapping()){
134               adcMod[ich] = rawStreamZDC->GetADCModFromMap(ich);
135               adcCh[ich] = rawStreamZDC->GetADCChFromMap(ich);
136               sigCode[ich] = rawStreamZDC->GetADCSignFromMap(ich);
137               det[ich] = rawStreamZDC->GetDetectorFromMap(ich);
138               sec[ich] = rawStreamZDC->GetTowerFromMap(ich);
139               //
140               fprintf(mapFile4Shuttle,"\t%d\t%d\t%d\t%d\t%d\t%d\n",
141                 ich,adcMod[ich],adcCh[ich],sigCode[ich],det[ich],sec[ich]);
142               //
143               //printf("ZDCMAPPINGda.cxx -> %d mod %d ch %d code %d det %d sec %d\n",
144               //   ich,adcMod[ich],adcCh[ich],sigCode[ich],det[ich],sec[ich]);
145               //
146               ich++;
147             }
148           }
149         }
150         fclose(mapFile4Shuttle);
151       } // SOD event
152       else{ 
153         if(sodRead){
154           printf("\t SOR read -> exiting from DA\n");
155           break;
156         }
157         else continue;
158       }
159       
160       iev++; 
161     }    
162       
163     /* free resources */
164     //free(event);
165   }
166   
167   /* store the result files on FES */
168   status = daqDA_FES_storeFile(MAPDATA_FILE, MAPDATA_FILE);
169   if(status){
170     printf("Failed to export file : %d\n",status);
171     return -1;
172   }
173
174   return status;
175 }