source: trunk/MagicSoft/Mars/datacenter/macros/fillcamera.C@ 9061

Last change on this file since 9061 was 8996, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 30.0 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of MARS, the MAGIC Analysis and Reconstruction
5! * Software. It is distributed to you in the hope that it can be a useful
6! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
7! * It is distributed WITHOUT ANY WARRANTY.
8! *
9! * Permission to use, copy, modify and distribute this software and its
10! * documentation for any purpose is hereby granted without fee,
11! * provided that the above copyright notice appear in all copies and
12! * that both that copyright notice and this permission notice appear
13! * in supporting documentation. It is provided "as is" without express
14! * or implied warranty.
15! *
16!
17!
18! Author(s): Thomas Bretz, 06/2007 <mailto:tbretz@astro.uni-wuerzburg.de>
19! Author(s): Daniela Dorner, 11/2005 <mailto:dorner@astro.uni-wuerzburg.de>
20! Author(s): Daniel Hoehne, 10/2007 <mailto:hoehne@astro.uni-wuerzburg.de>
21!
22! Copyright: MAGIC Software Development, 2000-2007
23!
24!
25\* ======================================================================== */
26
27/////////////////////////////////////////////////////////////////////////////
28//
29// fillcamera.C
30// ============
31//
32// This macro is used to read the camera-output files and fill the values
33// into the MC database.
34// You have to specify the path where to search for the camera files.
35// As default the dummy mode is kTRUE, so nothing will be filled but only
36// the mysql orders are printed. To really fill the db, set dummy to kFALSE.
37//
38// Make sure, that database and password are corretly set in a resource
39// file called mcsql.rc and the resource file is found.
40//
41// Returns 2 in case of failure and 1 in case of success.
42// Returns 0 in case of no connection to the db.
43//
44//
45/////////////////////////////////////////////////////////////////////////////
46#include <iostream>
47#include <iomanip>
48
49#include <TRegexp.h>
50#include <TObjectTable.h>
51
52#include <TFile.h>
53#include <TTree.h>
54#include <TBranch.h>
55
56//#include <TH1.h>
57
58#include <TSQLResult.h>
59#include <TSQLRow.h>
60#include <TSystem.h>
61
62#include "MSQLServer.h"
63#include "MSQLMagic.h"
64
65#include "MMcRunHeader.hxx"
66#include "MMcConfigRunHeader.h"
67#include "MMcCorsikaRunHeader.h"
68#include "MMcFadcHeader.hxx"
69#include "MMcEvtBasic.h"
70#include "MRawRunHeader.h"
71//#include "MRawEvtData.h"
72#include <MDirIter.h>
73
74#include <math.h>
75
76using namespace std;
77
78int Process(MSQLMagic &serv, TString fname, Bool_t dummy)
79{
80 //
81 // Read file
82 //
83 TFile file(fname, "READ");
84 if (!file.IsOpen())
85 {
86 cout << "ERROR - Could not find file " << fname << endl;
87 return 2;
88 }
89
90 //
91 // Get tree RunHeaders from file
92 //
93 TTree *tree = dynamic_cast<TTree*>(file.Get("RunHeaders"));
94 if (!tree)
95 {
96 cout << "ERROR - Tree RunHeaders not found in file " << fname << endl;
97 return 2;
98 }
99
100 //
101 // Get branch MMcCorsikaRunHeader from tree RunHeaders
102 //
103/* TBranch *b1 = tree->GetBranch("MMcCorsikaRunHeader.");
104 if (!b1)
105 {
106 cout << "ERROR - Branch MMcCorsikaRunHeader. not found in file " << fname << endl;
107 return 2;
108 }
109 MMcCorsikaRunHeader *runheader1 = 0;
110 b1->SetAddress(&runheader1);
111*/
112 MMcCorsikaRunHeader *runheader1 = 0;
113 tree->SetBranchAddress("MMcCorsikaRunHeader.", &runheader1);
114
115 //
116 // Get branch MMcConfigRunHeader from tree RunHeaders
117 //
118 MMcConfigRunHeader *runheader2 = 0;
119 tree->SetBranchAddress("MMcConfigRunHeader.", &runheader2);
120
121 //
122 // Get branch MMcRunHeader from tree RunHeaders
123 //
124 MMcRunHeader *runheader3 = 0;
125 tree->SetBranchAddress("MMcRunHeader.", &runheader3);
126
127 //
128 // Get branch MMcFadcRunHeader from tree RunHeaders
129 //
130 MMcFadcHeader *fadcheader = 0;
131 tree->SetBranchAddress("MMcFadcHeader.", &fadcheader);
132
133 //
134 // Get branch MRawRunHearder from tree RunHeaders
135 //
136 MRawRunHeader *rawheader = 0;
137 tree->SetBranchAddress("MRawRunHeader.", &rawheader);
138
139 if (tree->GetEntry(0)<0)
140 {
141 cout << "ERROR - No entry found in tree RunHeaders of file: " << fname << endl;
142 return 2;
143 }
144
145 //
146 // Get tree Events from file
147 //
148 TTree *tree2 = dynamic_cast<TTree*>(file.Get("Events"));
149 if (!tree2)
150 {
151 cout << "ERROR - Tree Events not found in file " << fname << endl;
152 return 2;
153 }
154
155 //
156 // Get branch MMcEvtBasic from tree Events
157 //
158 MMcEvtBasic *evtbasic = 0;
159 tree2->SetBranchAddress("MMcEvtBasic.", &evtbasic);
160
161 if (tree2->GetEntry(0)<0)
162 {
163 cout << "ERROR - No entry found in tree Events of file: " << fname << endl;
164 return 2;
165 }
166
167
168 // Definition of values
169 Double_t misptx = runheader2->GetMissPointingX();
170 Double_t mispty = runheader2->GetMissPointingY();
171 Double_t point = runheader2->GetPointSpread();
172 Double_t pointspreadx = runheader2->GetPointSpreadX();
173 Double_t pointspready = runheader2->GetPointSpreadY();
174 Double_t coneai = runheader1->GetViewconeAngleInner();
175 Double_t coneao = runheader1->GetViewconeAngleOuter();
176 Double_t spectrum = runheader1->GetSlopeSpec();
177 Double_t tmin = runheader3->GetShowerThetaMin();
178 Double_t tmax = runheader3->GetShowerThetaMax();
179 UInt_t corsvers = runheader3->GetCorsikaVersion();
180 UInt_t reflvers = runheader3->GetReflVersion();
181 UInt_t camvers = runheader3->GetCamVersion();
182 UInt_t numsimshow = runheader3->GetNumSimulatedShowers();
183 UInt_t numevents = tree2->GetEntries();
184
185 // some calculations: round the given values
186 pointspreadx=TMath::Floor(pointspreadx*100+0.5)/100;
187 pointspready=TMath::Floor(pointspready*100+0.5)/100;
188 point=TMath::Floor(point*10+0.5)/10;
189 coneai=TMath::Floor(coneai*10+0.5)/10;
190 coneao=TMath::Floor(coneao*10+0.5)/10;
191 spectrum=TMath::Floor(spectrum*10+0.5)/10;
192
193 // Definition of strings
194 TString elow = Form("%5.1f", runheader1->GetELowLim());
195 TString eupp = Form("%5.1f", runheader1->GetEUppLim());
196 TString slope = Form("%5.1f", spectrum);
197 TString wobble = Form("%5.0f", runheader1->GetWobbleMode());
198 TString corsika1 = Form("%5.0f", runheader1->GetCorsikaVersion());
199 TString coneanglei = Form("%5.1f", coneai);
200 TString coneangleo = Form("%5.1f", coneao);
201 TString atmomodel = Form("%5.1f", runheader1->GetAtmosphericModel());
202 TString psf = Form("%5.1f", point);
203 TString psfx = Form("%5.2f", pointspreadx);
204 TString psfy = Form("%5.2f", pointspready);
205 TString psfadd = Form("%5.2f", TMath::Hypot(runheader2->GetPointSpreadX(), runheader2->GetPointSpread()));
206 TString mirrfrac = Form("%5.2f", runheader2->GetMirrorFraction());
207 TString misx = Form("%5.2f", misptx);
208 TString misy = Form("%5.2f", mispty);
209 TString reflector = Form("%5.0i", reflvers);
210 TString camera = Form("%5.0i", camvers);
211 TString imax = Form("%5.1f", runheader3->GetImpactMax());
212 TString numphe = Form("%5.1f", runheader3->GetNumPheFromDNSB());
213 TString pmin = Form("%5.1f", runheader3->GetShowerPhiMin());
214 TString pmax = Form("%5.1f", runheader3->GetShowerPhiMax());
215 TString numss = Form("%7.0i", numsimshow);
216 TString thetamin = Form("%5.1f", tmin);
217 TString thetamax = Form("%5.1f", tmax);
218 TString ped = Form("%5.1f", fadcheader->GetPedestal(1));
219 TString low2high = Form("%5.1f", fadcheader->GetLow2HighGain());
220 TString amplfadc = Form("%5.2f", fadcheader->GetAmplitud());
221 TString amplfadco = Form("%5.2f", fadcheader->GetAmplitudOuter());
222 TString enoise = Form("%5.1f", fadcheader->GetElecNoise(1));
223 TString dnoise = Form("%5.1f", fadcheader->GetDigitalNoise(1));
224 TString numevt = Form("%7.0i", numevents);
225 TString partid = Form("%5.0f", evtbasic->GetPartId());
226 TString partname = evtbasic->GetParticleName();
227
228 // get the number of triggers
229 UInt_t ntrig = (UInt_t)tree2->Draw("Length$(MRawEvtData.fHiGainPixId.fN)", "MRawEvtData.fHiGainPixId.fN!=0", "goff");
230 if (ntrig<0)
231 {
232 cout << "ERROR - Evaluating triggered events in file: " << fname << endl;
233 return 2;
234 }
235 TString numtrig = Form("%7.0i", ntrig);
236// TH1I h("myhist", "", 1, -0.5, 0.5);
237// tree2->Draw("MRawEvtData.GetNumPixels()>>myhist", "", "goff");
238// h.SetDirectory(0);
239// TString numtrig = Form("%7.0i", TMath::Nint(h.GetBinContent(2)));
240
241 // Determine observation mode, fake wobble means On mode with mispointing
242 TString wobblemod="Wobble";
243 if (atoi(wobble)==0)
244 wobblemod = misptx == 0 && mispty == 0 ? "On" : "Fake Wobble";
245 if (atoi(coneangleo)>0)
246 wobblemod = "Diffuse";
247
248 //get the psf value for the path for linking
249 Float_t pointsfuncx=pointspreadx*10;
250 pointsfuncx=TMath::Floor(pointsfuncx*10+0.5)/10;
251 Int_t pointsfx = TMath::Nint(pointsfuncx);
252
253 // Get zbin
254 Float_t zBin=TMath::Nint((1-((TMath::Cos(tmin*TMath::Pi()/180)+TMath::Cos(tmax*TMath::Pi()/180))/2))*100);
255 Int_t zBin2=TMath::Nint(zBin);
256
257 // Definition of keys
258 Int_t corsikakey;
259 Int_t reflectorkey;
260 Int_t camerakey;
261 Int_t observationkey;
262 Int_t particlekey;
263 Int_t atmomodelkey;
264 Int_t amplfadckey;
265 Int_t psfkey;
266 Int_t viewconeangleokey;
267 Int_t spectrumkey;
268
269 // Definition of variables to be filled in the db
270 TString vars;
271
272 // Separation of ped/cal and data runs by checking the value pointspread
273 // ped/cal runs
274 if(point==-1)
275 {
276 cout << endl;
277 cout << "psf value: " << point << " -> MC P or C run." << endl;
278 cout << endl;
279 cout << "--- From File ---" << endl;
280 cout << endl;
281 cout << "Energy Range " << elow << " < E < " << eupp << endl;
282 cout << "SpectralIndex " << slope << endl;
283 cout << "CorsikaVer " << corsika1 << endl;
284 cout << "ParticleId " << partid << endl;
285 cout << "ParticleName " << partname << endl;
286 cout << "PointSpread " << psf << endl;
287 cout << "NumSimShowers " << numsimshow << endl;
288 cout << "ImpactMax " << imax << endl;
289 cout << "NumEvents " << numevt << endl;
290 cout << "NumTriggers " << numtrig << endl;
291 cout << "NumPheFromDNSB " << numphe << endl;
292 cout << "ViewconeAngleInner " << coneanglei << endl;
293 cout << "ViewconeAngleOuter " << coneangleo << endl;
294 cout << "AtmosphericModel " << atmomodel << endl;
295 cout << "Pedestal " << ped << endl;
296 cout << "Low2HighGain " << low2high << endl;
297 cout << "AmplitudeFADC " << amplfadc << endl;
298 cout << "AmplFADCOuter " << amplfadco << endl;
299 cout << "ElecNoise " << enoise << endl;
300 cout << "DigiNoise " << dnoise << endl;
301 cout << "PhiMin " << pmin << endl;
302 cout << "PhiMax " << pmax << endl;
303 cout << "ThetaMin " << thetamin << endl;
304 cout << "ThetaMax " << thetamax << endl;
305 cout << "Zenith range " << tmin << " to " << tmax << endl;
306 cout << "MirrorFraction " << mirrfrac << endl;
307 cout << endl;
308 cout << endl;
309 cout << "P/C run: there will be fixed values inserted into the db for the following parameters:" << endl;
310 cout << "ObservationMode " << wobblemod << " -> " << "n/a" <<endl;
311 cout << "ReflVer " << reflvers << " -> " << "n/a" <<endl;
312 cout << "CamVer " << camvers << " -> " << "n/a" <<endl;
313 cout << "PointSpreadX " << psfx << " -> " << "0" <<endl;
314 cout << "PointSpreadY " << psfy << " -> " << "0" <<endl;
315 cout << "MispointingX " << misx << " -> " << "0" <<endl;
316 cout << "MispointingY " << misy << " -> " << "0" <<endl;
317 cout << endl;
318 cout << "--- key's from mcdb tables ---" << endl;
319 cout << endl;
320
321 corsikakey=1;
322 reflectorkey=1;
323 camerakey=1;
324 observationkey=1;
325 particlekey = 1;
326 atmomodelkey = serv.QueryKeyOfName("AtmosphericModel", atmomodel.Data());
327 amplfadckey = serv.QueryKeyOfName("AmplFadc", amplfadc.Data());
328 viewconeangleokey = serv.QueryKeyOfName("ViewconeAngleO", coneangleo.Data());
329 spectrumkey = 1;
330 psfkey = 1;
331
332 if (corsvers==0)
333 {
334 cout << "CorsikaVersion not available" << endl;
335 }
336 else
337 {
338 corsikakey = serv.QueryKeyOfName("CorsikaVersion", corsika1.Data());
339 }
340 if (reflvers==0)
341 {
342 cout << "ReflectorVersion not available" << endl;
343 }
344 else
345 {
346 reflectorkey = serv.QueryKeyOfName("ReflectorVersion", reflector.Data());
347 }
348 if (camvers==0)
349 {
350 cout << "CameraVersion not available" << endl;
351 }
352 else
353 {
354 camerakey = serv.QueryKeyOfName("CameraVersion", camera.Data());
355 }
356
357 cout << "corsikakey: " << corsikakey << endl;
358 cout << "reflectorkey: " << reflectorkey << endl;
359 cout << "camerakey: " << camerakey << endl;
360 cout << "observationkey: " << observationkey << endl;
361 cout << "particlekey: " << particlekey << endl;
362 cout << "atmomodelkey: " << atmomodelkey << endl;
363 cout << "amplfadckey: " << amplfadckey << endl;
364 cout << "psfkey: " << psfkey << endl;
365 cout << "coneangleokey: " << viewconeangleokey << endl;
366 cout << "spectrumkey: " << spectrumkey << endl;
367 cout << endl;
368
369 // For ped/cal: fixed values for psf and mispointing
370 vars = Form("fPointSpreadX=0, fPointSpreadY=0, fMissPointingX=0, fMissPointingY=0, ");
371
372 }
373 // Data runs
374 else
375 {
376
377 cout << endl;
378 cout << "psf value: " << point << " -> MC data run." << endl;
379 cout << endl;
380 cout << "--- From File ---" << endl;
381 cout << endl;
382 cout << "Energy Range " << elow << " < E < " << eupp << endl;
383 cout << "SpectralIndex " << slope << endl;
384 cout << "ObservationMode " << wobblemod << endl;
385 cout << "CorsikaVer " << corsika1 << endl;
386 cout << "ReflVer " << reflector << endl;
387 cout << "CamVer " << camera << endl;
388 cout << "ParticleId " << partid << endl;
389 cout << "ParticleName " << partname << endl;
390 cout << "PointSpread " << psf << endl;
391 cout << "PointSpreadX " << pointspreadx << endl;
392 cout << "PointSpreadXY " << psfx << " /" << psfy << endl;
393// cout << "AdditionPSF " << psfadd << endl;
394 cout << "MispointingXY " << misx << " /" << misy <<endl;
395 cout << "NumSimShowers " << numss << endl;
396 cout << "ImpactMax " << imax << endl;
397 cout << "NumEvents " << numevt << endl;
398 cout << "NumTriggers " << numtrig << endl;
399 cout << "NumPheFromDNSB " << numphe << endl;
400 cout << "ViewconeAngleInner " << coneanglei << endl;
401 cout << "ViewconeAngleOuter " << coneangleo << endl;
402 cout << "AtmosphericModel " << atmomodel << endl;
403 cout << "Pedestal " << ped << endl;
404 cout << "Low2HighGain " << low2high << endl;
405 cout << "AmplitudeFADC " << amplfadc << endl;
406 cout << "AmplFADCOuter " << amplfadco << endl;
407 cout << "ElecNoise " << enoise << endl;
408 cout << "DigiNoise " << dnoise << endl;
409 cout << "PhiMin " << pmin << endl;
410 cout << "PhiMax " << pmax << endl;
411 cout << "ThetaMin " << thetamin << endl;
412 cout << "ThetaMax " << thetamax << endl;
413 cout << "Zenith range " << tmin << " to " << tmax << endl;
414 cout << "MirrorFraction " << mirrfrac << endl;
415 cout << endl;
416 cout << endl;
417 cout << "--- key's from mcdb tables ---" << endl;
418 cout << endl;
419
420 corsikakey=1;
421 reflectorkey=1;
422 camerakey=1;
423 observationkey = serv.QueryKeyOfName("ObservationMode", wobblemod.Data());
424 particlekey = serv.QueryKeyOfName("MCParticle", partname.Data());
425 atmomodelkey = serv.QueryKeyOfName("AtmosphericModel", atmomodel.Data());
426 amplfadckey = serv.QueryKeyOfName("AmplFadc", amplfadc.Data());
427 viewconeangleokey = serv.QueryKeyOfName("ViewconeAngleO", coneangleo.Data());
428 psfkey = serv.QueryKeyOfName("PSF", psfx);
429 spectrumkey = serv.QueryKeyOfName("Spectrum", slope);
430
431 if (corsvers==0)
432 {
433 cout << "CorsikaVersion not available" << endl;
434 }
435 else
436 {
437 corsikakey = serv.QueryKeyOfName("CorsikaVersion", corsika1.Data());
438 }
439 if (reflvers==0)
440 {
441 cout << "ReflectorVersion not available" << endl;
442 }
443 else
444 {
445 reflectorkey = serv.QueryKeyOfName("ReflectorVersion", reflector.Data());
446 }
447 if (camvers==0)
448 {
449 cout << "CameraVersion not available" << endl;
450 }
451 else
452 {
453 camerakey = serv.QueryKeyOfName("CameraVersion", camera.Data());
454 }
455
456 cout << "corsikakey: " << corsikakey << endl;
457 cout << "reflectorkey: " << reflectorkey << endl;
458 cout << "camerakey: " << camerakey << endl;
459 cout << "observationkey: " << observationkey << endl;
460 cout << "particlekey: " << particlekey << endl;
461 cout << "atmomodelkey: " << atmomodelkey << endl;
462 cout << "amplfadckey: " << amplfadckey << endl;
463 cout << "psfkey: " << psfkey << endl;
464 cout << "coneangleokey: " << viewconeangleokey << endl;
465 cout << "spectrumkey: " << spectrumkey << endl;
466 cout << endl;
467
468 // For data runs the values are taken from the file
469 vars = Form("fPointSpreadX=%5.2f, fPointSpreadY=%5.2f, fMissPointingX=%s, fMissPointingY=%s, ",
470 pointspreadx, pointspready, misx.Data(), misy.Data());
471
472 }
473
474 // Query maximum run number and add 1 to it, if no runnumber is found, start with 1
475 TString query(Form("SELECT IF (isnull(MAX(MCRunData.fRunNumber)+1),1,MAX(MCRunData.fRunNumber)+1) FROM MCRunData;"));
476 // TString query(Form("SELECT MCRunData.fRunNumber, IF (isnull(MAX(MCRunData.fRunNumber)+1),1,MAX(MCRunData.fRunNumber)+1), "
477 // "fFileName FROM MCRunData LEFT JOIN "
478 // "MCRunProcessStatus ON MCRunData.fRunNumber=MCRunProcessStatus.fRunNumber "
479 // "where fFileName=\"%s\" group by MCRunData.fRunNumber;", fname.Data()));
480
481 TSQLResult *res = serv.Query(query);
482 if (!res)
483 {
484 cout << "ERROR - Query failed: " << query << endl;
485 return 2;
486 }
487
488 TSQLRow *row = 0;
489 row = res->Next();
490 TString num=(*row)[0];
491 Int_t RunNum=atoi(num.Data());
492
493 delete res;
494// delete row;
495 // Query run number and filename from MCRunProcessStatus
496 TString query2(Form("SELECT fRunNumber, fFileName from MCRunProcessStatus where fFileName=\"%s\"", fname.Data()));
497 res = serv.Query(query2);
498 if (!res)
499 {
500 cout << "ERROR - Query failed: " << query2 << endl;
501 return 2;
502 }
503
504 row = res->Next();
505 // If query gives no entry for the filename the file will be inserted into the db
506 if (!row)
507 {
508 cout << "No entry in query result: " << query2 << endl;
509 cout << "--------" << endl;
510 cout << "RunNum: " << RunNum << endl;
511 cout << "File: " << fname << endl;
512 cout << endl;
513
514 vars +=
515 Form("fELowLim=%s, fEUppLim=%s, fSlopeSpec=%5.2f, "
516 "fImpactMax=%s, fNumSimulatedShowers=%d, fNumEvents=%d, "
517 "fNumPheFromDNSB=%s, fZBin=%d, fThetaMin=%s, "
518 "fThetaMax=%s, fPointSpread=%s, "
519 "fPedesMean=%s, fLow2HighGain=%s, "
520 "fAmplFadc=%s, fAmplFadcOuter=%s, ",
521 elow.Data(), eupp.Data(), spectrum,
522 imax.Data(), numsimshow, numevents,
523 numphe.Data(), zBin2, thetamin.Data(),
524 thetamax.Data(), psf.Data(),
525 ped.Data(), low2high.Data(),
526 amplfadc.Data(), amplfadco.Data());
527 vars +=
528 Form("fElectricNoise=%s, "
529 "fDigitalNoise=%s, fRunNumber=%d, "
530 "fCorsikaVersionKEY =%d, "
531 "fReflectorVersionKEY=%d, fCameraVersionKEY=%d, "
532 "fObservationModeKEY=%d, fMCParticleKEY=%d, "
533 "fSequenceFirst=0, fNumTriggers=%d, fViewconeAngleInner=%5.2f, fViewconeAngleOuter=%5.2f, "
534 "fAtmosphericModelKEY=%d, fAmplFadcKEY=%d, "
535 "fPSFKEY=%d, fViewconeAngleOKEY=%d, fSpectrumKEY=%d ",
536 enoise.Data(),
537 dnoise.Data(), RunNum,
538 corsikakey,
539 reflectorkey, camerakey,
540 observationkey, particlekey,
541 ntrig, coneai, coneao,
542 atmomodelkey, amplfadckey,
543 psfkey, viewconeangleokey, spectrumkey);
544
545 TString vars2 =
546 Form("fRunFilled=Now(), fFileName=\"%s\", fRunNumber=%d ",
547 fname.Data(), RunNum);
548
549
550 if (!serv.ExistStr("fRunNumber", "MCRunData", Form("%d", RunNum)))
551 {
552 if (!serv.Insert("MCRunData", vars))
553 return 2;
554 }
555 else
556 if (!serv.Update("MCRunData", vars, Form("fRunNumber=%d", RunNum)))
557 return 2;
558
559//MarsVersion miteintragen bei Prozessierung
560
561 if (!serv.ExistStr("fRunNumber", "MCRunProcessStatus", Form("%d", RunNum)))
562 {
563 if (!serv.Insert("MCRunProcessStatus", vars2))
564 return 2;
565 }
566 else
567 if (!serv.Update("MCRunProcessStatus", vars2, Form("fRunNumber=%d", RunNum)))
568 return 2;
569 }
570 // If the file is already filled into the db, the values will be updated
571 else
572 {
573 TString run=(*row)[0];
574 TString check=(*row)[1];
575 if (check==fname)
576 {
577 RunNum=atoi(run.Data());
578 cout << "File already inserted into db, do update " << endl;
579 cout << "--------" << endl;
580 cout << "RunNum: " << RunNum << endl;
581 cout << "File: " << fname << endl;
582 cout << endl;
583
584 vars +=
585 Form("fELowLim=%s, fEUppLim=%s, fSlopeSpec=%5.2f, "
586 "fImpactMax=%s, fNumSimulatedShowers=%d, fNumEvents=%d, "
587 "fNumPheFromDNSB=%s, fZBin=%d, fThetaMin=%s, "
588 "fThetaMax=%s, fPointSpread=%s, "
589 "fPedesMean=%s, fLow2HighGain=%s, "
590 "fAmplFadc=%s, fAmplFadcOuter=%s, ",
591 elow.Data(), eupp.Data(), spectrum,
592 imax.Data(), numsimshow, numevents,
593 numphe.Data(), zBin2, thetamin.Data(),
594 thetamax.Data(), psf.Data(),
595 ped.Data(), low2high.Data(),
596 amplfadc.Data(), amplfadco.Data());
597 vars +=
598 Form("fElectricNoise=%s, "
599 "fDigitalNoise=%s, fRunNumber=%d, "
600 "fCorsikaVersionKEY =%d, "
601 "fReflectorVersionKEY=%d, fCameraVersionKEY=%d, "
602 "fObservationModeKEY=%d, fMCParticleKEY=%d, "
603 "fSequenceFirst=0, fNumTriggers=%d, fViewconeAngleInner=%5.2f, fViewconeAngleOuter=%5.2f, "
604 "fAtmosphericModelKEY=%d, fAmplFadcKEY=%d, "
605 "fPSFKEY=%d, fViewconeAngleOKEY=%d, fSpectrumKEY=%d ",
606 enoise.Data(),
607 dnoise.Data(), RunNum,
608 corsikakey,
609 reflectorkey, camerakey,
610 observationkey, particlekey,
611 ntrig, coneai, coneao,
612 atmomodelkey, amplfadckey,
613 psfkey, viewconeangleokey, spectrumkey);
614
615 TString vars2 =
616 Form("fRunFilled=Now(), fFileName=\"%s\", fRunNumber=%d ",
617 fname.Data(), RunNum);
618
619
620 if (!serv.ExistStr("fRunNumber", "MCRunData", Form("%d", RunNum)))
621 {
622 if (!serv.Insert("MCRunData", vars))
623 return 2;
624 }
625 else
626 if (!serv.Update("MCRunData", vars, Form("fRunNumber=%d", RunNum)))
627 return 2;
628
629 if (!serv.ExistStr("fRunNumber", "MCRunProcessStatus", Form("%d", RunNum)))
630 {
631 if (!serv.Insert("MCRunProcessStatus", vars2))
632 return 2;
633 }
634 else
635 if (!serv.Update("MCRunProcessStatus", vars2, Form("fRunNumber=%d", RunNum)))
636 return 2;
637 }
638 //If none of the above options is true, something must be wrong
639 else
640 {
641 cout << "ERROR - Filename in query (" << check << ") and processed filename (" << fname << ") should be the same!" << endl;
642 return 2;
643 }
644 }
645 delete res;
646// delete row;
647
648 //link file geht nur für data files, cal und ped haben keine psf... müssen aber in alle verzeichnisse verlinkt werden
649 //wieder mit if point 0.5/-1.0 else
650
651// TString query3(Form("SELECT fMCParticleName, fSpectrum, fFileName, fObservationModeKEY from MCRunData "
652// "left join MCParticle on MCRunData.fMCParticleKEY=MCParticle.fMCParticleKEY "
653// "left join Spectrum on Spectrum.fSpectrumKEY=MCRunData.fSpectrumKEY "
654// "left join MCRunProcessStatus on MCRunProcessStatus.fRunNumber=MCRunData.fRunNumber "
655// "where MCRunData.fRunNumber=%d;", RunNum));
656 TString query3(Form("SELECT fMCParticleName, fSpectrum FROM MCRunData "
657 "LEFT JOIN MCParticle USING (fMCParticleKEY) "
658 "LEFT JOIN Spectrum USING (fSpectrumKEY) "
659 "WHERE MCRunData.fRunNumber=%d;", RunNum));
660 res = serv.Query(query3);
661 if (!res)
662 {
663 cout << "ERROR - Query failed: " << query3 << endl;
664 return 2;
665 }
666
667 row = res->Next();
668
669 // Definition of variables for linking the file
670 TString rawpath;
671 TString type = "D"; //P, C, D
672 TString particle = (*row)[0]; //ParticleName abfragen
673 TString spec = (*row)[1]; //Spectrum.fSpectrum abfragen
674 TString obsmode; //wird über obskey präzisiert
675 TString mkdir;
676 TString link;
677 TString RunNumber=Form("%08d",RunNum);
678
679 delete res;
680 rawpath = Form("/magic/montecarlo/rawfiles/19%02d/%02d/%02d", zBin2, amplfadckey, pointsfx);
681// rawpath = Form("/home/hoehne/Analyse/TestMonteCarlo/montecarlo/rawfiles/19%02d/%02d/%02d", zBin2, amplfadckey, pointsfx);
682 mkdir = Form("mkdir -p -v %s", rawpath.Data());
683
684 switch (observationkey)
685 {
686 case 1:
687// obsmode = ""; //evtl für ped u cal verwenden
688 cout << "" << endl;
689 cout << "Ped or Cal run -> no linking by fillcamera.C" << endl;
690// spec = "";
691// particle="MonteCarlo";
692// TRegexp pedcal("_._");
693// TString peca = fname(pedcal);
694// if (peca="_P_")
695// type="P";
696// if (peca="_C_")
697// type="C";
698 break;
699 //Problem: zbin und psf
700 //19990101_00002_C_MonteCarlo_E.root
701
702 case 2:
703 obsmode = "W";
704 break;
705
706 case 3:
707 obsmode = "";
708 break;
709
710 case 4:
711 obsmode = "FW";
712 break;
713
714 case 5:
715 obsmode = "Diff";
716 break;
717
718 default:
719 cout << "ERROR - ObservationModeKEY wrong value" << endl;
720 return 2;
721 }
722
723 TRegexp reg("_w.");
724 TString add = fname(reg);
725// add = add.Data()+2;
726 if (add=="_w+" || add=="_w-")
727 {
728 if (add=="_w+")
729 obsmode += "1";
730 else
731 obsmode += "2";
732 }
733
734 if (obsmode!=1)
735 {
736 link = Form("ln -sv %s %s/19%02d%02d%02d_%s_%s_%s%s%s_E.root", fname.Data(), rawpath.Data(), zBin2, amplfadckey, pointsfx, RunNumber.Data(), type.Data(), particle.Data(), spec.Data(), obsmode.Data());
737
738 if (dummy==kFALSE)
739 {
740 gSystem->Exec(mkdir);
741 gSystem->Exec(link);
742 }
743 else
744 {
745 cout << "" << endl;
746 cout << "Dummy mode. The following commands would be executed:" << endl;
747 cout << mkdir << endl;
748 cout << link << endl;
749 cout << "" << endl;
750 }
751 }
752 else
753 {
754 cout << "" << endl;
755 cout << "Linking will be done by fillcamera script" << endl;
756 cout << "" << endl;
757 }
758
759 delete runheader1;
760 delete runheader2;
761 delete runheader3;
762 delete fadcheader;
763 delete rawheader;
764 delete evtbasic;
765
766
767
768 return 1;
769
770}
771/*
772int fillcamera(TString fname, Bool_t dummy=kTRUE)
773{
774 MSQLMagic serv("sql.rc");
775 if (!serv.IsConnected())
776 {
777 cout << "ERROR - Connection to database failed." << endl;
778 return 0;
779 }
780
781 serv.SetIsDummy(dummy);
782
783 cout << endl;
784 cout << "fillcamera" << endl;
785 cout << "----------" << endl;
786 cout << endl;
787 cout << "Connected to " << serv.GetName() << endl;
788 cout << "File: " << fname << endl;
789 cout << endl;
790
791 return Process(serv, fname, dummy);
792}
793*/
794int fillcamera(TString path="/magic/montecarlo/camera", Bool_t dummy=kTRUE)
795{
796 MSQLMagic serv("mcsql.rc");
797 if (!serv.IsConnected())
798 {
799 cout << "ERROR - Connection to database failed." << endl;
800 return 0;
801 }
802
803 serv.SetIsDummy(dummy);
804
805 cout << endl;
806 cout << "fillcamera" << endl;
807 cout << "----------" << endl;
808 cout << endl;
809 cout << "Connected to " << serv.GetName() << endl;
810 cout << "Search path: " << path << endl;
811 cout << endl;
812
813
814 TString fname;
815 TString name;
816
817
818 MDirIter Next(path,"*.root",-1);
819
820 while(1)
821 {
822 TString name = Next();
823 if (name.IsNull())
824 break;
825 fname=name;
826 cout << endl;
827 cout << endl;
828 cout << "filename: " << fname << endl;
829
830// TObject::SetObjectStat(kTRUE);
831
832 if (!Process(serv, name, dummy))
833 return 2;
834/*
835 if (TObject::GetObjectStat())
836 {
837 TObject::SetObjectStat(kFALSE);
838 gObjectTable->Print();
839 }
840*/
841 }
842
843 return 1;
844}
Note: See TracBrowser for help on using the repository browser.