/[PAMELA software]/PadmeAmidala/src/RunGlue.cpp
ViewVC logotype

Contents of /PadmeAmidala/src/RunGlue.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.14 - (show annotations) (download)
Fri Dec 12 14:12:25 2008 UTC (15 years, 11 months ago) by mocchiut
Branch: MAIN
Changes since 1.13: +144 -143 lines
Do not calculate dltime

1 /**
2 * \file RunGlue.cpp
3 * \author Emiliano Mocchiutti
4 *
5 * The file contains implementation of the methods to query the DB.
6 */
7 //
8 #include <sstream>
9 #include <iostream>
10 //
11 #include <TFile.h>
12 #include <TTree.h>
13 #include <TTimeStamp.h>
14 #include <TTreeCloner.h>
15 #include <RunGlue.h>
16 //
17 ClassImp(RunGlue);
18 //
19 using namespace std;
20
21 RunGlue::RunGlue() {
22 this->Clear();
23 }
24
25 RunGlue::RunGlue(TSQLServer *da, UInt_t ru, TString di, TString wrkdi) {
26 fDBG = false;
27 li = new PamLevel2();
28 // li = 0;
29 this->Clear();
30 dbc = da;
31 run = ru;
32 dir = di;
33 //
34 wd = gSystem->WorkingDirectory();
35 //
36 outdir = wrkdi;
37 if ( !strcmp(outdir.Data(),"") ) outdir = wd;
38 fList = 0;
39 if ( run ){
40 runmode = true;
41 } else {
42 runmode = false;
43 createlist = true;
44 };
45 //
46 // lList = new TList();
47 //
48 };
49
50 void RunGlue::Clear() {
51 fEnd = false;
52 run = 0;
53 dir = "";
54 outdir = "";
55 fFilename = "";
56 };
57
58 void RunGlue::Clean() {
59 if ( !merged ) gSystem->Unlink(fFilename);
60 lList->Delete();
61 delete Target;
62 };
63
64 void RunGlue::SetDebug(Bool_t dbg) {
65 fDBG = dbg;
66 };
67
68 void RunGlue::SetDList(TString list) {
69 //
70 RUN = true;
71 //
72 if (list.Contains("-RUN", TString::kIgnoreCase)) RUN = false;
73 if (list.Contains("-ALL", TString::kIgnoreCase)) RUN = false;
74 if (list.Contains("+RUN", TString::kIgnoreCase)) RUN = true;
75 if (list.Contains("+ALL", TString::kIgnoreCase)) RUN = true;
76 //
77 fDList = list;
78 // li->SetWhichTrees(fDList);
79 //
80 if ( DebugMode() ) printf(" Detector list is %s \n",fDList.Data());
81 //
82 };
83
84 TList *RunGlue::GetRunList(){
85 //
86 lList = new TList();
87 lList->Clear();
88 TString thisrun;
89 TFile *su;
90 //
91 TSQLResult *pResult;
92 TSQLRow *Row;
93 //
94 if ( run && runmode ){
95 //
96 // Qurey the GL_RUN table to obtain RUN infos
97 //
98 GL_RUN *glrun = new GL_RUN();
99 glrun->Query_GL_RUN(run,dbc);
100 //
101 // convert RUNHEADER_TIME into a UTC date
102 //
103 GL_TIMESYNC *dbtime = new GL_TIMESYNC();
104 //
105 TString UTC="UTC";
106 TString rhdate=dbtime->ConvertTime(UTC,glrun->RUNHEADER_TIME);
107 //
108 TDatime ti = TDatime(rhdate.Data());
109 //
110 YY=(UInt_t)ti.GetYear();
111 MM=(UInt_t)ti.GetMonth();
112 DD=(UInt_t)ti.GetDay();
113 //
114 TTimeStamp *llim = new TTimeStamp(YY,MM,DD,0,0,0,0,true,0);
115 //
116 UInt_t lowerlimit = llim->GetSec();
117 UInt_t upperlimit = lowerlimit + 86401;
118 //
119 if ( DebugMode() ) printf(" YY %u MM %u DD %u ll %u ul %u \n",YY,MM,DD,lowerlimit,upperlimit);
120 //
121 YY -= 2000;
122 stringstream tmpf;
123 tmpf.str("");
124 tmpf << "L2PAM";
125 if ( YY < 10 ){
126 tmpf<< "0" << YY;
127 } else {
128 tmpf<< YY;
129 };
130 if ( MM < 10 ){
131 tmpf<< "0" << MM;
132 } else {
133 tmpf<< MM;
134 };
135 if ( DD < 10 ){
136 tmpf << "0" << DD << ".root";
137 } else {
138 tmpf << DD << ".root";
139 };
140 TString fpath = "";
141 if ( !strcmp(outdir,"") ){
142 fpath="./";
143 } else {
144 fpath += outdir;
145 fpath += "/";
146 };
147 //
148 fFilename = fpath + tmpf.str().c_str();
149 //
150 printf(" Output filename is %s \n",fFilename.Data());
151 //
152 if ( !this->OpenFile() ){
153 fEnd = true;
154 return(0);
155 };
156 //
157 stringstream myquery;
158 myquery.str("");
159 myquery << "SELECT ID FROM GL_RUN WHERE RUNHEADER_TIME>=" << (UInt_t)lowerlimit
160 << " AND RUNHEADER_TIME<" << (UInt_t)upperlimit << " ORDER BY RUNHEADER_TIME ASC;";
161 //
162 pResult = dbc->Query(myquery.str().c_str());
163 for( UInt_t r=0; r < 1000; r++){
164 Row = pResult->Next();
165 if( Row == NULL ) break;
166 if ( DebugMode() ) printf(" %u RUN %s \n",r,Row->GetField(0));
167 //
168 thisrun=dir+(TString)Row->GetField(0)+".Level2.root";
169 //
170 if ( DebugMode() ) printf(" Filename is %s \n",thisrun.Data());
171 //
172 su = TFile::Open(thisrun);
173 if ( li->CheckLevel2File(thisrun) ){
174 lList->Add(su);
175 } else {
176 if ( DebugMode() ) printf(" RUN %s DISCARDED \n",Row->GetField(0));
177 };
178 //
179 };
180 //
181 //
182 delete glrun;
183 delete dbtime;
184 //
185 };
186 //
187 if ( strcmp(dir.Data(),"" )){
188 //
189 if ( createlist ){
190 fList = new TList();
191 fDoneList = new TList();
192 fNlist = 0;
193 fNlistdone = 0;
194 //
195 // read files in the directory
196 //
197 if ( DebugMode() ) printf("\n No input run given\n Check for existing root files. \n");
198 //
199 TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(dir),dir);
200 TList *temp = datadir->GetListOfFiles();
201 //
202 TIter next(temp);
203 TSystemFile *questo = 0;
204 //
205 while ( (questo = (TSystemFile*)next()) ) {
206 TString name = questo->GetName();
207 if( name.EndsWith(".Level2.root") ){
208 char *fullpath0;
209 gSystem->IsFileInIncludePath(name,&fullpath0);
210 TString fullpath = fullpath0;
211 //
212 if ( DebugMode() ) printf(" fullpath = %s name %s \n",fullpath.Data(),name.Data());
213 //
214 //
215 su = TFile::Open(fullpath);
216 if ( li->CheckLevel2File((TString)fullpath) ){
217 fList->Add(su);
218 fNlist++;
219 } else {
220 if ( DebugMode() ) printf(" RUN %s DISCARDED \n",fullpath.Data());
221 };
222 //
223 };
224 };
225 createlist = false;
226 nrun = 0;
227 };
228 //
229 //
230 //
231 Bool_t stop = true;
232 UInt_t drun = 0;
233 while ( nrun < fNlist && stop ){
234 TString myrun = (TString)((TString)(gSystem->BaseName(((TFile*)fList->At(nrun))->GetName()))).ReplaceAll(".Level2.root",12,"",0);
235 if ( DebugMode() ) printf(" nrun %u myrun is %s \n",nrun,(myrun.ReplaceAll(".Level2.root",12,"",0)).Data());
236 run = (UInt_t)(myrun.Atoi());
237 nrun++;
238 //
239 TString donerun = "";
240 for (UInt_t ll=0; ll<fNlistdone; ll++){
241 donerun = "";
242 donerun = (TString)((TString)(gSystem->BaseName(((TFile*)fDoneList->At(ll))->GetName()))).ReplaceAll(".Level2.root",12,"",0);
243 if ( DebugMode() ) printf(" donerun is %s \n",(donerun.ReplaceAll(".Level2.root",12,"",0)).Data());
244 drun = (UInt_t)(donerun.Atoi());
245 //
246 if ( run == drun ) goto jump;
247 //
248 };
249 //
250 stop = false;
251 //
252 jump:
253 drun = 0;
254 //
255 };
256 //
257 if ( nrun >= fNlist && stop ){
258 fEnd = true;
259 return(0);
260 };
261 //
262 // Qurey the GL_RUN table to obtain RUN infos
263 //
264 printf(" PROCESSING RUN %u AND ITS FRIENDS\n",run);
265 GL_RUN *glrun = new GL_RUN();
266 glrun->Query_GL_RUN(run,dbc);
267 //
268 // convert RUNHEADER_TIME into a UTC date
269 //
270 GL_TIMESYNC *dbtime = new GL_TIMESYNC();
271 //
272 TString UTC="UTC";
273 TString rhdate=dbtime->ConvertTime(UTC,glrun->RUNHEADER_TIME);
274 //
275 TDatime ti = TDatime(rhdate.Data());
276 //
277 YY=(UInt_t)ti.GetYear();
278 MM=(UInt_t)ti.GetMonth();
279 DD=(UInt_t)ti.GetDay();
280 //
281 TTimeStamp *llim = new TTimeStamp(YY,MM,DD,0,0,0,0,true,0);
282 //
283 UInt_t lowerlimit = llim->GetSec();
284 UInt_t upperlimit = lowerlimit + 86401;
285 //
286 if ( DebugMode() ) printf(" YY %u MM %u DD %u ll %u ul %u \n",YY,MM,DD,lowerlimit,upperlimit);
287 //
288 YY -= 2000;
289 stringstream tmpf;
290 tmpf.str("");
291 tmpf << "L2PAM";
292 if ( YY < 10 ){
293 tmpf<< "0" << YY;
294 } else {
295 tmpf<< YY;
296 };
297 if ( MM < 10 ){
298 tmpf<< "0" << MM;
299 } else {
300 tmpf<< MM;
301 };
302 if ( DD < 10 ){
303 tmpf << "0" << DD << ".root";
304 } else {
305 tmpf << DD << ".root";
306 };
307 TString fpath = "";
308 if ( !strcmp(outdir,"") ){
309 fpath="./";
310 } else {
311 fpath += outdir;
312 fpath += "/";
313 };
314 //
315 fFilename = fpath + tmpf.str().c_str();
316 //
317 printf(" Output filename is %s \n",fFilename.Data());
318 //
319 if ( !this->OpenFile() ) return(0);
320 //
321 stringstream myquery;
322 myquery.str("");
323 myquery << "SELECT ID FROM GL_RUN WHERE RUNHEADER_TIME>=" << (UInt_t)lowerlimit
324 << " AND RUNHEADER_TIME<" << (UInt_t)upperlimit << " ORDER BY RUNHEADER_TIME ASC;";
325 //
326 pResult = dbc->Query(myquery.str().c_str());
327 for( UInt_t r=0; r < 1000; r++){
328 Row = pResult->Next();
329 if( Row == NULL ) break;
330 if ( DebugMode() ) printf(" %u RUN %s \n",r,Row->GetField(0));
331 //
332 thisrun=dir+(TString)Row->GetField(0)+".Level2.root";
333 //
334 if ( DebugMode() ) printf(" Filename is %s \n",thisrun.Data());
335 //
336 su = TFile::Open(thisrun);
337 if ( su ){
338 TFile *su0 = TFile::Open(thisrun);
339 fDoneList->Add(su0);
340 fNlistdone++;
341 };
342 if ( li->CheckLevel2File(thisrun) ){
343 lList->Add(su);
344 if ( DebugMode() ) printf(" RUN %s ADDED \n",Row->GetField(0));
345 } else {
346 if ( DebugMode() ) printf(" RUN %s DISCARDED \n",Row->GetField(0));
347 };
348 //
349 };
350 //
351 if ( DebugMode() ){
352 UInt_t ll = 0;
353 while ( (TFile*)lList->At(ll) ){
354 TString donerun = "";
355 donerun = (TString)((TString)(gSystem->BaseName(((TFile*)lList->At(ll))->GetName()))).ReplaceAll(".Level2.root",12,"",0);
356 printf(" XXX file is %s \n",donerun.Data());
357 ll++;
358 //
359 };
360 };
361 //
362 delete glrun;
363 delete dbtime;
364 //
365 };
366 //
367 // is it the end?
368 //
369 if ( runmode ){
370 fEnd = true;
371 } else {
372 //
373 // did we use all the run in the directory? if so exit
374 //
375 if ( nrun >= fNlist ) fEnd = true;
376 };
377 //
378 return(lList);
379 };
380
381 Bool_t RunGlue::OpenFile(){
382 //
383 fOpen = false;
384 printf(" Check if output file already exists \n");
385 ifstream myfile;
386 myfile.open((this->GetFilename()).Data());
387 if ( myfile ){
388 // Target = TFile::Open((this->GetFilename()).Data(), "READ" );
389 //
390 // if ( Target ){
391 // Target->Close();
392 myfile.close();
393 printf("Error opening target file, %s already exist!\n",(this->GetFilename()).Data());
394 return(false);
395 } else {
396 //
397 printf(" Output file does not exist, creating it\n");
398 //
399 Long64_t maxsize = 99900000000LL;
400 //
401 Target = TFile::Open((this->GetFilename()).Data(), "RECREATE" );
402 //fastMethod = kTRUE;
403 fastMethod = kFALSE;
404 //
405 //
406 if ( !Target || Target->IsZombie()) {
407 printf("Error opening target file (does %s exist?)\n",(this->GetFilename()).Data());
408 exit(1);
409 }
410 //
411 TTree::SetMaxTreeSize(maxsize);
412 // Target->SetCompressionLevel(2);
413 Target->SetCompressionLevel(3);
414 //Target->SetCompressionLevel(5);
415 //
416 fOpen = true;
417 return(true);
418 //
419 };
420 //
421 return(true);
422 //
423 };
424
425
426 void RunGlue::DeleteRunFiles(TList *dlist){
427 //
428 TString donerun = "";
429 //
430 printf(" Deleting runs: \n");
431 //
432 UInt_t ll = 0;
433 //
434 while ( (TFile*)dlist->At(ll) ){
435 donerun = (TString)(((TFile*)dlist->At(ll))->GetName());
436 gSystem->Unlink(donerun);
437 printf(" Deleted file is %s \n",donerun.Data());
438 ll++;
439 //
440 };
441 };
442
443 void RunGlue::UpdateDB(TList *dlist){
444 //
445 TSQLResult *pResult;
446 TSQLRow *Row;
447 stringstream myquery;
448 //
449 TString donerun = "";
450 //
451 if ( DebugMode() ) printf(" Updating GL_RUN: \n");
452 //
453 UInt_t ll = 0;
454 UInt_t idl2 = 0;
455 UInt_t idr = 0;
456 //
457 //
458 myquery.str("");
459 myquery << "select ID from GL_RAW where NAME='level2 files';";
460 if ( DebugMode() ) printf(" query is %s \n",myquery.str().c_str());
461 //
462 pResult = dbc->Query(myquery.str().c_str());
463 if ( !pResult ){
464 printf(" ERROR QUERYING ON DB!\n");
465 return;
466 };
467 Row = pResult->Next();
468 if( Row == NULL ){
469 printf(" ERROR QUERYING THE DB!\n");
470 return;
471 } else {
472 idr = (UInt_t)atoll(Row->GetField(0));
473 };
474 //
475 myquery.str("");
476 // myquery << "insert into GL_ROOT (ID_RAW,PATH,NAME) values (" << idr << ",'" << outdir.Data() << "','" << ((TString)gSystem->BaseName(this->GetFilename())).Data() << "');";
477 myquery << "insert into GL_ROOT (ID_RAW,PATH,NAME) values (" << idr << ",'$PAM_L2','" << ((TString)gSystem->BaseName(this->GetFilename())).Data() << "');";
478 if ( DebugMode() ) printf(" query is %s \n",myquery.str().c_str());
479 //
480 pResult = dbc->Query(myquery.str().c_str());
481 if ( !pResult ){
482 printf(" ERROR WRITING ON DB!\n");
483 return;
484 };
485 myquery.str("");
486 myquery << "select ID from GL_ROOT where NAME='" << ((TString)gSystem->BaseName(this->GetFilename())).Data() << "';";
487 if ( DebugMode() ) printf(" query is %s \n",myquery.str().c_str());
488 //
489 pResult = dbc->Query(myquery.str().c_str());
490 if ( !pResult ){
491 printf(" ERROR WRITING ON DB!\n");
492 return;
493 };
494 Row = pResult->Next();
495 if( Row == NULL ){
496 printf(" ERROR QUERYING THE DB!\n");
497 return;
498 } else {
499 idl2 = (UInt_t)atoll(Row->GetField(0));
500 };
501 //
502 //
503 //
504 UInt_t drun = 0;
505 //
506 while ( (TFile*)dlist->At(ll) ){
507 donerun = "";
508 donerun = (TString)((TString)(gSystem->BaseName(((TFile*)dlist->At(ll))->GetName()))).ReplaceAll(".Level2.root",12,"",0);
509 drun = (UInt_t)(donerun.Atoi());
510 //
511 if ( DebugMode() ) printf(" Run is %s \n",donerun.Data());
512 //
513 myquery.str("");
514 myquery << "update GL_RUN set ID_ROOT_L2=" << idl2 << " where ID=" << drun << ";";
515 if ( DebugMode() ) printf(" query is %s \n",myquery.str().c_str());
516 //
517 pResult = dbc->Query(myquery.str().c_str());
518 if ( !pResult ){
519 printf(" ERROR WRITING ON DB!\n");
520 return;
521 };
522 //
523 ll++;
524 //
525 };
526 };
527
528 //
529 // method stolen to ROOT's "hadd" and modified
530 //
531 void RunGlue::MergeRootfile(TList *sourcelist) {
532 //
533 merged = true;
534 //
535 if ( li ) li->Delete();
536 li = new PamLevel2(wd,sourcelist,fDList);
537 li->SetSELLI(2);
538 //
539 Target->cd();
540 //
541 li->CreateCloneTrees(Target);
542 ULong64_t nevents = li->GetEntries();
543 printf(" NEVENTS %llu \n",nevents);
544 for(ULong64_t iev=0; iev<nevents; iev++){
545 li->Clear();
546 if( li->GetEntry(iev) ){
547 li->FillCloneTrees();
548 };
549 };
550 Target->cd();
551 li->WriteCloneTrees();
552 printf("Written file %s \n",Target->GetName());
553 // Target->Write();
554 // TTree *slist = (TTree*)Target->Get("SelectionList");
555 // slist->Delete("all");
556 Target->Close();
557
558 // //
559 // TDirectory *target = Target;
560 // //
561 // if ( DebugMode() ) printf("\nTarget path is: %s \n",target->GetPath());
562 // //
563 // TString path( (char*)strstr( target->GetPath(), ":" ) );
564 // path.Remove(0,2);
565 // //
566 // TDirectory *first_source = (TDirectory*)sourcelist->First();
567 // THashList allNames;
568 // //
569 // while ( first_source ){
570 // //
571 // TDirectory *current_sourcedir = first_source->GetDirectory(path);
572 // //
573 // if ( !current_sourcedir ){
574 // first_source = (TDirectory*)sourcelist->After(first_source);
575 // continue;
576 // }
577 // //
578 // // loop over all keys in this directory
579 // //
580 // TChain *globChain = 0;
581 // TIter nextkey( current_sourcedir->GetListOfKeys() );
582 // TKey *key = 0;
583 // TKey *oldkey = 0;
584 // TH1::AddDirectory(kFALSE); // gain time, do not add the objects in the list in memory
585 // //
586 // while ( (key = (TKey*)nextkey()) ) {
587 // //
588 // // printf(" target ls \n");
589 // // Target->ls();
590 // //
591 // if ( current_sourcedir == target ) break;
592 // //
593 // if ( oldkey && !strcmp(oldkey->GetName(),key->GetName()) ) continue; //keep only the highest cycle number for each key
594 // //
595 // if ( allNames.FindObject(key->GetName()) ) continue;
596 // //
597 // if ( DebugMode() ) printf(" Key name is -%s- \n",key->GetName());
598 // //
599 // //
600 // //
601 // if ( !strcmp(key->GetName(),"Tracker") && !li->IsTRK2() && !li->IsTRK1() && !li->IsTRKh() ) continue;
602 // //
603 // if ( !strcmp(key->GetName(),"Calorimeter") && !li->IsCAL2() && !li->IsCAL1() ) continue;
604 // //
605 // if ( !strcmp(key->GetName(),"ToF") && !li->IsTOF() ) continue;
606 // //
607 // if ( !strcmp(key->GetName(),"Trigger") && !li->IsTRG() ) continue;
608 // //
609 // if ( !strcmp(key->GetName(),"Anticounter") && !li->IsAC() ) continue;
610 // //
611 // if ( !strcmp(key->GetName(),"S4") && !li->IsS4() ) continue;
612 // //
613 // if ( !strcmp(key->GetName(),"NeutronD") && !li->IsND() ) continue;
614 // //
615 // if ( !strcmp(key->GetName(),"OrbitalInfo") && !li->IsORB() ) continue;
616 // //
617 // if ( !strcmp(key->GetName(),"Run") && !li->IsRUN() ) continue;
618 // //
619 // if ( strcmp(key->GetName(),"Calorimeter") && strcmp(key->GetName(),"Tracker") && strcmp(key->GetName(),"ToF") && strcmp(key->GetName(),"Trigger") && strcmp(key->GetName(),"Anticounter") && strcmp(key->GetName(),"S4") && strcmp(key->GetName(),"NeutronD") && strcmp(key->GetName(),"OrbitalInfo") && strcmp(key->GetName(),"Run") && strcmp(key->GetName(),"ProcessID0") ){
620 // if ( DebugMode() ) printf(" ERROR UNKNOWN KEY %s !\n",key->GetName());
621 // continue;
622 // };
623 // //
624 // printf(" 1 \n");
625 // allNames.Add(new TObjString(key->GetName()));
626 // printf(" 2 \n");
627 // //
628 // // read object from first source file
629 // //
630 // current_sourcedir->cd();
631 // TObject *obj = key->ReadObj();
632 // printf(" 3 \n");
633 // //
634 // if ( obj->IsA()->InheritsFrom("TTree") ){
635 // //
636 // // loop over all source files create a chain of Trees "globChain"
637 // //
638 // TString obj_name;
639 // printf(" 4 \n");
640 // //
641 // if ( path.Length() ) {
642 // obj_name = path + "/" + obj->GetName();
643 // } else {
644 // obj_name = obj->GetName();
645 // };
646 // //
647 // globChain = new TChain(obj_name);
648 // //
649 // globChain->SetCacheSize(0);
650 // //
651 // printf(" 5 \n");
652 // globChain->Add(first_source->GetName());
653 // printf(" 6 \n");
654 // //
655 // TFile *nextsource = (TFile*)sourcelist->After( first_source );
656 // //
657 // while ( nextsource ) {
658 // //
659 // //do not add to the list a file that does not contain this Tree
660 // //
661 // printf(" 7 \n");
662 // TFile *curf = TFile::Open(nextsource->GetName());
663 // //
664 // if ( curf ) {
665 // //
666 // Bool_t mustAdd = kFALSE;
667 // //
668 // if (curf->FindKey(obj_name)) {
669 // //
670 // mustAdd = kTRUE;
671 // //
672 // } else {
673 // //
674 // //we could be more clever here. No need to import the object
675 // //we are missing a function in TDirectory
676 // //
677 // TObject *aobj = curf->Get(obj_name);
678 // //
679 // if ( aobj ){
680 // mustAdd = kTRUE;
681 // delete aobj;
682 // };
683 // };
684 // if (mustAdd) {
685 // printf(" 8 \n");
686 // globChain->Add(nextsource->GetName());
687 // printf(" 9 \n");
688 // };
689 // };
690 // delete curf;
691 // nextsource = (TFile*)sourcelist->After(nextsource);
692 // };
693 // //
694 // printf(" 10 \n");
695 // delete nextsource;
696 // printf(" 11 \n");
697 // //
698 // } else {
699 // //
700 // // object is of no type that we know or can handle
701 // //
702 // if ( DebugMode() ) cout << "Unknown object type, name: "
703 // << obj->GetName() << " title: " << obj->GetTitle() << endl;
704 // };
705 // //
706 // // now write the merged histogram (which is "in" obj) to the target file
707 // // note that this will just store obj in the current directory level,
708 // // which is not persistent until the complete directory itself is stored
709 // // by "target->Write()" below
710 // //
711 // printf(" 12 \n");
712 // if ( obj ){
713 // //
714 // target->cd();
715 // //
716 // if( obj->IsA()->InheritsFrom("TTree") ) {
717 // //
718 // Long64_t nfiles = 0;
719 // if ( fastMethod ){
720 // // globChain->Merge(target->GetFile(),0,"C keep fast");
721 // nfiles=this->Mergy((TChain*)globChain,target->GetFile(),0,"C keep fast");
722 // } else {
723 // //globChain->Merge(target->GetFile(),0,"C keep");
724 // printf(" 13 %llu \n",globChain->GetEntries());
725 // nfiles=this->Mergy((TChain*)globChain,target->GetFile(),0,"C keep");
726 // printf(" 14 \n");
727 // };
728 // //
729 // merged = true;
730 // //
731 // if ( DebugMode() ){
732 // printf(" Merged %i files\n",(int)nfiles);
733 // globChain->ls();
734 // };
735 // //
736 // delete globChain;
737 // // return;
738 // //
739 // } else {
740 // //
741 // // obj->Write( key->GetName() ); // <==================================================================================
742 // //
743 // };
744 // };
745 // delete obj;
746 // oldkey = key;
747 // };
748 // //
749 // first_source = (TDirectory*)sourcelist->After(first_source);
750 // //
751 // };
752 // // save modifications to target file
753 // //
754 // target->SaveSelf(kTRUE);
755 // //
756 };
757
758
759 // Long64_t RunGlue::Mergy(TChain *mychain, TFile* file, Int_t basketsize, Option_t* option){
760 // // We must have been passed a file, we will use it
761 // // later to reset the compression level of the branches.
762 // if (!file) {
763 // // FIXME: We need an error message here.
764 // printf(" 19 \n");
765 // return 0;
766 // }
767 // printf(" 20 \n");
768
769 // // Options
770 // Bool_t fastClone = kFALSE;
771 // TString opt = option;
772 // opt.ToLower();
773 // if (opt.Contains("fast")) {
774 // fastClone = kTRUE;
775 // printf(" 21 \n");
776 // }
777 // // The chain tree must have a list of branches
778 // // because we may try to change their basket
779 // // size later.
780 // TObjArray* lbranches = mychain->GetListOfBranches();
781 // if (!lbranches) {
782 // // FIXME: We need an error message here.
783 // printf(" 22 \n");
784 // return 0;
785 // }
786
787 // // file->cd();
788 // // The chain must have a current tree because
789 // // that is the one we will clone.
790 // // if (!fTree) {
791 // // -- LoadTree() has not yet been called, no current tree.
792 // // FIXME: We need an error message here.
793 // // return 0;
794 // // }
795
796 // // Copy the chain's current tree without
797 // // copying any entries, we will do that later.
798 // printf(" 23 \n");
799 // TTree* newTree = mychain->CloneTree(0);
800 // if (!newTree) {
801 // // FIXME: We need an error message here.
802 // printf(" 24 \n");
803 // return 0;
804 // }
805 // printf(" 25 \n");
806
807
808 // // Strip out the (potential) directory name.
809 // // FIXME: The merged chain may or may not have the
810 // // same name as the original chain. This is
811 // // bad because the chain name determines the
812 // // names of the trees in the chain by default.
813 // printf(" 26 \n");
814 // newTree->SetName(gSystem->BaseName(mychain->GetName()));
815 // printf(" 27 \n");
816
817 // // FIXME: Why do we do this?
818 // // newTree->SetAutoSave(-1);
819 // newTree->SetAutoSave(900000000000000LL);
820
821 // printf(" 28 \n");
822 // // Circularity is incompatible with merging, it may
823 // // force us to throw away entries, which is not what
824 // // we are supposed to do.
825 // newTree->SetCircular(0);
826
827 // // Reset the compression level of the branches.
828 // if (opt.Contains("c")) {
829 // TBranch* branch = 0;
830 // TIter nextb(newTree->GetListOfBranches());
831 // while ((branch = (TBranch*) nextb())) {
832 // printf(" 29 \n");
833 // branch->SetCompressionLevel(file->GetCompressionLevel());
834 // }
835 // }
836
837 // printf(" 30 \n");
838 // // Reset the basket size of the branches.
839 // if (basketsize > 1000) {
840 // TBranch* branch = 0;
841 // TIter nextb(newTree->GetListOfBranches());
842 // while ((branch = (TBranch*) nextb())) {
843 // printf(" 31 \n");
844 // branch->SetBasketSize(basketsize);
845 // }
846 // }
847
848 // printf(" 32 \n");
849 // Long64_t nentries = mychain->GetEntriesFast();
850 // //Long64_t nentries = mychain->GetEntries();
851
852 // // Copy the entries.
853 // if (fastClone) {
854 // // For each tree in the chain.
855 // for (Long64_t i = 0; i < nentries; i += mychain->GetTree()->GetEntries()) {
856 // if (mychain->LoadTree(i) < 0) {
857 // break;
858 // }
859 // TTreeCloner cloner(mychain->GetTree(), newTree, option);
860 // if (cloner.IsValid()) {
861 // newTree->SetEntries(newTree->GetEntries() + mychain->GetTree()->GetEntries());
862 // cloner.Exec();
863 // } else {
864 // if (mychain->GetFile()) {
865 // printf("Merge Skipped file %s\n", mychain->GetFile()->GetName());
866 // // } else {
867 // // Warning("Merge", "Skipped file number %d\n", fTreeNumber);
868 // }
869 // }
870 // }
871 // } else {
872 // printf(" 33 %llu \n",nentries);
873 // mychain->Print();
874 // for (Long64_t i = 0; i < nentries; i++) {
875 // printf(" i %llu \n",i);
876 // // for (Long64_t i = 0; i < 1; i++) {
877 // if (mychain->GetEntry(i) <= 0) {
878 // break;
879 // }
880 // newTree->Fill();
881 // }
882 // printf(" 34 \n");
883 // }
884
885 // // Write the new tree header.
886 // printf(" 35 \n");
887 // newTree->Write();
888
889 // printf(" 36 \n");
890 // // Get our return value.
891 // Int_t nfiles = newTree->GetFileNumber() + 1;
892
893 // // Close and delete the current file of the new tree.
894 // if (!opt.Contains("keep")) {
895 // // FIXME: What happens to fDirectory in newTree here?
896 // delete newTree->GetCurrentFile();
897 // }
898 // return nfiles;
899 // }

  ViewVC Help
Powered by ViewVC 1.1.23