41 #include <TObjArray.h>
42 #include <TObjString.h>
54 #include <TTimeStamp.h>
80 fUserGroup = gSystem->GetUserInfo();
81 fUserName = fUserGroup->fUser;
101 TChain*
chain =
new TChain(treeName);
116 if (!currentFile.Contains(
"root"))
continue;
118 if (counter<=startFile)
continue;
119 if ((maxFiles>0) && (counter>maxFiles+startFile))
break;
123 chain->Add(currentFile.Data());
144 TChain*
chain =
new TChain(treeName);
159 if (!currentFile.Contains(
"root"))
continue;
162 array.AddLast(
new TObjString(currentFile));
165 Int_t entries = array.GetEntries();
166 printf(
"Number of entries\t%d\n",entries);
170 Double_t *randomI =
new Double_t[entries];
171 Int_t *indexes =
new Int_t[entries];
172 for (Int_t i=0;i<entries; i++) randomI[i]=gRandom->Rndm();
173 TMath::Sort(entries,randomI,indexes);
175 for (Int_t i=startFile; (i<startFile+maxFiles) && (i<entries); i++){
176 Int_t ifile = indexes[i];
177 if (ifile<entries && (array.At(ifile)) && array.At(ifile)->TestBit(TObject::kCannotPick)==kFALSE){
178 printf(
"%d\t%d\t%s\n",i, ifile, array.At(ifile)->GetName());
179 chain->Add(array.At(ifile)->GetName());
180 array.At(ifile)->SetBit(TObject::kCannotPick);
195 TDSet*
chain =
new TDSet(treeName);
210 if (!currentFile.Contains(
"root"))
continue;
212 if (maxFiles>0 && counter>maxFiles)
break;
213 chain->Add(currentFile.Data());
232 TDSet*
chain =
new TDSet(treeName);
247 if (!currentFile.Contains(
"root"))
continue;
250 array.AddLast(
new TObjString(currentFile));
253 Int_t entries = array.GetEntries();
254 printf(
"Number of entries\t%d",entries);
255 if (maxFiles<0) maxFiles=entries;
256 if (maxFiles>entries) maxFiles=entries;
257 for (Int_t i=0; i<maxFiles; i++){
258 Int_t ifile = TMath::Nint(gRandom->Rndm()*Float_t(entries));
259 if (ifile<entries && (array.At(ifile)) && array.At(ifile)->TestBit(TObject::kCannotPick)==kFALSE){
260 printf(
"%d\t%d\t%s\n",i, ifile, array.At(ifile)->GetName());
261 chain->Add(array.At(ifile)->GetName());
262 array.At(ifile)->SetBit(TObject::kCannotPick);
291 if (!file) {
return -1;}
292 if (file->IsZombie()) {file->Close();
delete file;
return -2;};
294 TString TrName(treeName);
297 file->Close();
delete file;
300 TTree *
tree = (TTree*)file->Get(treeName);
301 if (!tree) {file->Close();
delete file;
return -3;}
302 TBranch * branch = 0;
304 branch = tree->GetBranch(branchName);
305 if (!branch) {file->Close();
delete file;
return -4;}
308 if (debugLevel==1 && tree->GetEntries()==0 )
return 1;
310 tree->SetBranchStatus(
"*",1);
313 Int_t entries = tree->GetEntries();
314 for (Int_t i=0;i<entries; i++){
315 if (branch) branch->GetEntry(i);
316 else tree->GetEntry();
322 file->Close();
delete file;
326 file->Close();
delete file;
348 gEnv->SetValue(
"TFile.Recover", 0);
351 finput.open(inputList, ios_base::in);
354 focGood.open(Form(
"%s.Good",inputList), ios_base::out|ios_base::trunc);
355 focBad.open(Form(
"%s.Bad",inputList), ios_base::out|ios_base::trunc);
357 if(!finput.is_open()) {
358 cout<<
"Can't open file "<<inputList<<endl;
367 while(finput.good()) {
368 finput >> currentFile;
369 if (!currentFile.Contains(
"root"))
continue;
370 if (currentFile.Contains(
"alien://")){
371 focGood<<currentFile<<endl;
374 Bool_t isZip = currentFile.Contains(
"#");
375 const char * dirname = gSystem->DirName(currentFile.Data());
378 for (Int_t i=0; i<array->GetEntries(); i+=2){
381 snprintf(fname,1000,
"%s/%s",dirname,array->At(i)->GetName());
382 if (((TObjString*)array->At(i))->String().Contains(
"*")){
383 snprintf(fname,1000,
"%s", currentFile.Data());
387 const char * fileName = gSystem->BaseName(currentFile.Data());
388 TString fstring=fileName;
389 fstring[fstring.First(
"#")]=0;
390 snprintf(fname,1000,
"%s/%s#%s",dirname,fstring.Data(),array->At(i)->GetName());
391 printf(fname,
"To check %s%s#%s\n",dirname,fstring.Data(),array->At(i)->GetName());
394 printf(
"\nFile to be checked %s\n",fname);
396 Int_t cstatus = CheckTreeInFile(fname, array->At(i+1)->GetName(), checkLevel,0);
404 focGood<<currentFile<<endl;
406 focBad<<currentFile<<endl;
434 finput.open(inputList, ios_base::in);
437 focGood.open(Form(
"%s.Good",inputList), ios_base::out|ios_base::trunc);
438 focBad.open(Form(
"%s.Bad",inputList), ios_base::out|ios_base::trunc);
440 if(!finput.is_open()) {
441 cout<<
"Can't open file "<<inputList<<endl;
450 while(finput.good()) {
451 finput >> currentFile;
452 if (!currentFile.Contains(
"root"))
continue;
453 if (currentFile.Contains(
"alien://")){
454 focGood<<currentFile<<endl;
458 const char * dirname = gSystem->DirName(currentFile.Data());
459 const char * fileName = gSystem->BaseName(currentFile.Data());
460 TString fstring=fileName;
461 fstring[fstring.First(
"#")]=0;
463 for (Int_t i=0; i<array->GetEntries(); i+=2){
466 snprintf(fname,1000,
"%s/%s#%s",dirname,fstring.Data(),array->At(i)->GetName());
467 printf(fname,
"To check %s%s#%s\n",dirname,fstring.Data(),array->At(i)->GetName());
469 Int_t cstatus = CheckTreeInFile(fname, array->At(i+1)->GetName(), checkLevel,0);
477 focGood<<currentFile<<endl;
479 focBad<<currentFile<<endl;
505 Int_t nfiles = array->GetEntries();
509 for (Int_t ifile =0; ifile<nfiles; ifile++){
510 snprintf(infile,1000,
"%s/%s", idir, array->At(ifile)->GetName());
511 snprintf(outfile,1000,
"%s/%s", odir, array->At(ifile)->GetName());
512 printf(
"%s - %s\n",infile, outfile);
513 Bool_t result = TFile::Cp(infile,outfile);
568 TFile *
fout =
new TFile(outputFile,
"recreate");
570 TTree *joinTree=
new TTree(outputTree,outputTree);
574 TObjArray *arrayInput = TString(inputTrees).Tokenize(
"+");
575 Int_t nTrees = arrayInput->GetEntries();
580 TArrayI arrayEnableTree(nTrees);
581 for (Int_t i=0; i<2; i++)
printf(
"\n");
584 for (Int_t i=0; i<2; i++)
printf(
"\n");
585 {
for (Int_t itree=0; itree<nTrees; itree++){
587 TObjArray *description = TString(arrayInput->At(itree)->GetName()).
Tokenize(
"#");
588 if (description->GetEntries()<4) {
589 printf(
"Fatal: Invalid description: %s\n", arrayInput->At(itree)->GetName());
594 printf(
"Fatal: Invalid description: fileName %s\n", description->At(4)->GetName());
598 arrayFile->AddAt(f,itree);
599 TTree *
tree = (TTree*)f->Get(description->At(3)->GetName());
601 printf(
"Fatal: Invalid description. Tree name\t%s\n", description->At(3)->GetName());
605 tree->SetCacheSize(400000000);
607 arrayTrees->AddAt(tree,itree);
609 arrayRunID->AddAt(
new TObjString(description->At(2)->GetName()),itree);
610 arrayNames->AddAt(
new TObjString(description->At(1)->GetName()),itree);
611 arrayEnableTree[itree]=atoi(description->At(0)->GetName());
619 map<int, int> runMap;
620 map<int, int> *runMapTree =
new map<int, int>[nTrees];
622 {
for (Int_t itree=0; itree<nTrees; itree++){
623 TTree *
tree = (TTree*)arrayTrees->At(itree);
624 Int_t entries=tree->GetEntries();
626 snprintf(query,2000,
"%s:Entry$", arrayRunID->At(itree)->GetName());
627 entries = tree->Draw(query,
"",
"goff");
628 for (Int_t ientry=0;ientry<entries; ientry++){
629 Int_t irun=Int_t(tree->GetV1()[ientry]);
631 if (arrayEnableTree[itree]>0) runMap[irun]+=1;
632 runMapTree[itree][irun]=ientry;
633 if (debugLevel>0)
printf(
"%s\t%d\t%d\n",tree->GetName(), irun, runMapTree[itree][irun]);
642 joinTree->Branch(indexName, &jrun,Form(
"%s/I",indexName));
643 Int_t *status=
new Int_t[nTrees];
644 char *brName =
new char[10000];
645 char *brTitle=
new char[10000];
648 {
for (Int_t itree=0; itree<nTrees; itree++){
649 TTree *
tree = (TTree*)arrayTrees->At(itree);
651 TString treeName=arrayNames->At(itree)->GetName();
652 if (treeName.Length()>0){
653 joinTree->Branch(Form(
"%s.status",treeName.Data()), &status[itree],Form(
"%s.status/I",treeName.Data()));
655 joinTree->Branch(
"status", &status[itree],
"status/I");
658 Int_t nbranches= tree->GetListOfBranches()->GetEntries();
659 for (Int_t ibr=0; ibr<nbranches; ibr++){
660 TBranch * br = (TBranch*)(tree->GetListOfBranches()->At(ibr));
661 if (treeName.Length()>0){
662 sprintf(brName,
"%s.%s",treeName.Data(), br->GetName());
663 sprintf(brTitle,
"%s.%s",treeName.Data(), br->GetTitle());
665 sprintf(brName,
"%s",br->GetName());
666 sprintf(brTitle,
"%s",br->GetTitle());
669 TString className=br->GetClassName();
670 if (className.Length()==0){
671 TString str(br->GetTitle());
672 if (str[str.Length()-1]==
'I') addr=
new Int_t;
673 if (str[str.Length()-1]==
'F') addr=
new Float_t;
674 if (str[str.Length()-1]==
'D') addr=
new Double_t;
675 if (str[str.Length()-1]==
'C') addr=
new Char_t[10000];
676 if (addr) joinTree->Branch(brName, addr, brTitle);
677 br->SetAddress(addr);
679 TClass cclass(className);
680 TObject **addrClass =
new TObject *;
682 printf(
"%s\t%s\n",br->GetName(), className.Data());
683 br->SetAddress(addrClass);
685 joinTree->Branch(brName,addrClass);
694 map<int, int>::iterator riter;
695 {
for (riter=runMap.begin(); riter != runMap.end(); ++riter){
696 printf(
"%d\t%d\t", riter->first, riter->second);
698 for (Int_t itree=0; itree<nTrees; itree++){
699 TTree *
tree = (TTree*)arrayTrees->At(itree);
700 Int_t entry= runMapTree[itree][jrun];
701 status[itree]=(entry>0)?1:0;
702 if (entry>=0) tree->GetEntry(entry);
710 joinTree->Write(outputTree);
731 fout.open(Form(
"%s.cache",fileIn));
733 foutLog.open(Form(
"%s.cacheLog",fileIn));
743 fname.ReplaceAll(
"-",
"_");
744 fname.ReplaceAll(
"/",
"_");
745 fname.ReplaceAll(
":",
"_");
746 fname.ReplaceAll(
"~",
"_");
747 cacheFile=cachePrefix;
749 printf(
"%s\t%s\n",currentFile.Data(),cacheFile.Data());
750 if (TFile::Cp(currentFile.Data(),cacheFile.Data())){
751 fout<<cacheFile.Data()<<
"\n";
752 foutLog<<s.AsString();
753 foutLog<<cacheFile.Data()<<
"n";
755 foutLog<<
"Copy failed"<<currentFile.Data()<<cacheFile.Data()<<
"\n";
777 printf(
"MakeTreeFromList\n");
779 printf(
"treeOut=%s\n",treeOut);
780 printf(
"treeIn=%s\n",treeIn);
781 printf(
"fileList=%s\n",flist);
786 foutLog.open(Form(
"%s.chainLog",flist));
794 foutLog<<
"Opening file"<<currentFile.Data();
796 foutLog<<
"Error opening file\t"<<currentFile<<
"\n";
797 cout<<
"Error opening file\t"<<currentFile<<
"\n";
800 TTree *
tree = (TTree*)f->Get(treeIn);
802 foutLog<<
"Error opening tree\t"<<currentFile<<treeIn<<
"\n";
803 cout<<
"Error opening tree\t"<<currentFile<<treeIn<<
"\n";
807 if (tree->GetListOfBranches()==0){
808 foutLog<<
"Error opening tree\t"<<currentFile<<treeIn<<
"\n";
809 cout<<
"Error opening tree\t"<<currentFile<<treeIn<<
"\n";
812 Int_t nbranchesCurrent = tree->GetListOfBranches()->GetEntries();
813 if ( nbranches ==0 ) nbranches=nbranchesCurrent;
814 if ( nbranches!=nbranchesCurrent){
815 foutLog<<
"Error tree layout\t"<<currentFile<<
" \t"<<treeIn<<
" \t"<<nbranches<<
" \t"<<nbranchesCurrent<<
"\n";
816 cout<<
"Error tree layout\t" <<currentFile<<
" \t"<<treeIn<<
" \t"<<nbranches<<
" \t"<<nbranchesCurrent<<
"\n";
821 foutLog<<
"Number of files"<<counter<<
"\n";
822 cout<<
"Number of files"<<counter<<
"\n";
827 if (!chain) status=kFALSE;
828 if (chain->GetEntries()==0) status=kFALSE;
830 printf(
"Incorrect list (%s) or trees (%s)", flist,treeIn);
834 TTree *
tree = chain->CopyTree(
"1");
836 tree->Write(treeOut);
printf("Chi2/npoints = %f\n", TMath::Sqrt(chi2/npoints))
TFile * Open(const char *filename, Long64_t &nevents)
TFile f("CalibObjects.root")
strP3 Tokenize("+") -> Print()