]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/ITSSPDVertexDiamondda.cxx
Setting the magnetic field - needed by the clusterfinders
[u/mrichter/AliRoot.git] / ITS / ITSSPDVertexDiamondda.cxx
1 /*
2 Contact: cvetan.cheshkov@cern.ch
3 Link: http://alisoft.cern.ch/viewvc/trunk/ITS/ITSSPDVertexDiamondda.cxx?root=AliRoot&view=log , /afs/cern.ch/user/c/cheshkov/public/ITS/VD_da_test.date , /afs/cern.ch/user/c/cheshkov/public/08000058338016.30.root.date.gz
4 Reference Run: 58338
5 Run Type: PHYSICS
6 DA Type: MON
7 Number of events needed: 100
8 Input Files: GRP/Geometry/Data , ITS/Align/Data , spd_noisy_ocdb , spd_dead_ocdb , TRIGGER/SPD/PITConditions (all the files are taken from SPD daqDetDB)
9 Output Files: SPDVertexDiamondDA.root
10 Trigger types used: PHYSICS, SPD-F0 
11 */
12
13 #define OUTPUT_FILE "SPDVertexDiamondDA.root"
14 #define N_EVENTS_AUTOSAVE 50
15
16 extern "C" {
17 #include "daqDA.h"
18 }
19
20 #include "event.h"
21 #include "monitor.h"
22
23 #ifdef ALI_AMORE
24 #include <AmoreDA.h>
25 //int amore::da::Updated(char const*) {}
26 #endif
27
28 #include <TPluginManager.h>
29 #include <TROOT.h>
30 #include <TH1.h>
31 #include <TH2.h>
32 #include <TSystem.h>
33 #include <TGeoGlobalMagField.h>
34
35 #include "AliLog.h"
36 #include "AliMagF.h"
37 #include "AliRawReaderDate.h"
38 #include "AliCDBManager.h"
39 #include "AliITSMeanVertexer.h"
40
41 int main(int argc, char **argv) {
42
43   gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
44                                         "*",
45                                         "TStreamerInfo",
46                                         "RIO",
47                                         "TStreamerInfo()"); 
48
49   int status;
50   if (argc<2) {
51     printf("Wrong number of arguments\n");
52     return -1;
53   }
54
55   /* define data source : this is argument 1 */  
56   status=monitorSetDataSource( argv[1] );
57   if (status!=0) {
58     printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
59     return -1;
60   }
61
62   /* declare monitoring program */
63   status=monitorDeclareMp( __FILE__ );
64   if (status!=0) {
65     printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
66     return -1;
67   }
68
69   /* define wait event timeout - 1s max */
70   monitorSetNowait();
71   monitorSetNoWaitNetworkTimeout(1000);
72   
73   /* log start of process */
74   printf("Vertex-Diamond SPD DA started\n");  
75
76   /* init some counters */
77   int nevents_with_vertex = 0;
78   int nevents_physics=0;
79   int nevents_total=0;
80
81   struct eventHeaderStruct *event;
82   eventTypeType eventT;
83
84   // Get run number
85   if (getenv("DATE_RUN_NUMBER")==0) {
86     printf("DATE_RUN_NUMBER not properly set.\n");
87     return -1;
88   }
89   int runNr = atoi(getenv("DATE_RUN_NUMBER"));
90
91   // Get the necessary OCDB files from the DAQ detector DB
92   if (gSystem->AccessPathName("localOCDB/GRP/Geometry/Data",kFileExists)) {
93     if (gSystem->mkdir("localOCDB/GRP/Geometry/Data",kTRUE) != 0) {
94       printf("Failed to create directory: localOCDB/GRP/Geometry/Data");
95       return -1;
96     }
97   }
98   status = daqDA_DB_getFile("GRP/Geometry/Data","localOCDB/GRP/Geometry/Data/Run0_999999999_v0_s0.root");
99   if (status) {
100     printf("Failed to get geometry file (GRP/Geometry/Data) from DAQdetDB, status=%d\n", status);
101     return -1;
102   }
103
104   if (gSystem->AccessPathName("localOCDB/ITS/Align/Data",kFileExists)) {
105     if (gSystem->mkdir("localOCDB/ITS/Align/Data",kTRUE) != 0) {
106       printf("Failed to create directory: localOCDB/ITS/Align/Data");
107       return -1;
108     }
109   }
110   status = daqDA_DB_getFile("ITS/Align/Data","localOCDB/ITS/Align/Data/Run0_999999999_v0_s0.root");
111   if (status) {
112     printf("Failed to get its-alignment file (ITS/Align/Data) from DAQdetDB, status=%d\n", status);
113     return -1;
114   }
115
116   if (gSystem->AccessPathName("localOCDB/ITS/Calib/SPDNoisy",kFileExists)) {
117     if (gSystem->mkdir("localOCDB/ITS/Calib/SPDNoisy",kTRUE) != 0) {
118       printf("Failed to create directory: localOCDB/ITS/Calib/SPDNoisy");
119       return -1;
120     }
121   }
122   status = daqDA_DB_getFile("spd_noisy_ocdb","localOCDB/ITS/Calib/SPDNoisy/Run0_999999999_v0_s0.root");
123   if (status) {
124     printf("Failed to get spd file (spd_noisy_ocdb) from DAQdetDB, status=%d\n", status);
125     return -1;
126   }
127
128   if (gSystem->AccessPathName("localOCDB/ITS/Calib/SPDDead",kFileExists)) {
129     if (gSystem->mkdir("localOCDB/ITS/Calib/SPDDead",kTRUE) != 0) {
130       printf("Failed to create directory: localOCDB/ITS/Calib/SPDDead");
131       return -1;
132     }
133   }
134   status = daqDA_DB_getFile("spd_dead_ocdb","localOCDB/ITS/Calib/SPDDead/Run0_999999999_v0_s0.root");
135   if (status) {
136     printf("Failed to get spd file (spd_dead_ocdb) from DAQdetDB, status=%d\n", status);
137     return -1;
138   }
139
140   if (gSystem->AccessPathName("localOCDB/TRIGGER/SPD/PITConditions",kFileExists)) {
141     if (gSystem->mkdir("localOCDB/TRIGGER/SPD/PITConditions",kTRUE) != 0) {
142       printf("Failed to create directory: localOCDB/TRIGGER/SPD/PITConditions");
143       return -1;
144     }
145   }
146   status = daqDA_DB_getFile("TRIGGER/SPD/PITConditions","localOCDB/TRIGGER/SPD/PITConditions/Run0_999999999_v0_s0.root");
147   if (status) {
148     printf("Failed to get spd trigger file (TRIGGER/SPD/PITConditions) from DAQdetDB, status=%d\n", status);
149     return -1;
150   }
151
152   // Global initializations
153
154   // The B filed is required in AliITSClusterFinderV2SPD
155   // for the Lorentz angle correction. B set to 0.      
156   TGeoGlobalMagField::Instance()->SetField(new AliMagF("Maps","Maps", 0., 0., AliMagF::k5kGUniform));  
157   AliLog::SetGlobalLogLevel(AliLog::kError);
158   AliCDBManager *man = AliCDBManager::Instance();
159   man->SetDefaultStorage("local://localOCDB");
160   man->SetRun(runNr);
161
162   // Init mean vertexer
163   AliITSMeanVertexer *mv = new AliITSMeanVertexer();
164   if (!mv->Init()) {
165     printf("Initialization of mean vertexer object failed ! Check the log for details");
166     return -1;
167   }
168
169   // Initialization of AMORE sender
170 #ifdef ALI_AMORE
171   amore::da::AmoreDA vtxAmore(amore::da::AmoreDA::kSender);
172 #endif
173   /* main loop (infinite) */
174   for(;;) {
175     
176     /* check shutdown condition */
177     if (daqDA_checkShutdown()) {break;}
178     
179     /* get next event (blocking call until timeout) */
180     status=monitorGetEventDynamic((void **)&event);
181     if (status==MON_ERR_EOF) {
182       printf ("End of File detected\n");
183       break; /* end of monitoring file has been reached */
184     }
185     
186     if (status!=0) {
187       printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
188       break;
189     }
190     
191     /* retry if got no event */
192     if (event==NULL) {
193       continue;
194     }
195
196     nevents_total++;
197     eventT=event->eventType;
198     switch (event->eventType){
199       
200       /* START OF RUN */
201     case START_OF_RUN:
202       break;
203       /* END START OF RUN */
204       
205     /* END OF RUN */
206     case END_OF_RUN:
207       break;
208       
209     case PHYSICS_EVENT:
210       nevents_physics++;
211       AliRawReader *rawReader = new AliRawReaderDate((void*)event);
212
213       // Run mean-vertexer reco
214       if (mv->Reconstruct(rawReader)) nevents_with_vertex++;
215
216       // Auto save
217       if ((nevents_physics%N_EVENTS_AUTOSAVE) == 0) {
218         mv->WriteVertices(OUTPUT_FILE);
219
220 #ifdef ALI_AMORE
221       // send the histos to AMORE pool
222         printf("AMORE send status: %d\n",vtxAmore.Send(mv->GetVertexXY()->GetName(),mv->GetVertexXY()));
223         printf("AMORE send status: %d\n",vtxAmore.Send(mv->GetVertexZ()->GetName(),mv->GetVertexZ()));
224 #endif
225       }
226
227       delete rawReader;
228     }
229     
230     /* free resources */
231     free(event);
232     
233     /* exit when last event received, no need to wait for TERM signal */
234     if (eventT==END_OF_RUN) {
235       printf("EOR event detected\n");
236       break;
237     }
238   }
239
240   mv->WriteVertices(OUTPUT_FILE);
241
242 #ifdef ALI_AMORE
243   // send the histos to AMORE pool
244   printf("AMORE send status: %d\n",vtxAmore.Send(mv->GetVertexXY()->GetName(),mv->GetVertexXY()));
245   printf("AMORE send status: %d\n",vtxAmore.Send(mv->GetVertexZ()->GetName(),mv->GetVertexZ()));
246 #endif
247
248   delete mv;
249
250   /* write report */
251   printf("Run #%s, received %d events with vertex, out of %d physics and out of %d total events\n",getenv("DATE_RUN_NUMBER"),nevents_with_vertex,nevents_physics,nevents_total);
252
253   status=0;
254
255   /* export file to FXS */
256   if (daqDA_FES_storeFile(OUTPUT_FILE, "VertexDiamond")) {
257     status=-2;
258   }
259   
260   return status;
261 }