/[PAMELA software]/DarthVader/RunInfo/src/RunInfo.cpp
ViewVC logotype

Contents of /DarthVader/RunInfo/src/RunInfo.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.21 - (show annotations) (download)
Tue May 15 14:35:31 2012 UTC (12 years, 6 months ago) by mocchiut
Branch: MAIN
Changes since 1.20: +2 -2 lines
Reprocessing bugs fixed, ToF bugs fixed, new software versions, new quaternions, IGRF bug fixed, code cleanup

1 //
2 #include <sstream>
3 //
4 #include <TObject.h>
5 #include <TChain.h>
6 #include <TSystem.h>
7 #include <TSystemFile.h>
8 #include <TArrayI.h>
9 #include <TFile.h>
10 #include <TTree.h>
11 #include <TDirectory.h>
12 #include <TSQLServer.h>
13 #include <TSQLRow.h>
14 #include <TSQLResult.h>
15 //
16 #include <GLTables.h>
17 #include <RunInfo.h>
18 ClassImp(SoftInfo);
19 ClassImp(ItoRunInfo);
20 //
21 using namespace std;
22 //
23
24 SoftInfo::SoftInfo() {
25 Clear();
26 }
27
28 void SoftInfo::Clear(Option_t *t){
29 TRIG_ver = "";
30 TOF_ver = "";
31 AC_ver = "";
32 TRK_ver = "";
33 ORB_ver = "";
34 CAL_ver = "";
35 ND_ver = "";
36 S4_ver = "";
37 DV_ver = "";
38 }
39
40 UInt_t SoftInfo::GetSWinfo(TString Detector){
41 TString sver;
42 UInt_t version = 0;
43 if ( !strcmp(Detector.Data(),"TRIG") ){
44 sver = TRIG_ver;
45 };
46 if ( !strcmp(Detector.Data(),"TOF") ){
47 sver = TOF_ver;
48 };
49 if ( !strcmp(Detector.Data(),"AC") ){
50 sver = AC_ver;
51 };
52 if ( !strcmp(Detector.Data(),"TRK") ){
53 sver = TRK_ver;
54 };
55 if ( !strcmp(Detector.Data(),"CALO") ){
56 sver = CAL_ver;
57 };
58 if ( !strcmp(Detector.Data(),"S4") ){
59 sver = S4_ver;
60 };
61 if ( !strcmp(Detector.Data(),"DV") ){
62 sver = DV_ver;
63 };
64 if ( !strcmp(Detector.Data(),"ND") ){
65 sver = ND_ver;
66 };
67 if ( !strcmp(Detector.Data(),"ORB") ){
68 sver = ORB_ver;
69 };
70 sver.ReplaceAll("v",1," ",1);
71 sver.ReplaceAll("r",1," ",1);
72 version = (UInt_t)sver.Atoi();
73 return(version);
74 };
75
76 /**
77 * Fills a struct cSoftInfo with values from a SoftInfo object (to put data into a F77 common).
78 */
79 void SoftInfo::GetLevel2Struct(cSoftInfo *l2) const{
80 l2->FillTrigWith(TRIG_ver);
81 l2->FillTofWith(TOF_ver);
82 l2->FillAcWith(AC_ver);
83 l2->FillTrkWith(TRK_ver);
84 l2->FillOrbWith(ORB_ver);
85 l2->FillCalWith(CAL_ver);
86 l2->FillNdWith(ND_ver);
87 l2->FillS4With(S4_ver);
88 }
89 /***********************/
90
91 ItoRunInfo::~ItoRunInfo() {
92 this->GL_RUN::Clear();
93 }
94
95 ItoRunInfo::ItoRunInfo() {
96 reprocessing = false;
97 updating = false;
98 isreadonly = true;
99 first_file_entry = 0;
100 last_file_entry = 0;
101 file_entries = 0;
102 totnorun = 0;
103 this->GL_RUN::Clear();
104 version = new SoftInfo();
105 norun = 0;
106 runlist = new TArrayI(500);
107 file = NULL;
108 newtree = NULL;//new TTree();
109 }
110
111 ItoRunInfo::ItoRunInfo(TFile *processFl){
112 //
113 file=(TFile*)processFl;
114 dbc=NULL;
115 processFolder = "";
116 idRun = 0;
117 Detector = "NONE";
118 //
119 reprocessing = false;
120 updating = false;
121 first_file_entry = 0;
122 last_file_entry = 0;
123 file_entries = 0;
124 version = new SoftInfo();
125 // glrun = new GL_RUN();
126 norun = 0;
127 totnorun = 0;
128 runlist = new TArrayI(500);
129 newtree = NULL;
130 //
131 }
132
133
134
135 TChain *ItoRunInfo::GetRunTree(TList *fl){
136 //
137 TChain *Tout = new TChain("Run");
138 // loop over files and create chains
139 TIter next(fl);
140 TSystemFile *questo = 0;
141 while ( (questo = (TSystemFile*) next()) ) {
142 TString name = questo->GetName();
143 Tout->Add(name);
144 };
145 //
146 Tout->SetBranchAddress("RunInfo", GetPointerToRI());
147 printf("Run : set branch address RunInfo\n");
148 Tout->SetBranchAddress("SoftInfo", GetPointerToSI());
149 printf("Software : set branch address SoftInfo\n");
150 //
151 return Tout;
152 //
153 }
154
155 ItoRunInfo::ItoRunInfo(TSQLServer *db, TFile *processFl, TString processFld){
156 //
157 file=(TFile*)processFl;
158 dbc=(TSQLServer*)db;
159 processFolder = processFld;
160 //
161 reprocessing = false;
162 updating = false;
163 first_file_entry = 0;
164 last_file_entry = 0;
165 file_entries = 0;
166 version = new SoftInfo();
167 norun = 0;
168 totnorun = 0;
169 runlist = new TArrayI(500);
170 //
171 }
172
173 void ItoRunInfo::CopyFromTo(GL_RUN *glrun,GL_RUN *newrun,SoftInfo *sinfo, SoftInfo *newver){
174 //
175 if ( glrun && newrun ){
176 //
177 // printf("copy \n");
178 //
179 newrun->ID = glrun->ID ;
180 newrun->ID_RUN_FRAG = glrun-> ID_RUN_FRAG ;
181 newrun->ID_ROOT_L0 = glrun->ID_ROOT_L0 ;
182 newrun->ID_ROOT_L2 = glrun->ID_ROOT_L2 ;
183 newrun->RUNHEADER_TIME = glrun->RUNHEADER_TIME ;
184 newrun->RUNTRAILER_TIME = glrun->RUNTRAILER_TIME ;
185 newrun->EV_FROM = glrun->EV_FROM ;
186 newrun->EV_TO = glrun->EV_TO ;
187 newrun->TRK_CALIB_USED = glrun->TRK_CALIB_USED ;
188 newrun->EFF_WRK_SCHEDULE = glrun->EFF_WRK_SCHEDULE ;
189 newrun->PRH_VAR_TRG_MODE_A = glrun->PRH_VAR_TRG_MODE_A ;
190 newrun->PRH_VAR_TRG_MODE_B = glrun->PRH_VAR_TRG_MODE_B ;
191 newrun->ACQ_BUILD_INFO =glrun->ACQ_BUILD_INFO ;
192 newrun->ACQ_VAR_INFO = glrun->ACQ_VAR_INFO ;
193 newrun->RUNHEADER_OBT = glrun->RUNHEADER_OBT ;
194 newrun->RUNTRAILER_OBT = glrun->RUNTRAILER_OBT ;
195 newrun->RUNHEADER_PKT = glrun->RUNHEADER_PKT ;
196 newrun->RUNTRAILER_PKT = glrun->RUNTRAILER_PKT ;
197 newrun->NEVENTS = glrun->NEVENTS ;
198 newrun->LAST_TIMESYNC = glrun->LAST_TIMESYNC ;
199 newrun->OBT_TIMESYNC = glrun->OBT_TIMESYNC ;
200 newrun->COMPILATIONTIMESTAMP = glrun->COMPILATIONTIMESTAMP ;
201 newrun->FAV_WRK_SCHEDULE = glrun->FAV_WRK_SCHEDULE ;
202 newrun->RM_ACQ_AFTER_CALIB = glrun->RM_ACQ_AFTER_CALIB ;
203 newrun->RM_ACQ_SETTING_MODE = glrun->RM_ACQ_SETTING_MODE ;
204 newrun->PKT_COUNTER = glrun->PKT_COUNTER ;
205 newrun->PKT_READY_COUNTER = glrun->PKT_READY_COUNTER ;
206 newrun->TRK_CALIB_USED = glrun->TRK_CALIB_USED ;
207 newrun->CAL_DSP_MASK = glrun->CAL_DSP_MASK ;
208 newrun->BOOT_NUMBER = glrun->BOOT_NUMBER ;
209 newrun->PHYSENDRUN_MASK_S3S2S12 = glrun->PHYSENDRUN_MASK_S3S2S12 ;
210 newrun->PHYSENDRUN_MASK_S11CRC = glrun->PHYSENDRUN_MASK_S11CRC ;
211 newrun->VALIDATION = glrun->VALIDATION ;
212 //
213 };
214 //
215 if ( newver && sinfo ){
216 //
217 newver->TRIG_ver = sinfo->TRIG_ver;
218 newver->TOF_ver = sinfo->TOF_ver;
219 newver->AC_ver = sinfo->AC_ver;
220 newver->TRK_ver = sinfo->TRK_ver;
221 newver->ORB_ver = sinfo->ORB_ver;
222 newver->CAL_ver = sinfo->CAL_ver;
223 newver->S4_ver = sinfo->S4_ver;
224 newver->DV_ver = sinfo->DV_ver;
225 newver->ND_ver = sinfo->ND_ver;
226 //
227 };
228 }
229
230 Int_t ItoRunInfo::Update(UInt_t run, TString Detector, TString Version){
231 //
232 isreadonly = false;
233 idRun = run;
234 //
235 Bool_t debug = false;
236 //
237 // Bool_t ismydir = false;
238 //
239 if ( !strcmp(processFolder.Data(),"") ){
240 processFolder = "runinfoFolder";
241 // ismydir = true;
242 };
243 //
244 GL_RUN *oldrun = new GL_RUN();
245 GL_RUN *newrun = new GL_RUN();
246 SoftInfo *oldver = new SoftInfo();
247 SoftInfo *newver = new SoftInfo();
248 //
249 this->GL_RUN::Clear();
250 version->Clear();
251 //
252 norun = 0;
253 //
254 Bool_t found = false;
255 Int_t error = 0;
256 //
257 TTree *oldtree = 0;
258 //
259 // Try to get the tree Run in the processed file
260 //
261 oldtree = (TTree*)file->Get("Run");
262 //
263 // Look for detector's versions if we are updating a single detector
264 //
265 if ( debug ) printf("Detector -%s- \n",Detector.Data());
266 if ( !strcmp(Detector.Data(),"NONE") ){
267 version->TRIG_ver = Version;
268 version->TOF_ver = Version;
269 version->AC_ver = Version;
270 version->TRK_ver = Version;
271 version->ORB_ver = Version;
272 version->CAL_ver = Version;
273 version->S4_ver = Version;
274 version->DV_ver = Version;
275 version->ND_ver = Version;
276 } else {
277 if ( !strcmp(Detector.Data(),"TRIG") ) version->TRIG_ver = Version;
278 if ( !strcmp(Detector.Data(),"TOF") ) version->TOF_ver = Version;
279 if ( !strcmp(Detector.Data(),"AC") ) version->AC_ver = Version;
280 if ( !strcmp(Detector.Data(),"TRK") ) version->TRK_ver = Version;
281 if ( !strcmp(Detector.Data(),"CALO") ) version->CAL_ver = Version;
282 if ( !strcmp(Detector.Data(),"S4") ) version->S4_ver = Version;
283 if ( !strcmp(Detector.Data(),"DV") ) version->DV_ver = Version;
284 if ( !strcmp(Detector.Data(),"ND") ) version->ND_ver = Version;
285 if ( !strcmp(Detector.Data(),"ORB") ) version->ORB_ver = Version;
286 if ( strcmp(Detector.Data(),"TRIG") && strcmp(Detector.Data(),"TOF") && strcmp(Detector.Data(),"AC") && strcmp(Detector.Data(),"TRK") && strcmp(Detector.Data(),"CALO") && strcmp(Detector.Data(),"S4") && strcmp(Detector.Data(),"ND") && strcmp(Detector.Data(),"ORB") && strcmp(Detector.Data(),"DV") ) return(-804);
287 };
288 //
289 if ( !oldtree ) {
290 //
291 if ( strcmp(Detector.Data(),"NONE") ) return(-803);
292 updating = false;
293 if ( debug ) printf(" RunInfo: creating Run tree in this file\n");
294 //
295 } else {
296 //
297 updating = true;
298 if ( debug ) printf(" RunInfo: updating versioning information \n");
299 //
300 };
301 //
302 file->cd();
303 //
304 // Prepare a new tree to upgrade the contents of the old tree
305 //
306 newtree = new TTree("Run-new","PAMELA Level2 data from the GL_RUN table");
307 newtree->Branch("RunInfo","GL_RUN",&newrun);
308 newtree->Branch("SoftInfo","SoftInfo",&newver);
309 //
310 //
311 if ( !updating ){
312 if ( idRun == 0 ){
313 if ( debug ) printf("\n RUNINFO - ERROR: reprocessing data but no RunInfo tree in Level2 file. \n");
314 return(-805);
315 };
316 //
317 error = Query_GL_RUN(idRun, dbc);
318 //
319 if ( error ){
320 if ( debug ) printf("\n RUNINFO - ERROR: Query_GL_RUN exited with non zero error\n");
321 return(error);
322 };
323 if ( ID == 0 ){
324 if ( debug ) printf("\n RUNINFO - ERROR: no run with ID_RUN = %u \n",idRun);
325 return(-5);
326 };
327 //
328 //
329 CopyFromTo((GL_RUN*)this,newrun,version,newver);
330 //
331 // fill the tree;
332 //
333 newtree->Fill();
334 //
335 totnorun = 1;
336 reprocessing = false;
337 first_file_entry = 0;
338 if ( EV_TO >= EV_FROM ) last_file_entry = (UInt_t)(EV_TO - EV_FROM);
339 norun = 1;
340 runlist->AddAt((Int_t)ID,0);
341 //
342 newtree->SetName("Run");
343 //
344 file->cd();
345 //
346 delete newver;
347 delete newrun;
348 delete oldver;
349 delete oldrun;
350 //
351 return(0);
352 //
353 } else {
354 //
355 //
356 oldtree->SetBranchAddress("RunInfo",&oldrun);
357 oldtree->SetBranchAddress("SoftInfo",&oldver);
358 //
359 totnorun = oldtree->GetEntries();
360 //
361 if ( totnorun > 500 ){
362 if ( debug ) printf("\n RUNINFO - ERROR: can not handle more than 500 runs!\n");
363 return(-806);
364 };
365 //
366 found = false;
367 //
368 for ( UInt_t run = 0; run < totnorun; run++){
369 //
370 if ( oldtree->GetEntry(run) <= 0 ) throw -36;
371 //
372 CopyFromTo(oldrun,newrun,oldver,newver);
373 //
374 file_entries += (oldrun->EV_TO - oldrun->EV_FROM + 1);
375 //
376 if ( debug ) printf("totnorun %i idRun %i newrun->ID %i \n",(int)totnorun,(int)idRun,(int)newrun->ID);
377 //
378 if ( idRun == 0 || idRun == newrun->ID ) {
379 //
380 if ( debug ) printf(" Updating run number %u newrun->ID %i \n",idRun,(int)newrun->ID);
381 //
382 found = true;
383 //
384 runlist->AddAt(newrun->ID,norun);
385 norun++;
386 //
387 if ( !strcmp(Detector.Data(),"NONE") ){
388 //
389 // update infromations querying the DB
390 //
391 error = Query_GL_RUN(newrun->ID, dbc);
392 //
393 if ( error ){
394 if ( debug ) printf("\n RUNINFO - ERROR: Query_GL_RUN exited with non zero error\n");
395 return(error);
396 };
397 //
398 CopyFromTo((GL_RUN*)this,newrun,NULL,NULL);
399 //
400 } else {
401 //
402 if ( !strcmp(Detector.Data(),"TRIG") ){
403 newver->TRIG_ver = version->TRIG_ver;
404 newver->TOF_ver = oldver->TOF_ver;
405 newver->AC_ver = oldver->AC_ver;
406 newver->TRK_ver = oldver->TRK_ver;
407 newver->ORB_ver = oldver->ORB_ver;
408 newver->CAL_ver = oldver->CAL_ver;
409 newver->S4_ver = oldver->S4_ver;
410 newver->DV_ver = oldver->DV_ver;
411 newver->ND_ver = oldver->ND_ver;
412 if ( strcmp(oldver->TRIG_ver.Data(),"") ) reprocessing = true;
413 };
414 if ( !strcmp(Detector.Data(),"TOF") ){
415 newver->TRIG_ver = oldver->TRIG_ver;
416 newver->TOF_ver = version->TOF_ver;
417 newver->AC_ver = oldver->AC_ver;
418 newver->TRK_ver = oldver->TRK_ver;
419 newver->ORB_ver = oldver->ORB_ver;
420 newver->CAL_ver = oldver->CAL_ver;
421 newver->DV_ver = oldver->DV_ver;
422 newver->S4_ver = oldver->S4_ver;
423 newver->ND_ver = oldver->ND_ver;
424 if ( strcmp(oldver->TOF_ver.Data(),"") ) reprocessing = true;
425 };
426 if ( !strcmp(Detector.Data(),"AC") ){
427 newver->TRIG_ver = oldver->TRIG_ver;
428 newver->TOF_ver = oldver->TOF_ver;
429 newver->TRK_ver = oldver->TRK_ver;
430 newver->ORB_ver = oldver->ORB_ver;
431 newver->CAL_ver = oldver->CAL_ver;
432 newver->DV_ver = oldver->DV_ver;
433 newver->S4_ver = oldver->S4_ver;
434 newver->ND_ver = oldver->ND_ver;
435 newver->AC_ver = version->AC_ver;
436 if ( strcmp(oldver->AC_ver.Data(),"") ) reprocessing = true;
437 };
438 if ( !strcmp(Detector.Data(),"TRK") ){
439 newver->TRIG_ver = oldver->TRIG_ver;
440 newver->TOF_ver = oldver->TOF_ver;
441 newver->CAL_ver = oldver->CAL_ver;
442 newver->ORB_ver = oldver->ORB_ver;
443 newver->DV_ver = oldver->DV_ver;
444 newver->S4_ver = oldver->S4_ver;
445 newver->ND_ver = oldver->ND_ver;
446 newver->AC_ver = oldver->AC_ver;
447 newver->TRK_ver = version->TRK_ver;
448 if ( strcmp(oldver->TRK_ver.Data(),"") ) reprocessing = true;
449 };
450 if ( !strcmp(Detector.Data(),"ORB") ){
451 newver->TRIG_ver = oldver->TRIG_ver;
452 newver->TOF_ver = oldver->TOF_ver;
453 newver->CAL_ver = oldver->CAL_ver;
454 newver->TRK_ver = oldver->TRK_ver;
455 newver->DV_ver = oldver->DV_ver;
456 newver->S4_ver = oldver->S4_ver;
457 newver->ND_ver = oldver->ND_ver;
458 newver->AC_ver = oldver->AC_ver;
459 newver->ORB_ver = version->ORB_ver;
460 if ( strcmp(oldver->ORB_ver.Data(),"") ) reprocessing = true;
461 };
462 if ( !strcmp(Detector.Data(),"CALO") ){
463 newver->TRIG_ver = oldver->TRIG_ver;
464 newver->TOF_ver = oldver->TOF_ver;
465 newver->DV_ver = oldver->DV_ver;
466 newver->S4_ver = oldver->S4_ver;
467 newver->ORB_ver = oldver->ORB_ver;
468 newver->ND_ver = oldver->ND_ver;
469 newver->AC_ver = oldver->AC_ver;
470 newver->TRK_ver = oldver->TRK_ver;
471 newver->CAL_ver = version->CAL_ver;
472 if ( strcmp(oldver->CAL_ver.Data(),"") ) reprocessing = true;
473 };
474 if ( !strcmp(Detector.Data(),"S4") ){
475 newver->TRIG_ver = oldver->TRIG_ver;
476 newver->TOF_ver = oldver->TOF_ver;
477 newver->ND_ver = oldver->ND_ver;
478 newver->AC_ver = oldver->AC_ver;
479 newver->TRK_ver = oldver->TRK_ver;
480 newver->ORB_ver = oldver->ORB_ver;
481 newver->CAL_ver = oldver->CAL_ver;
482 newver->DV_ver = oldver->DV_ver;
483 newver->S4_ver = version->S4_ver;
484 if ( strcmp(oldver->S4_ver.Data(),"") ) reprocessing = true;
485 };
486 if ( !strcmp(Detector.Data(),"DV") ){
487 newver->TRIG_ver = oldver->TRIG_ver;
488 newver->TOF_ver = oldver->TOF_ver;
489 newver->ND_ver = oldver->ND_ver;
490 newver->AC_ver = oldver->AC_ver;
491 newver->TRK_ver = oldver->TRK_ver;
492 newver->ORB_ver = oldver->ORB_ver;
493 newver->CAL_ver = oldver->CAL_ver;
494 newver->S4_ver = oldver->S4_ver;
495 newver->DV_ver = version->DV_ver;
496 if ( strcmp(oldver->DV_ver.Data(),"") ) reprocessing = true;
497 };
498 if ( !strcmp(Detector.Data(),"ND") ){
499 newver->TRIG_ver = oldver->TRIG_ver;
500 newver->TOF_ver = oldver->TOF_ver;
501 newver->DV_ver = oldver->DV_ver;
502 newver->S4_ver = oldver->S4_ver;
503 newver->AC_ver = oldver->AC_ver;
504 newver->ORB_ver = oldver->ORB_ver;
505 newver->TRK_ver = oldver->TRK_ver;
506 newver->CAL_ver = oldver->CAL_ver;
507 newver->ND_ver = version->ND_ver;
508 if ( strcmp(oldver->ND_ver.Data(),"") ) reprocessing = true;
509 };
510 };
511 //
512 if ( oldrun->EV_TO >= oldrun->EV_FROM ) last_file_entry = first_file_entry + (oldrun->EV_TO - oldrun->EV_FROM + 1);
513 //
514 } else {
515 if ( !found ) first_file_entry += (oldrun->EV_TO - oldrun->EV_FROM + 1);
516 };
517 //
518 file->cd();
519 if ( debug ) printf("filling: totnorun %i idRun %i newrun->ID %i \n",(int)totnorun,(int)idRun,(int)newrun->ID);
520 newtree->Fill();
521 //
522 };
523 //
524 file->cd();
525 if ( oldtree ) oldtree->Delete("all");
526 newtree->SetName("Run");
527 //
528 delete newver;
529 delete newrun;
530 delete oldver;
531 delete oldrun;
532 //
533 if ( !found ){
534 if ( debug ) printf("\n RUNINFO - ERROR: no run with ID_RUN = %u \n",idRun);
535 return(-5);
536 };
537 //
538 this->Write();
539 // newtree->Write();
540 };
541 // if ( oldtree ) oldtree->Delete(); // crasha qua in queste righe e se non le metti...
542 // if ( newver ) delete newver;
543 // if ( newrun ) delete newrun;
544 // if ( oldver ) delete oldver;
545 // if ( oldrun ) delete oldrun;
546 return(0);
547 }
548
549 void ItoRunInfo::Write(){
550 file->cd();
551 newtree->Write("Run",TObject::kOverwrite);
552 }
553
554 Int_t ItoRunInfo::Read(UInt_t idRun){
555 //
556 isreadonly = true;
557 //
558 Bool_t debug = false;
559 //
560 SoftInfo *newver = new SoftInfo();
561 GL_RUN *newrun = new GL_RUN();
562 //
563 // Try to get the tree Run in the processed file
564 //
565 newtree = (TTree*)file->Get("Run");
566 //
567 if ( !newtree ) {
568 //
569 printf("\n RUNINFO - ERROR: no RunInfo tree in Level2 file. \n");
570 return(-801);
571 //
572 } else {
573 //
574 printf(" RunInfo: opening RunInfo tree \n");
575 //
576 newtree->SetBranchAddress("RunInfo",&newrun);
577 newtree->SetBranchAddress("SoftInfo",&newver);
578 //
579 totnorun = newtree->GetEntries();
580 //
581 if ( totnorun > 500 ){
582 if ( debug ) printf("\n RUNINFO - ERROR: can not handle more than 500 runs!\n");
583 return(-806);
584 };
585 //
586 first_file_entry = 0;
587 //
588 for ( UInt_t run = 0; run < totnorun; run++){
589 //
590 if ( newtree->GetEntry(run) <= 0 ) throw -36;
591 //
592 file_entries += (newrun->EV_TO - newrun->EV_FROM + 1);
593 //
594 if ( debug ) printf("totnorun %i newrun->ID %i \n",(int)totnorun,(int)newrun->ID);
595 //
596 CopyFromTo(newrun,(GL_RUN*)this,newver,version);
597 if ( idRun == ID || idRun == 0 ){
598 runlist->AddAt(newrun->ID,norun);
599 norun++;
600 };
601 if ( newrun->EV_TO >= newrun->EV_FROM ) last_file_entry = first_file_entry + (newrun->EV_TO - newrun->EV_FROM + 1);
602 };
603 };
604 if ( debug ) printf("norun %i \n",(int)norun);
605 Int_t error = 0;
606 error = GetRunInfo(idRun);
607 delete newver;
608 delete newrun;
609 if ( error ) return(error);
610 return(0);
611 }
612
613 void ItoRunInfo::Close(){
614 reprocessing = false;
615 updating = false;
616 first_file_entry = 0;
617 last_file_entry = 0;
618 file_entries = 0;
619 norun = 0;
620 delete runlist;
621 // file = new TFile();
622 file = 0;
623 // if ( isreadonly ) newtree->Delete();
624 }
625
626 void ItoRunInfo::Clear(Option_t *t){
627 if ( newtree ) newtree->Delete();
628 }
629
630 UInt_t ItoRunInfo::GetRunForEntry(UInt_t entry){
631 //
632 UInt_t startfrom = 0;
633 //
634 if ( entry >= (UInt_t)first_file_entry && entry <= (UInt_t)last_file_entry ) return(ID);
635 //
636 if ( entry > (UInt_t)last_file_entry ){
637 for ( UInt_t nrun = 0; nrun < norun; nrun++){
638 if ( ID == (UInt_t)runlist->At(nrun) ) {
639 startfrom = nrun+1;
640 break;
641 };
642 };
643 } else {
644 startfrom = 0;
645 };
646 //
647 if ( startfrom >= norun ) startfrom = 0;
648 //
649 retry:
650 //
651 for ( UInt_t nrun = startfrom; nrun < norun; nrun++){
652 GetRunInfo((UInt_t)runlist->At(nrun));
653 if ( entry >= (UInt_t)first_file_entry && entry <= (UInt_t)last_file_entry ){
654 return((UInt_t)runlist->At(nrun));
655 };
656 };
657 if ( startfrom ){
658 startfrom = 0;
659 goto retry;
660 };
661 printf(" ERROR! run not found \n");
662 return(0);
663 }
664
665 Int_t ItoRunInfo::GetRunInfo(UInt_t run){
666 Bool_t found = false;
667 SoftInfo *nwver = new SoftInfo();
668 GL_RUN *nwrun = new GL_RUN();
669 //
670 newtree->SetBranchAddress("RunInfo",&nwrun);
671 newtree->SetBranchAddress("SoftInfo",&nwver);
672 //
673 last_file_entry = 0;
674 first_file_entry = 0;
675 //
676 totnorun = newtree->GetEntries();
677 //
678 for ( UInt_t nrun = 0; nrun < totnorun; nrun++){
679 if ( newtree->GetEntry(nrun) <= 0 ) throw -36;
680 //
681 if ( nwrun->ID == run || run == 0 ){
682 CopyFromTo(nwrun,(GL_RUN*)this,nwver,version);
683 found = true;
684 if ( nwrun->EV_TO >= nwrun->EV_FROM ) last_file_entry = first_file_entry + (nwrun->EV_TO - nwrun->EV_FROM + 1);
685 };
686 if ( !found ) first_file_entry += (nwrun->EV_TO - nwrun->EV_FROM + 1);
687 };
688 delete nwver;
689 delete nwrun;
690 if ( found ) return(0);
691 return(-800);
692 }
693

  ViewVC Help
Powered by ViewVC 1.1.23