LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
AssembleSingleFile.C
Go to the documentation of this file.
1 TChain * CreateChainFromList_opt(std::string ListFileName, std::string ChainName, std::string BaseDirectory, bool DoCheck=false);
2 void MakeCombinedFile(std::string FileList, std::string BaseDirectory, std::string OutputName);
3 
4 
5 void AssembleSingleFile(std::string FileList, std::string BaseDirectory, std::string OutputName)
6 {
7 
8  TFile *f = TFile::Open(OutputName.c_str(),"RECREATE");
9  TChain * ch = CreateChainFromList_opt(FileList.c_str(),BaseDirectory.c_str(),"pmtresponse/PhotonLibraryData",false);
10 
11  Int_t Voxel, OpChannel;
12  Float_t Visibility;
13  ch->SetBranchAddress("Voxel", &Voxel);
14  ch->SetBranchAddress("OpChannel", &OpChannel);
15  ch->SetBranchAddress("Visibility", &Visibility);
16 
17  TTree * tt = new TTree("PhotonLibraryData","PhotonLibraryData");
18  tt->Branch("Voxel", &Voxel, "Voxel/I");
19  tt->Branch("OpChannel", &OpChannel, "OpChannel/I");
20  tt->Branch("Visibility", &Visibility, "Visibility/F");
21 
22  for(int i=0; i!=ch->GetEntries(); ++i)
23  {
24  ch->GetEntry(i);
25  tt->Fill();
26  }
27 
28  f->Write();
29  f->Close();
30 }
31 
32 
33 
34 
35 TChain * CreateChainFromList_opt(std::string ListFileName, std::string BaseDirectory, std::string ChainName, bool DoCheck)
36 {
37  std::ifstream InputFile(ListFileName.c_str());
38  std::string FileName;
39 
40  TChain * TheChain = new TChain(ChainName.c_str());
41  if(!DoCheck)
42  {
43  while(getline(InputFile, FileName))
44  {
45  FileName=BaseDirectory+FileName;
46  std::cout<<FileName.c_str()<<std::endl;
47  TheChain->Add(FileName.c_str());
48  }
49  }
50  else
51  {
52  while(getline(InputFile, FileName))
53  {
54  FileName=BaseDirectory+FileName;
55  TFile*f=TFile::Open(FileName.c_str());
56  if(f->Get(ChainName.c_str()))
57  {
58  std::cout<<FileName.c_str()<<std::endl;
59  TheChain->Add(FileName.c_str());
60  }
61  else std::cout<<"Chain " <<ChainName << " not found in file " << FileName<<std::endl;
62  }
63 
64 
65  }
66  return TheChain;
67 }
68 
69 
70 
TFile f
Definition: plotHisto.C:6
Definition: type_traits.h:56
TChain * CreateChainFromList_opt(std::string ListFileName, std::string ChainName, std::string BaseDirectory, bool DoCheck=false)
void AssembleSingleFile(std::string FileList, std::string BaseDirectory, std::string OutputName)
void MakeCombinedFile(std::string FileList, std::string BaseDirectory, std::string OutputName)