3const Int_t ntokh[
nHead] = {7, 10, 6, 6, 8, 10, 16, 16, 16, 13, 13, 13, 13, 16, 2, 8};
6void ReadHeader(ifstream& fin, vector<TString>& header);
10void WriteEvent(ofstream& fout, vector<TString>& evBuff;);
23 gSystem->ExpandPathName(inFile);
26 cerr <<
"Error: Path does not exist: " << inFile << endl;
31 if (
gSystem->GetPathInfo(inFile, stat) != 0) {
32 cerr <<
"Error: Cannot get path info: " << inFile << endl;
37 vector<TString> filesToProcess;
39 if (stat.
fMode & S_IFREG) {
42 if (inFile.EndsWith(
".r12")) {
43 filesToProcess.push_back(inFile);
45 cerr <<
"Warning: Input file does not have .r12 extension: " << inFile << endl;
48 }
else if (stat.
fMode & S_IFDIR) {
50 void* dirp =
gSystem->OpenDirectory(inFile);
52 cerr <<
"Error: Cannot open directory: " << inFile << endl;
56 const char* p_file_name =
nullptr;
57 while ((p_file_name =
gSystem->GetDirEntry(dirp)) !=
nullptr) {
63 filesToProcess.push_back(fullPath);
68 cerr <<
"Error: Input path is neither a file nor a directory: " << inFile << endl;
72 const int nfiles = nbefore / nafter;
77 cout <<
"Found " << filesToProcess.size() <<
" file(s) to process:" << endl << endl;
78 for (
const auto& input_file : filesToProcess) {
79 cout <<
"Current input file: " << input_file << endl;
81 fin.open(input_file.Data());
84 vector<TString> header
ReadHeader(fin, header);
86 int success = 0, ntot = 0;
88 for (
int ifile = 0; ifile < nfiles; ++ifile) {
94 Int_t lastPos = -1, pos = 0;
100 outFile.
Replace(lastPos, event_before_k.
Length(), event_after_k);
103 int idot = input_file.
Last(
'.');
104 int iund = input_file.Last(
'_');
105 int last_number = (
TString(input_file(iund + 1, idot - iund - 1))).Atoi();
106 int new_last_number = (last_number - 1) * nfiles + ifile + 1;
107 TString str_new_last_number =
"";
108 str_new_last_number += new_last_number;
110 cout <<
" Current output file: " << outFile << endl;
114 fout.open(outFile.
Data());
115 for (
int j = 0; j <
nHead; ++j)
116 fout << header[j] << endl;
120 for (
Int_t iev = 0; iev < nbefore * 10; ++iev) {
121 vector<TString> evBuff;
128 evNew.
Form(
"%9d", nsel);
129 evBuff[0].Replace(0, 9, evNew);
133 cout << iev <<
" " << nsel <<
" " << success << endl;
137 cout <<
" Number of selected events: " << nsel << endl;
146 cout <<
" Total number of events: " << ntot << endl;
155 for (
Int_t ihead = 0; ihead <
nHead; ++ihead) {
157 header.push_back(chline);
168 Int_t success = 1, nPart = 0, nNucl = 0, iok = 0, iev = 0;
169 Float_t b, bx, by, beamA, beamZ;
173 for (
Int_t ihead = 0; ihead > -1; ++ihead) {
179 if (ntok <= 5 && ntok >= 3) {
186 if (token.IsDigit()) {
187 sscanf(chline.
Data(),
"%d %d %f %f %f", &iev, &nPart, &b, &bx, &by);
193 evBuff.push_back(chline);
194 }
else if (ntok == 8) {
198 if (token.IsDigit()) {
199 sscanf(chline.
Data(),
"%d %f %f", &nNucl, &beamA, &beamZ);
202 evBuff.push_back(chline);
205 for (
int j = 0; j < nNucl; ++j) {
207 evBuff.push_back(chline);
209 }
else if (ntok <= 1)
210 evBuff.push_back(chline);
221 for (
Int_t ipart = 0; ipart < nPart; ++ipart) {
223 evBuff.push_back(chline);
237 Int_t nlines = evBuff.size();
238 for (
int j = 0; j < nlines; ++j)
239 fout << evBuff[j] << endl;
255 Double_t ratio = ((double)nevent) / divider;
262 str.ReplaceAll(
",",
".");
264 if (str.EndsWith(
"."))
265 str.Remove(str.Length() - 1, 1);
Int_t ReadEvent(ifstream &fin, vector< TString > &evBuff;)
void ReadHeader(ifstream &fin, vector< TString > &header)
TString GetRatioString(Int_t nevent, Int_t divider)
Get a string representation of the ratio: nevent/divider If divider is zero, the result is "inf" The ...
void WriteEvent(ofstream &fout, vector< TString > &evBuff;)
void SplitDcmsmm(TString inFile="./DCMSMM_XeCsI_3.8_AGeV_mb_50k_2.r12", Int_t nbefore=10000, Int_t nafter=2500)
char * Form(const char *fmt,...)
R__EXTERN TSystem * gSystem
Int_t GetEntriesFast() const
void Delete(Option_t *option="") override
TObject * UncheckedAt(Int_t i) const
const TString & GetString() const
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
TString & Replace(Ssiz_t pos, Ssiz_t n, const char *s)
const char * Data() const
Ssiz_t Last(char c) const
TObjArray * Tokenize(const TString &delim) const
static TString Format(const char *fmt,...)
static TString Itoa(Int_t value, Int_t base)
void Form(const char *fmt,...)
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
std::istream & ReadLine(std::istream &str, Bool_t skipWhite=kTRUE)