]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ZDC/ZDCMAPPINGda.cxx
STANDALONE RunType added
[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, STANDALONE_BC, STANDALONE_COSMIC, STANDALONE_CENTRAL, 
17           STANDALONE_MB, STANDALONE_SEMICENTRAL
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
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   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) {
105         continue;
106       }      
107       
108       // Initalize raw-data reading and decoding
109       AliRawReader *reader = new AliRawReaderDate((void*)event);
110       // --- Reading event header
111       //UInt_t evtype = reader->GetType();
112       //printf("\n\t ZDCPEDESTALda -> ev. type %d\n",evtype);
113       //printf("\t ZDCPEDESTALda -> run # %d\n",reader->GetRunNumber());
114       //
115       AliZDCRawStream *rawStreamZDC = new AliZDCRawStream(reader);
116         
117         
118       /* use event - here, just write event id to result file */
119       eventT=event->eventType;
120       
121       Int_t ich=0, adcMod[48], adcCh[48], sigCode[48], det[48], sec[48];
122       
123       if(eventT==START_OF_DATA){
124         sodRead = kTRUE;
125         
126         rawStreamZDC->SetSODReading(kTRUE);
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("ZDCMAPPING.cxx ->  mod %d ch %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       } // SOD event
153       else{ 
154         if(sodRead){
155           printf("\t SOR read -> exiting from DA\n");
156           break;
157         }
158         else continue;
159       }
160       
161       iev++; 
162     }    
163       
164     /* free resources */
165     //free(event);
166   }
167   
168   /* store the result files on FES */
169   status = daqDA_FES_storeFile(MAPDATA_FILE, MAPDATA_FILE);
170   if(status){
171     printf("Failed to export file : %d\n",status);
172     return -1;
173   }
174
175   return status;
176 }