]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HMPID/HMPIDda.cxx
Copy constructor was accidentally commented out
[u/mrichter/AliRoot.git] / HMPID / HMPIDda.cxx
1 /*
2 *********************************************************
3 Author:                                                 *
4 this file provides the detector algorithm for HMPID.    *
5 *********************************************************
6 */
7 extern "C" {
8 #include <daqDA.h>
9 }
10
11 #include "event.h"
12 #include "monitor.h"
13
14 #include <Riostream.h>
15 #include <stdio.h>
16 #include <stdlib.h>
17
18 //AliRoot
19 #include "AliHMPIDRawStream.h"
20 #include "AliHMPIDCalib.h"
21 #include "AliRawReaderDate.h"
22 #include "AliBitPacking.h"
23 #include "TMath.h"
24
25 //ROOT
26 #include "TFile.h"
27 #include "TSystem.h"
28 #include "TKey.h"
29 #include "TH2S.h"
30 #include "TObject.h"
31 #include "TBenchmark.h"
32 #include "TMath.h"
33 #include "TRandom.h"
34 #include "TTree.h"
35 #include "TTreePlayer.h"
36
37
38 int main(int argc, char **argv){ 
39
40   int status;
41
42   /* log start of process */
43   printf("HMPID DA program started\n");  
44
45   /* check that we got some arguments = list of files */
46   if (argc<2) {
47     printf("Wrong number of arguments\n");
48     return -1;
49   }
50
51   /* copy locally a file from daq detector config db
52   status=daqDA_DB_getFile("myconfig","./myconfig.txt");
53   if (status) {
54     printf("Failed to get config file : %d\n",status);
55     return -1;
56   }
57   and possibly use it */
58
59   /* report progress */
60   daqDA_progressReport(10);
61
62
63   /* init the pedestal calculation */
64   AliHMPIDCalib *pCal=new AliHMPIDCalib();
65   //pCal->Init();                    //Init the pedestal calculation
66   
67   /* init event counter */
68   Int_t iEvtNcal=0;
69
70   int n;
71   for (n=1;n<argc;n++) {
72
73     status=monitorSetDataSource( argv[n] );
74     if (status!=0) {
75       printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
76       return -1;
77     }
78
79     /* report progress */
80     /* in this example, indexed on the number of files */
81     daqDA_progressReport(10+80*n/argc);
82
83     for(;;) { // infinite loop 
84       struct eventHeaderStruct *event;
85       eventTypeType eventT;
86
87       /* get next event */
88       status=monitorGetEventDynamic((void **)&event);
89       if (status==MON_ERR_EOF) break; /* end of monitoring file has been reached */
90       if (status!=0) {
91         printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
92         return -1;
93       }
94
95       /* retry if got no event */
96       if (event==NULL) {
97         break;
98       }
99
100       /* use event - here, just write event id to result file */
101       eventT=event->eventType;
102
103       if (eventT==PHYSICS_EVENT) {                                                //we use PHYSICS_EVENT for pedestal not CALIBRATION_EVENT
104         
105         iEvtNcal++;
106
107         AliRawReader *reader = new AliRawReaderDate((void*)event);
108
109         // Temporary there. Shall be removed as soon as the equipment ID is set correctly
110         // For the moment ddl.map file contains one line which maps
111         // the observed eqID=225 to the first HMPID DDL with ID=1536
112         //      reader->LoadEquipmentIdsMap("ddl.map");
113         
114         AliHMPIDRawStream stream(reader);
115
116         while(stream.Next()) {
117           Int_t ddl=stream.GetDDLNumber();
118             for(Int_t row = 1; row <=AliHMPIDRawStream::kNRows; row++){
119               for(Int_t dil = 1; dil <=AliHMPIDRawStream::kNDILOGICAdd; dil++){
120                 for(Int_t pad = 0; pad < AliHMPIDRawStream::kNPadAdd; pad++){
121                   pCal->FillPedestal(ddl,row,dil,pad,stream.GetCharge(ddl,row,dil,pad));
122                 }//pad
123               }//dil
124             }//row
125         } //raw data loop
126         
127         delete reader;
128
129       }// if CALIBRATION_EVENT
130
131       /* exit when last event received, no need to wait for TERM signal */
132       if (eventT==END_OF_RUN) {
133         printf("EOR event detected\n");
134         break;    
135     
136       } // events loop   
137
138       free(event);
139     }
140
141   }
142
143   /* write report */
144   printf("Run #%s, received %d calibration events\n",getenv("DATE_RUN_NUMBER"),iEvtNcal);
145
146   if (!iEvtNcal) {
147     printf("No calibration events have been read. Exiting\n");
148     return -1;
149   }
150
151   /* report progress */
152   daqDA_progressReport(90);
153
154   for(Int_t ddl=0; ddl < 14; ddl++) {
155     
156     /* Calculate pedestal for the given ddl, if there is no ddl go t next */
157     if(!pCal->CalcPedestal(ddl,Form("./HmpidPedDdl%02i.txt",ddl))) continue;
158     
159     /* store the result file on FES */
160     status=daqDA_FES_storeFile(Form("./HmpidPedDdl%02i.txt",ddl),Form("HMPID_DA_Pedestals_ddl=%02i",ddl));
161     if (status) {
162       printf("Failed to export file : %d\n",status);
163       return -1;
164     }
165   }//ddl
166
167   /* report progress */
168   daqDA_progressReport(100);
169
170   return status;
171 }