Common Analysis Framework » QFRAMEWORK » TQUtils

namespace TQUtils


 TQUtils:

 The TQUtils namespace provides a variety of utility methods.


Function Members (Methods)

public:
intappendToListOfFolderNames(const TString& filename, TList* list, TClass* type = TQFolder::Class(), const TString& prefix = "")
intappendToListOfFolders(const TString& filename, TList* list, TClass* type = TQFolder::Class())
boolareEquivalent(TObject* obj1, TObject* obj2)
doubleconvertdXfromNDC(double x)
doubleconvertdXtoNDC(double x)
doubleconvertdXtoPixels(double x)
doubleconvertdYfromNDC(double y)
doubleconvertdYtoNDC(double y)
doubleconvertdYtoPixels(double y)
doubleconvertXfromNDC(double x)
doubleconvertXtoNDC(double x)
doubleconvertXtoPixels(double x)
doubleconvertYfromNDC(double y)
doubleconvertYtoNDC(double y)
doubleconvertYtoPixels(double y)
booldirectoryExists(const TString& path)
voiddumpTop(TString folder, TString prefix = "qframework", TString message = "")
boolensureDirectory(TString path)
boolensureDirectoryForFile(TString filename)
boolensureTrailingNewline(const char* filename)
TList*execute(const TString& cmd, size_t maxOutputLength = 80)
boolfileExists(const TString& filename)
boolfileExistsEOS(const TString& filename)
boolfileExistsLocal(const TString& filename)
TStringfindFile(const TString& basepath, const TString& filename)
TStringfindFile(TList* basepaths, const TString& filename)
TStringfindFile(TList* basepaths, const TString& filename, int& index)
TStringfindFileEOS(const TString& basepath, const TString& filename, const TString& eosprefix)
TStringfindFileLocal(const TString& basepath, const TString& filename)
TStringformatTimeDifference(unsigned int time)
doublegetAverage(vector<double>& vec)
doublegetAverageOrderOfMagnitude(TMatrixD* mat)
intgetAverageOrderOfMagnitudeInt(TMatrixD* mat)
TObjArray*getBranchNames(const TString& input)
size_tgetCurrentRSS()
unsigned longgetCurrentTime()
unsigned longgetFileSize(const TString& path)
chargetLastCharacterInFile(const char* filename)
TList*getListOfFilesMatching(TString pattern)
TList*getListOfFolderNamesInFile(const TString& filename, TClass* type = TQFolder::Class())
TList*getListOfFoldersInFile(const TString& filename, TClass* type = TQFolder::Class())
vector<TQTaggable*>*getListOfTagsFromFile(const TString& filename)
vector<TQTaggable*>*getListOfTagsFromFile(const TString& filename, TQTaggable& dictTags)
TStringgetMD5(const TString& filepath)
TStringgetMD5EOS(TString filepath)
TStringgetMD5Local(const TString& filepath)
intgetMinIndex(const vector<int>& vals, const vector<bool>& accepts)
intgetMinIndex(int val0, int val1, int val2, bool accept0, bool accept1, bool accept2)
TStringgetModificationDate(TFile* f)
TList*getObjects(const TString& objName, TClass* objClass = TObject::Class(), TDirectory* d = (ROOT::Internal::TDirectoryAtomicAdapter(TDirectory::CurrentDirectory())))
TList*getObjectsFromFile(TString identifier, TClass* objClass = TObject::Class())
TList*getObjectsFromFile(const TString& filename, const TString& objName, TClass* objClass = TObject::Class())
doublegetOrderOfMagnitude(double value)
intgetOrderOfMagnitudeInt(double value)
size_tgetPeakRSS()
doublegetSampleCorrelation(vector<double>& vec1, vector<double>& vec2, bool verbose = true)
doublegetSampleCovariance(vector<double>& vec1, vector<double>& vec2, bool verbose = true)
doublegetSampleVariance(vector<double>& vec)
doublegetSum(TTree* t, const TString& bname)
TStringgetTimeStamp(const TString& format = "%c", size_t len = 80)
doublegetValue(TTree* t, const TString& bname, Long64_t iEvent = 0)
boolinRange(double x, double a, double b)
boolisNum(double a)
TList*ls(TString exp)
TList*lsdCache(const TString& fname, const TString& localGroupDisk, const TString& oldHead, const TString& newHead, const TString& dq2cmd = "dq2")
TList*lsEOS(TString exp, const TString& eosprefix, TString path = "")
TList*lsLocal(const TString& exp)
TFile*openFile(const TString& filename)
boolparseAssignment(TString input, TString* dest, TString* source)
voidprintActiveBranches(TTree* t)
voidprintBranches(TTree* t)
voidprintDecayChain(TTree* t, Long64_t evt = 0, int ptcl = 0, const TString& bName = "TruthParticles")
voidprintHEPdataInfo(TQFolder* config, const TString& title, const TString& description, const TString& filename)
voidprintParticle(TTree* t, Long64_t evt, int index, const TString& bName = "TruthParticles")
voidprintParticles(TTree* t, Long64_t evt, int id, const TString& bName = "TruthParticles")
voidprintProductionChain(TTree* t, Long64_t evt = 0, int ptcl = 0, const TString& bName = "TruthParticles")
stringreadEnvVarValue(const string& envVar)
boolreadEnvVarValueBool(const string& envVar, bool fallback = true)
doubleround(double d, int nDigits = 0)
doubleroundAuto(double d, int nSig = 1)
doubleroundAutoDown(double d, int nSig = 1)
doubleroundAutoUp(double d, int nSig = 1)
doubleroundDown(double d, int nDigits = 0)
doubleroundUp(double d, int nDigits = 0)
intsgn(int val)
doublesgn(double val)
voidwriteHEPdataError(ostream& out, double eup, double edn, string elbl)
voidwriteHEPdataHeader(ostream& out, const TString& vartype, const TString name, const TString& unit = "")
voidwriteHEPdataValue(ostream& out, const TString& s)
voidwriteHEPdataValue(ostream& out, double d)
voidwriteHEPdataValueAndError(ostream& out, double d, double e, string elbl)
voidwriteHEPdataValueWithErrors(ostream& out, double d)
doublexAODMetaDataGetNEventsInitialFromCutBookkeeper(TTree* tree, const char* container = "StreamAOD", const char* bookkeeper = "AllExecutedEvents")
doublexAODMetaDataGetNEventsInitialFromCutBookkeeper(xAOD::TEvent& event, const char* container = "StreamAOD", const char* bookkeeper = "AllExecutedEvents")
doublexAODMetaDataGetSumWeightsInitialFromCutBookkeeper(TTree* tree, const char* container = "StreamAOD", const char* bookkeeper = "AllExecutedEvents")
doublexAODMetaDataGetSumWeightsInitialFromCutBookkeeper(xAOD::TEvent& event, const char* container = "StreamAOD", const char* bookkeeper = "AllExecutedEvents")
doublexAODMetaDataGetSumWeightsInitialFromEventBookkeeper(TTree* MetaData)

Class Charts

Function documentation

int getMinIndex(int val0, int val1, int val2, bool accept0, bool accept1, bool accept2)
int getMinIndex(const vector<int>& vals, const vector<bool>& accepts)
bool areEquivalent(TObject* obj1, TObject* obj2)
 Returns true if objects <obj1> and <obj2> are considered equivalent. [not yet
 implemented]
bool ensureDirectoryForFile(TString filename)
 ensure that the directory for the given file exists
char getLastCharacterInFile(const char* filename)
 retrieve the last character in a text file
bool ensureTrailingNewline(const char* filename)
 check if the given text file has a terminating newline character
 if this is not the case, append a newline at the end
bool directoryExists(const TString& path)
 check if directory <path> exists
bool ensureDirectory(TString path)
 ensure that the directory with the given path exists
TFile * openFile(const TString& filename)
bool fileExists(const TString& filename)
 Check whether the file <filename> exists and return true if so,
 and false otherwise
bool fileExistsEOS(const TString& filename)
 Check whether the file <filename> exists and return true if so,
 and false otherwise. Works on eos paths.
bool fileExistsLocal(const TString& filename)
 check if the file exists and is readable;
TList * getListOfFilesMatching(TString pattern)
 Scans the file system for files whose names match the string pattern <pattern>
 and returns a list (instance of TList) of matching filenames (as instances of
 TObjString).
bool parseAssignment(TString input, TString* dest, TString* source)
TObjArray * getBranchNames(const TString& input)
 Strip all valid branch names from a TString
 and return them in a TObjArray 
bool isNum(double a)
Determine if a given number is a valid and finite numerical value
bool inRange(double x, double a, double b)
 Determine if a given number is in a given range
   * if a<b, inRange(x,a,b) will return true if a<=x<=b, else false
   * if a>b, inRange(x,a,b) will return false if a<x<b, else true

unsigned long getCurrentTime()
 returns the current time in milliseconds since 01 Jan 1970, 0:00
TString getTimeStamp(const TString& format = "%c", size_t len = 80)
 return the current time formatted according to the given string
TString formatTimeDifference(unsigned int time)
double convertXtoNDC(double x)
 convert an x-coordinate (horizontal)
 from user to NDC coordinates
 using the current pad
double convertYtoNDC(double y)
 convert an y-coordinate (vertical)
 from user to NDC coordinates
 using the current pad
double convertXtoPixels(double x)
 convert an x-coordinate (horizontal)
 from user to absolute (pixel) coordinates
 using the current pad
double convertYtoPixels(double y)
 convert an y-coordinate (vertical)
 from user to absolute (pixel) coordinates
 using the current pad
double convertXfromNDC(double x)
 convert an x-coordinate (horizontal)
 from NDC to user coordinates
 using the current pad
double convertYfromNDC(double y)
 convert an y-coordinate (vertical)
 from NDC to user coordinates
 using the current pad
double convertdXtoNDC(double x)
 convert an x-distance (horizontal)
 from user to NDC coordinates
 using the current pad
double convertdYtoNDC(double y)
 convert an y-distance (vertical)
 from user to NDC coordinates
 using the current pad
double convertdXtoPixels(double x)
 convert an x-distance (horizontal)
 from user to absolute (pixel) coordinates
 using the current pad
double convertdYtoPixels(double y)
 convert an y-distance (vertical)
 from user to absolute (pixel) coordinates
 using the current pad
double convertdXfromNDC(double x)
 convert an x-distance (horizontal)
 from NDC to user coordinates
 using the current pad
double convertdYfromNDC(double y)
 convert an y-distance (vertical)
 from NDC to user coordinates
 using the current pad
double getAverage(vector<double>& vec)
double getSampleVariance(vector<double>& vec)
returns unbiased sample variance 1/(n-1)*sum (x_i-x)^2
double getSampleCovariance(vector<double>& vec1, vector<double>& vec2, bool verbose = true)
returns unbiased sample covariance 1/(n-1)*sum (x_i-x)^2
double getSampleCorrelation(vector<double>& vec1, vector<double>& vec2, bool verbose = true)
double getAverageOrderOfMagnitude(TMatrixD* mat)
 Calculates the average order of magnitude of the matrix entries through log10(value).
 If value is zero, the order of magnitude is assumed to be zero.
 This version does not round at any step.
int getAverageOrderOfMagnitudeInt(TMatrixD* mat)
 Calculates the average order of magnitude of the matrix entries through log10(value).
 If value is zero, the order of magnitude is assumed to be zero.
 This version rounds down to the next integer at each step (i.e. at each log10(value) as well as for the average)
TList* execute(const TString& cmd, size_t maxOutputLength = 80)
 execute the commmand, returning a TList containing lines of output it produced
TString findFileEOS(const TString& basepath, const TString& filename, const TString& eosprefix)
 return the full valid path of a file residing on EOS, given the filename and a base folder
 returns empty string if no match found
TString findFileLocal(const TString& basepath, const TString& filename)
 return the full valid path of a local file, given the filename and a base folder
 returns empty string if no match found
TString findFile(const TString& basepath, const TString& filename)
 return the full valid path of a file at any location, given the filename and a list of base folders
 returns empty string if no match found
TString findFile(TList* basepaths, const TString& filename, int& index)
 return the full valid path of a file, given the filename and a list of base folders
 returns empty string if no match found
TString findFile(TList* basepaths, const TString& filename)
 return the full valid path of a file, given the filename and a list of base folders
 returns empty string if no match found
TList* ls(TString exp)
 return a list of files matching the expression
 if used on local files, the output is equivalent to bash "ls"

 this function also supports remote file systems
 - for EOS, please make sure that TQLibrary knows about
 the location of the "eos.select" binary
 if not properly detected by the Makefile, this can be
 edited by calling TQLibrary::getQLibary()->setEOScmd("...")
 please prefix EOS paths with "root://"
 - for Grid dCache, please make sure that TQLibrary knows about
 * the name of the local group disk
 set with TQLibary::getQLibrary()->setLocalGroupDisk("...")
 * a dq2 suite (default "dq2")
 set with TQLibary::getQLibrary()->setDQ2cmd("...")
 * if necessary, path head replacements. Set with
 TQLibrary::getQLibrary()->setDQ2Head() for the old head to be removed
 TQLibrary::getQLibrary()->setdCacheHead() for the new head to be prepended
 all of these values can be set in a "locals.h" defintion file, for example, put
 #define LOCALGROUPDISK "UNI-FREIBURG_LOCALGROUPDISK"
 #define DQ2PATHHEAD "srm://se.bfg.uni-freiburg.de"
 #define DCACHEPATHHEAD "dcap://se.bfg.uni-freiburg.de:22125"
 please prefix dataset expressions with "dCache:"
TList* lsEOS(TString exp, const TString& eosprefix, TString path = "")
 return a full list of all files in the given location on EOS
 please make sure that TQLibrary knows about the location of the
 binary "eos.select".
 if not properly detected by the Makefile, this can be
 edited by calling TQLibrary::getQLibary()->setEOScmd("...")
TList* lsdCache(const TString& fname, const TString& localGroupDisk, const TString& oldHead, const TString& newHead, const TString& dq2cmd = "dq2")
 return a full list of all files locally available in the dCache
 the dataset and localGroupDisk names are forwarded to dq2-ls
 the dq2-command can be set as optional parameter (use, e.g. 'dq2' or 'rucio')
 if oldHead and newHead are given, the resulting path head will be exchanged accordingly
TList* lsLocal(const TString& exp)
 execute an "ls" command locally and return the result as a TList
TList* getObjectsFromFile(TString identifier, TClass* objClass = TObject::Class())
 the identifier is formatted "filename:objectname"
 retrieves a list of all objects in the given file
 that have a key matching the given class
 and object name pattern (may contain wildcards)
TList* getObjectsFromFile(const TString& filename, const TString& objName, TClass* objClass = TObject::Class())
 retrieves a list of all objects in the given file
 that have a key matching the given class
 and object name pattern (may contain wildcards)
TList* getObjects(const TString& objName, TClass* objClass = TObject::Class(), TDirectory* d = (ROOT::Internal::TDirectoryAtomicAdapter(TDirectory::CurrentDirectory())))
 retrieves a list of all objects in the given directory
 that have a key matching the given class
 and object name pattern (may contain wildcards)
 Wildcard matching is disabled, if the given name contains a slash (/). In
 this case the given name is used directory in root_file->Get(..), which
 means that the TTrees can be stored in TDirectories.
std::vector<TQTaggable*>* getListOfTagsFromFile(const TString& filename)
 retrieves a list of sets of tags written in a file
 tags written in a single line are put together a set, i.e. one TQTaggable
 optionally provide a dictionary for $(placeholder)'s
std::vector<TQTaggable*>* getListOfTagsFromFile(const TString& filename, TQTaggable& dictTags)
 retrieves a list of sets of tags written in a file
 tags written in a single line are put together a set, i.e. one TQTaggable
 optionally provide a dictionary for $(placeholder)'s
void printBranches(TTree* t)
 print the branches of a tree in a nice format
void printActiveBranches(TTree* t)
 print the active branches of a tree in a nice format
void printProductionChain(TTree* t, Long64_t evt = 0, int ptcl = 0, const TString& bName = "TruthParticles")
void printDecayChain(TTree* t, Long64_t evt = 0, int ptcl = 0, const TString& bName = "TruthParticles")
void printParticles(TTree* t, Long64_t evt, int id, const TString& bName = "TruthParticles")
void printParticle(TTree* t, Long64_t evt, int index, const TString& bName = "TruthParticles")
double getValue(TTree* t, const TString& bname, Long64_t iEvent = 0)
 evaluate an expression on a specific event of a TTree
double getSum(TTree* t, const TString& bname)
 evaluate an expression on all events of a TTree and return the sum
double xAODMetaDataGetSumWeightsInitialFromEventBookkeeper(TTree* MetaData)
 retrieve the initial sum of weights from the event bookkeepers in this tree
 thanks to a dirty hack, this also works in standalone mode
double xAODMetaDataGetSumWeightsInitialFromCutBookkeeper(xAOD::TEvent& event, const char* container = "StreamAOD", const char* bookkeeper = "AllExecutedEvents")
 retrieve the initial sum of weights from the cut bookkeepers in this file
double xAODMetaDataGetSumWeightsInitialFromCutBookkeeper(TTree* tree, const char* container = "StreamAOD", const char* bookkeeper = "AllExecutedEvents")
 retrieve the initial sum of weights from the cut bookkeepers in this file
double xAODMetaDataGetNEventsInitialFromCutBookkeeper(xAOD::TEvent& event, const char* container = "StreamAOD", const char* bookkeeper = "AllExecutedEvents")
 retrieve the initial number of events from the cut bookkeepers in this file
double xAODMetaDataGetNEventsInitialFromCutBookkeeper(TTree* tree, const char* container = "StreamAOD", const char* bookkeeper = "AllExecutedEvents")
TList* getListOfFoldersInFile(const TString& filename, TClass* type = TQFolder::Class())
 retrieve the list of TQFolders contained in a given file
 if the class type is given, only TQFolder instances
 of the given class type are considered
int appendToListOfFolders(const TString& filename, TList* list, TClass* type = TQFolder::Class())
 append all TQfolders contained in a given file to a list
 if the class type is given, only TQFolder instances
 of the given class type are considered
TList* getListOfFolderNamesInFile(const TString& filename, TClass* type = TQFolder::Class())
 retrieve the list of names of TQFolders contained in a given file
 if the class type is given, only TQFolder instances
 of the given class type are considered
int appendToListOfFolderNames(const TString& filename, TList* list, TClass* type = TQFolder::Class(), const TString& prefix = "")
 append all names of TQFolders contained in a given file to a list
 if the class type is given, only TQFolder instances
 of the given class type are considered
 the prefix is prepended to every single name
double roundAuto(double d, int nSig = 1)
 round some double to a number of significant digits
double roundAutoDown(double d, int nSig = 1)
 round down some double to a number of significant digits
double roundAutoUp(double d, int nSig = 1)
 round up some double to a number of significant digits
double round(double d, int nDigits = 0)
 round some double to a number of digits
double roundDown(double d, int nDigits = 0)
 round down some double to a number of digits
double roundUp(double d, int nDigits = 0)
 round up some double to a number of digits
TString getMD5(const TString& filepath)
 retrieve the MD5 sum (hex value) of some file as a TString
TString getMD5Local(const TString& filepath)
 retrieve the MD5 sum (hex value) of some local file as a TString
TString getMD5EOS(TString filepath)
 retrieve the MD5 sum (hex value) of some EOS file as a TString
TString getModificationDate(TFile* f)
 return the modification date of a TFile as a TString
unsigned long getFileSize(const TString& path)
void dumpTop(TString folder, TString prefix = "qframework", TString message = "")
void writeHEPdataHeader(ostream& out, const TString& vartype, const TString name, const TString& unit = "")
void writeHEPdataValue(ostream& out, double d)
void writeHEPdataValueAndError(ostream& out, double d, double e, string elbl)
void writeHEPdataValueWithErrors(ostream& out, double d)
void writeHEPdataError(ostream& out, double eup, double edn, string elbl)
void writeHEPdataValue(ostream& out, const TString& s)
void printHEPdataInfo(TQFolder* config, const TString& title, const TString& description, const TString& filename)
std::string readEnvVarValue(const string& envVar)
bool readEnvVarValueBool(const string& envVar, bool fallback = true)
 reads an env var specified by the first argument and returns its value as
 a boolean. If the env var is not found or cannot be safely interpreted as
 a boolean then fallback is returned.
size_t getPeakRSS()
size_t getCurrentRSS()
int sgn(int val)
to be moved to TQStringUtils
{ return (val<0 ? -1 : 1); }
double sgn(double val)
{ return (val<0 ? -1. : 1.); }
double getOrderOfMagnitude(double value)
{return value==0 ? 0. : log10(fabs(value)) ;}
int getOrderOfMagnitudeInt(double value)
{return int (value==0 ? 0. : log10(fabs(value))) ;}