1 #include "OutputConvention.h" 40 outFileName = getOutputDir();
43 TString theArgv0 = TString::Format(
"%s", argv[0]);
44 TObjArray* tkns = theArgv0.Tokenize(
"/");
45 if(tkns->GetSize() > 0){
46 TObjString* lastPartOfName = (TObjString*) tkns->At(tkns->GetLast());
47 theArgv0 = lastPartOfName->GetString();
51 outFileName += theArgv0;
55 for(
int argInd=1; argInd < argc; argInd++){
56 outFileName += TString::Format(
"_%s", argv[argInd]);
61 outFileName += getDateTimeSuffix();
65 outFileName +=
".root";
68 if(strncmp(ext.Data(),
".", 1)!=0){
69 ext = TString::Format(
".%s", ext.Data());
90 TString outFileName = getOutputFileName();
91 TFile* outFile =
new TFile(outFileName,
"recreate");
92 if(outFile->IsZombie()){
93 std::cerr <<
"Error! Unable to open output file " << outFileName.Data() << std::endl;
109 TString Acclaim::OutputConvention::getDateTimeSuffix(){
110 if(dateTimeSuffix==
""){
119 dateTimeSuffix = TString::Format(
"_%d", dateTime.GetYear());
121 Int_t m = dateTime.GetMonth();
123 dateTimeSuffix += TString::Format(
"-0%d", m);
126 dateTimeSuffix += TString::Format(
"-%d", m);
129 Int_t d = dateTime.GetDay();
131 dateTimeSuffix += TString::Format(
"-0%d", d);
134 dateTimeSuffix += TString::Format(
"-%d", d);
137 Int_t h = dateTime.GetHour();
139 dateTimeSuffix += TString::Format(
"_0%d", h);
142 dateTimeSuffix += TString::Format(
"_%d", h);
145 Int_t m2 = dateTime.GetMinute();
147 dateTimeSuffix += TString::Format(
"-0%d", m2);
150 dateTimeSuffix += TString::Format(
"-%d", m2);
153 Int_t s = dateTime.GetSecond();
155 dateTimeSuffix += TString::Format(
"-0%d", s);
158 dateTimeSuffix += TString::Format(
"-%d", s);
161 return dateTimeSuffix;
177 const char* outputDirPoss = getenv(
"OUTPUT_DIR");
178 if(outputDirPoss!=NULL){
179 outputDir += TString::Format(
"%s/", outputDirPoss);
201 TFile* theFile = NULL;
203 TChain* tempChain =
new TChain(
"tempChain");
204 tempChain->Add(fileNameWithWildcards);
206 TObjArray* fileList = tempChain->GetListOfFiles();
208 const int numFiles = fileList->GetEntries();
211 std::vector<TString> fileNames(numFiles,
"");;
213 for(
int fileInd=0; fileInd < numFiles; fileInd++){
214 fileNames.at(fileInd) = TString::Format(
"%s", fileList->At(fileInd)->GetTitle());
216 std::sort(fileNames.begin(), fileNames.end(), std::greater<TString>());
217 for(
int fileInd=0; fileInd < numFiles; fileInd++){
220 theFile = TFile::Open(fileNames.at(0));
OutputConvention(int argcIn, char *argvIn[])
Constructor.
static TFile * getFile(TString fileNameWithWildcards)
Opens matching file with the most recent suffix.
TFile * makeFile()
Create the new output file with proper name.
TString getOutputFileName(TString ext="")
Get the name of the output file from the program name (and system time).
TString getOutputDir()
Looks for an environment variable called OUTPUT_DIR and if it exists, sets it as the output dir...