20 #include <TAuthenticate.h>
21 #include <TCollection.h>
23 #include <TDirectory.h>
24 #include <TEventList.h>
27 #include <TGFileDialog.h>
28 #include <TGInputDialog.h>
35 #include "TDataMember.h"
48 using Diana::QVectorI;
51 : fFile(0), fFileOpen(false), fHeader(0), fPulseInfo(0), fQChain(0)
68 bool foundModifiedFile =
false;
71 map<string, time_t>::const_iterator fileIter;
76 foundModifiedFile =
true;
79 if (foundModifiedFile) {
80 cout <<
"Some open files were modified. Reopening files." << endl;
85 return foundModifiedFile;
105 fQChain->GetEntry(eventNumber);
108 if(!samplesname.empty() &&
fQChain->FindBranch(samplesname.c_str())) {
109 std::string brname = samplesname;
110 br =
fQChain->GetBranch(brname.c_str());
111 TLeaf* leaf = br->GetLeaf(brname.c_str());
113 const char* leafType = leaf->GetTypeName();
114 TClass thisClass(leafType);
115 bool isQVector = std::string(
"Diana::QVector") == thisClass.GetName();
116 bool isQVectorI = std::string(
"Diana::QVectorI") == thisClass.GetName();
117 bool isQPulse = std::string(
"QPulse") == thisClass.GetName();
120 fQChain->SetBranchAddress(samplesname.c_str(),&samples);
121 fQChain->GetEntry(eventNumber);
123 }
else if(isQVectorI) {
125 fQChain->SetBranchAddress(samplesname.c_str(),&samples);
126 fQChain->GetEntry(eventNumber);
128 }
else if(isQPulse) {
130 fQChain->SetBranchAddress(samplesname.c_str(),&samples);
131 fQChain->GetEntry(eventNumber);
136 fQChain->GetEntry(eventNumber);
140 if(br)
fQChain->ResetBranchAddress(br);
145 fQChain->Draw(
">>eList", cuts,
"goff same");
147 TEventList *eventListPtr = (TEventList*) gDirectory->Get(
"eList");
148 TEventList eventList = *eventListPtr;
149 eventList.SetName(
"eventList");
182 const Long64_t eventNumber)
186 static vector<QSampleInfo> empty;
205 if(rh.IsValid())
return &rh.Get();
209 fQChain->LoadTree(eventNumber);
210 TTree *tree =
fQChain->GetTree();
212 TDirectory *directory = tree->GetDirectory();
220 string currentFile = directory->GetName();
221 string firstPartial = currentFile;
222 firstPartial.replace(firstPartial.size() - 8, 3,
"001");
226 if(rh.IsValid())
return &(rh.Get());
235 if(!runData)
return 0;
253 int N = aliasList->GetSize();
254 for (
int i = 0; i <
N; ++i) {
256 = aliasList->At(i)->GetName();
257 bool notSamples = (alias !=
"Samples");
259 aliases.insert(alias);
263 if (
fQChain->GetListOfAliases() ) {
264 int N =
fQChain->GetListOfAliases()->GetSize();
265 for (
int i = 0; i <
N; ++i) {
266 string alias =
fQChain->GetListOfAliases()->At(i)->GetName();
267 aliases.insert(alias);
283 int N = leafList->GetSize();
284 for (
int i = 0; i <
N; ++i) {
285 TLeaf *leaf = (TLeaf*) leafList->At(i);
287 string type = leaf->GetTypeName();
288 string name = leaf->GetName();
290 bool notfUniqueID = name.find(
".fUniqueID") == string::npos;
291 bool notfBits = name.find(
".fBits") == string::npos;
292 if (numericType && notfUniqueID && notfBits) {
305 TIter next(leafList);
306 while(TLeaf* leaf = (TLeaf*)next()) {
308 string type = leaf->GetTypeName();
309 string name = leaf->GetName();
310 TClass thisClass(type.c_str(),kTRUE);
311 bool isQVector = std::string(
"Diana::QVector") == thisClass.GetName();
312 bool isQVectorI = std::string(
"Diana::QVectorI") == thisClass.GetName();
313 bool isQPulse = std::string(
"QPulse") == thisClass.GetName();
314 bool isQPulseC = std::string(
"QPulseC") == thisClass.GetName();
315 if (isQVector || isQVectorI || isQPulse || isQPulseC) {
329 cout << endl << endl;
332 cout <<
"There is 1 open file:" << endl;
334 cout <<
"There are " <<
fFilenames.size() <<
" open files:" << endl;
335 for (
unsigned int i = 0; i !=
fFilenames.size(); ++i) {
339 cout <<
"There are no open files." << endl;
353 if (stat(filename.c_str(), &attrib) != -1) {
354 mtime = attrib.st_mtime;
366 fi.fIniDir = StrDup(dir);
367 const char *filetypes[] = {
"ROOT files",
"*.root",
368 "File lists",
"*.list",
370 fi.fFileTypes = filetypes;
371 new TGFileDialog(gClient->GetRoot(), 0, kFDOpen, &fi);
373 if (fi.fMultipleSelection) {
374 if (fi.fFileNamesList) {
375 int N = fi.fFileNamesList->GetEntries();
376 for (
int i = 0; i <
N; ++i) {
377 OpenFile(fi.fFileNamesList->At(i)->GetName());
381 else if (fi.fFilename) {
385 if (fi.fFilename || fi.fFileNamesList) {
386 string currentDirectory = fi.fIniDir;
398 string prefixRemovedFilename = filename;
399 if (prefixRemovedFilename.find(
":\\") != string::npos) {
402 prefixRemovedFilename
403 = prefixRemovedFilename.substr(prefixRemovedFilename.find(
":\\")
406 if (prefixRemovedFilename.find(
"root://") == string::npos
407 && prefixRemovedFilename.find(
':') != string::npos) {
409 = prefixRemovedFilename.substr(0, prefixRemovedFilename.find(
':'));
410 if (server.find_last_of(
"/\\") != string::npos) {
411 server = server.substr(server.find_last_of(
"/\\") + 1);
414 = prefixRemovedFilename.substr(prefixRemovedFilename.find(
':') + 1);
415 if (server ==
"corc") {
416 server =
"corleone.roma1.infn.it";
417 file =
"/data/dianadata/ntp_cuoricino/" + file;
419 else if (server ==
"apollo") {
420 server =
"dianadaqha1.lngs.infn.it";
421 file =
"/data/daq/rawdata/" + file;
423 filename =
"root://" + server +
'/' + file;
424 TAuthenticate::SetGlobalUser(
"diana");
425 static char* passwd = NULL;
427 passwd = TAuthenticate::PromptPasswd(
"Password for user diana: ");
428 TAuthenticate::SetGlobalPasswd(passwd);
431 TString filenameTString(filename);
432 if (filenameTString.EndsWith(
".list")) {
434 }
else if (filenameTString.EndsWith(
".root")) {
439 cout <<
"Warning: The file " << filename
440 <<
" is already open and will not be added to the chain again."
442 }
else if (filename !=
"") {
443 fFile = TFile::Open(filename.c_str(),
"READ");
445 cout <<
"File " << filename
446 <<
" does not appear to be a valid ROOT file." << endl;
455 unsigned int numberOfTreesFound = 0;
456 TList *listOfKeys =
fFile->GetListOfKeys();
457 TIter keyIter(listOfKeys);
458 while ( TKey *currentKey =
dynamic_cast<TKey*
>(keyIter()) ) {
459 if ( TObject *currentObj
460 =
dynamic_cast<TObject*
>(currentKey->ReadObj()) ) {
461 if (currentObj->InheritsFrom(
"TTree")) {
463 ++numberOfTreesFound;
467 if (numberOfTreesFound != 1) {
468 cout <<
"File " << filename
469 <<
" does not contain a tree named " <<
QTREE_NAME
473 new TGInputDialog(gClient->GetRoot(), gClient->GetRoot(),
474 "Enter the name of the tree:", 0,
476 key =
fFile->FindKey(treeName);
480 string keyClass = key->GetClassName();
489 cout <<
"Tree class " << keyClass <<
" in file "
491 <<
" does not match existing tree class "
494 <<
"The tree will not be added to the chain."
509 const char* pulserPath =
fQChain->GetAlias(
"IsHeater");
511 fQChain->SetAlias(
"IsPulser",pulserPath);
517 cout <<
"The file " << filename
518 <<
" does not contain a tree with the given name."
533 vector<string>::const_iterator fileIter;
534 for (fileIter = files.begin(); fileIter != files.end(); ++fileIter) {
542 if (textFileHandler.
ReadFile(filename)) {
545 dataPath = textFileHandler.
GetValue(
"DATAPATH");
548 if ( dataPath.rfind(
"/") + 1 != dataPath.size() ) {
549 dataPath = dataPath +
"/";
552 else if ( filename.find_last_of(
"/\\") != std::string::npos ) {
554 = filename.substr( 0, filename.find_last_of(
"/\\") + 1 );
559 const vector<pair<string, string> >& lines = textFileHandler.
GetLines();
560 vector<pair<string, string> >::const_iterator lineIter = lines.begin();
561 while (lineIter != lines.end() && lineIter->first !=
"START") {
565 while (lineIter != lines.end() && lineIter->first !=
"END") {
566 string dataFile = lineIter->first;
567 if (!dataFile.empty() && dataFile[0] !=
'#') {
588 const TKey* key =
fFile->FindKey(treeName.c_str());
589 string treeClass = key->GetClassName();
591 if (treeClass ==
"QTree"
592 || treeClass ==
"QiTree"
593 || treeClass ==
"QATree") {
595 fFile->GetObject(treeName.c_str(), tree);
598 const char* unixTimeVar = utv ? utv->GetTitle() :
"";
599 double minTime = tree->GetMinimum(unixTimeVar);
601 fQChain->SetAlias(
"LowestStartRunUnixTime", Form(
"%.9g", minTime) );
QChannelRunData chanRunData
TList * GetListOfAllAliases()
Int_t Add(const char *filename, Long64_t nentries=kBigNumber)
TObjArray * GetListOfAllLeaves()
basic channel and run based info. Used in the QRunData object.
void SetDataDirectory(const std::string &directory)
Set data directory.
const std::string & GetDataDirectory()
Get data directory.
static QGDefaultsHandler * Instance()
Singleton.
Class to handle ROOT files.
time_t ModificationTime(const std::string &filename)
Return modification time of file.
Diana::QGlobalDataManager * fDataManager
std::set< std::string > GetSetOfQVectorAliases()
Get the aliases defined in the tree.
double fLowestStartTimeUnix
Lowest StartTimeUnix of open files.
std::set< std::string > GetSetOfLeaves()
Get the names of the leaves of the tree.
bool fFileOpen
File open flag.
Diana::QVector fSamples
samples (QVector or QVectorI or QPulse) to load
std::set< std::string > GetSetOfAliases()
Get the aliases defined in the tree.
const QRunData * GetRunData(const Long64_t eventNumber)
Get the run data for an event.
std::string fDataDirectory
Directory containing data files.
const QChannelRunData * GetChannelRunData(const Long64_t eventNumber)
Get the run data for an event.
const Diana::QVector & GetPulse(const Long64_t eventNumber, const std::string &samplesName)
Get the pulse of an event.
bool CheckForModifiedFiles()
Check whether any open file has been modified.
TEventList GetEventList(TCut cuts)
Get an event list containing the events passing a cut.
std::set< std::string > fNumericTypes
Collection of numeric data types.
void SetUpChain()
Set up the chain.
std::vector< std::string > fFilenames
Filenames.
QHeader * fHeader
QBaseEvent.
std::string fTreeClass
Name of tree's class.
void OpenFile()
Pop up a file open dialog.
TObject * GetGenericObject(const Long64_t eventNumber, const std::string &samplesName)
void ParseFileList(const std::string &filename)
Parse file list.
void ReopenFiles()
Reopen files.
void SetUpNumericTypes()
Specify the numeric data types.
std::set< std::string > GetSetOfQVectorLeaves()
Get the names of the leaves of the tree.
const std::vector< QSampleInfo > & GetSignificantSamples(const Long64_t eventNumber)
Get significant samples of an event.
std::string fDefaultPulseLabel
defalt label of samples to load
const QSampleInfo & GetMasterSample(const Long64_t eventNumber)
Get master sample of an event.
void SetLowestStartTimeUnix(const std::string &treeName)
Set LowestStartTimeUnix alias.
void GetEvent(const Long64_t eventNumber, const std::string &samplesName="")
Get an event.
void ListOpenFiles()
Print a list of open files to the console.
virtual ~QGFileHandler()
Destructor.
std::map< std::string, time_t > fModificationTime
Modification times of every open file.
QGFileHandler()
Constructor.
void CloseFiles()
Close all open files, empty the chain.
void OpenFiles(const std::vector< std::string > &files)
Open files, add them to the chain.
Class to handle input and output for text files.
const std::vector< std::pair< std::string, std::string > > & GetLines()
Get the lines of the file as key, value pairs.
std::string GetValue(std::string key)
Retrieve value associated with a key.
bool ReadFile(std::string filename)
Read file, returns true if successful.
bool DoesKeyExist(std::string key)
Return true if key exists.
static QGlobalReaderDispatcher & GetInstance()
const QSampleInfo & GetMasterSample() const
Get MasterSample.
const std::vector< QSampleInfo > & GetSamplesInfo() const
Get Samples Info.
const int & GetChannelId() const
Get ChannelId.
Raw event: sampled waveform.
const Diana::QVector & GetSamples() const
Get Samples casted to double (QVector instead of QVectorI). Use this method in place of GetSamplesADC...
global handle for QRunData
const QChannelRunData & GetChannelRunData(const int channel) const
get channel based run data quantities
contains information on flagged samples
Interface for raw daq vectors in Diana.
Interface for vectors in Diana analysis.