KaliVeda  1.12/06
Heavy-Ion Analysis Toolkit
KVRunListCreator.cpp
Go to the documentation of this file.
1 #include "KVRunListCreator.h"
2 #include "TEnv.h"
3 
4 #include <KVSystemDirectory.h>
5 #include <KVAvailableRunsFile.h>
6 #include <KVSystemFile.h>
7 
9 
10 
11 
16 KVRunListCreator::KVRunListCreator(const TString& dir, const TString& datatype, const TString& fmt)
17 {
18  // Give directory to scan, optional format for runfile names
19  // "datatype" should correspond to a known plugin for reading raw data files,
20  // see available plugins for KVRawDataReader (output of method KVBase::GetListOfPluginURIs("KVRawDataReader"))
21 
22  SetRunDir(dir);
23  if (fmt != "") SetFileFormat(fmt);
24  else SetFileFormat(gEnv->GetValue("DataSet.RunFileName.raw", "run_%04d.dat%*"));
25  fRunInfos.SetOwner();
26  fDataType = datatype;
27  ScanDirectory();
28  TFile f("runinfos.root", "recreate");
29  GetRunInfos().Write();
30  f.Close();
31 }
32 
33 
34 
37 
39 {
40  // Return number of runs found
41 
42  KVSystemDirectory sysdir("rundir", GetRunDir());
43  TIter it(sysdir.GetListOfFiles());
44  KVSystemFile* sysfile;
45  int howmany = 0;
46  while ((sysfile = (KVSystemFile*)it())) {
47  int run_num;
48  if ((run_num = KVAvailableRunsFile::IsRunFileName(GetFileFormat(), sysfile->GetName()))) {
49  KVDatime when;
51  ++howmany;
52  KVNameValueList* infos = new KVNameValueList;
53  infos->SetName(Form("run%010d", run_num));
54  infos->SetValue("Run", run_num);
55  infos->SetValue("Start", when.AsSQLString());
56  infos->SetValue("End", sysfile->GetDate());
57  Int_t x = sysfile->GetSize();
58  if (x == sysfile->GetSize())
59  infos->SetValue("Size", x);
60  else
61  infos->SetValue64bit("Size", sysfile->GetSize());
62  if (fDataType != "") {
63  fReader.reset(KVRawDataReader::OpenFile(fDataType, Form("%s/%s", sysdir.GetTitle(), sysfile->GetName())));
64  ULong64_t events = 0;
65  // correct start date/time from infos in file (GANIL/MFM data) ?
66  if (fReader->GetRunInfos().HasStringParameter("FileCreationTime")) {
67  when.SetGanacqNarvalDate(fReader->GetRunInfos().GetStringValue("FileCreationTime"));
68  infos->SetValue("Start", when.AsSQLString());
69  }
70  while (fReader->GetNextEvent()) ++events;
71 
72  infos->SetValue64bit("Events", events);
73  }
74  infos->ls();
75  fRunInfos.Add(infos);
76  }
77  }
78  }
79  return howmany;
80 }
81 
82 
int Int_t
ClassImp(KVPartitionList) void KVPartitionList
Initialisation.
#define f(i)
R__EXTERN TEnv * gEnv
char * Form(const char *fmt,...)
Bool_t ExtractDateFromFileName(const Char_t *name, KVDatime &date)
Int_t IsRunFileName(const Char_t *filename)
Extension of TDatime to handle various useful date formats.
Definition: KVDatime.h:32
void SetGanacqNarvalDate(const Char_t *GanacqDateString)
Definition: KVDatime.cpp:297
Handles lists of named parameters with different types, a list of KVNamedParameter objects.
virtual void ls(Option_t *opt="") const
void SetValue(const Char_t *name, value_type value)
void SetValue64bit(const Char_t *name, ULong64_t)
static KVRawDataReader * OpenFile(const TString &type, const TString &filename)
Set up a list of runs from a directory containing data files.
TString fDataType
type of data (KVRawDataReader plugin name)
KVUniqueNameList fRunInfos
const Char_t * GetFileFormat()
unique_ptr< KVRawDataReader > fReader
Int_t ScanDirectory()
Return number of runs found.
const Char_t * GetRunDir()
Extension of ROOT TSystemDirectory class, handling browsing directories on disk.
virtual TList * GetListOfFiles() const
Extended ROOT TSystemFile with added info on file size etc.
Definition: KVSystemFile.h:17
const Char_t * GetDate() const
Definition: KVSystemFile.h:43
Long64_t GetSize() const
Definition: KVSystemFile.h:39
virtual void Add(TObject *obj)
const char * AsSQLString() const
virtual const char * GetValue(const char *name, const char *dflt) const
virtual const char * GetName() const
virtual const char * GetTitle() const
virtual void SetName(const char *name)
unsigned long long ULong64_t
Double_t x[n]