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