tdaq-develop-2025-02-12
RootFileExplorer.h
1 #ifndef __RootFileExplorer_H__
2 #define __RootFileExplorer_H__
3 
4 #include <dirent.h>
5 #include <errno.h>
6 #include <stdio.h>
7 #include <string.h>
8 #include <sys/stat.h>
9 #include <sys/types.h>
10 #include <unistd.h>
11 #include <iostream>
12 #include <list>
13 #include <map>
14 #include <sstream>
15 #include <stdexcept>
16 #include <string>
17 #include <vector>
18 
19 #include <TBuffer.h>
20 #include <TBufferFile.h>
21 #include <TBufferJSON.h>
22 #include <TList.h>
23 #include <TRegexp.h>
24 
25 // #include "otsdaq/Macros/CoutMacros.h"
26 #include "otsdaq/MessageFacility/MessageFacility.h"
27 // #include "otsdaq/XmlUtilities/ConvertFromXML.h"
28 // #include "otsdaq/XmlUtilities/ConvertToXML.h"
29 
30 #include <xercesc/dom/DOM.hpp>
31 #include <xercesc/framework/LocalFileFormatTarget.hpp>
32 #include <xercesc/framework/StdOutFormatTarget.hpp>
33 #include <xercesc/util/OutOfMemoryException.hpp>
34 #include <xercesc/util/PlatformUtils.hpp>
35 #include <xercesc/util/XMLString.hpp>
36 
37 #include <xercesc/dom/DOM.hpp>
38 #include <xercesc/dom/DOMDocument.hpp>
39 #include <xercesc/dom/DOMDocumentType.hpp>
40 #include <xercesc/dom/DOMElement.hpp>
41 #include <xercesc/dom/DOMImplementation.hpp>
42 #include <xercesc/dom/DOMImplementationLS.hpp>
43 #include <xercesc/dom/DOMImplementationRegistry.hpp>
44 #include <xercesc/dom/DOMNodeIterator.hpp>
45 #include <xercesc/dom/DOMNodeList.hpp>
46 #include <xercesc/dom/DOMText.hpp>
47 #include <xercesc/framework/LocalFileFormatTarget.hpp>
48 #include <xercesc/parsers/XercesDOMParser.hpp>
49 #include <xercesc/util/OutOfMemoryException.hpp>
50 #include <xercesc/util/PlatformUtils.hpp>
51 #include <xercesc/util/XMLString.hpp>
52 #include <xercesc/util/XMLUni.hpp>
53 #include <xercesc/util/XercesDefs.hpp>
54 #include <xercesc/validators/common/Grammar.hpp>
55 // #include <xercesc/dom/DOMLSSerializer.hpp>
56 // #include <xercesc/dom/DOMLSOutput.hpp>
57 
58 #include "otsdaq/Macros/BinaryStringMacros.h"
59 // #include "otsdaq/XmlUtilities/HttpXmlDocument.h"
60 
61 #if defined(XERCES_NEW_IOSTREAMS)
62 #include <iostream>
63 #else
64 #include <iostream.h>
65 #endif
66 
67 #include <TDirectory.h>
68 #include <TFile.h>
69 #include <TKey.h>
70 
71 using namespace ots;
72 using namespace std;
73 
74 XERCES_CPP_NAMESPACE_USE
75 
76 // clang-format off
78 {
79  public:
80 
81  RootFileExplorer (string fSystemPath ,
82  string fRootPath ,
83  string fFoldersPath ,
84  string fHistName ,
85  string fRFoldersPath ,
86  string fFileName ,
87  TFile * rootFile = NULL ) ;
88  ~RootFileExplorer (void ) {;}
89  xercesc::DOMDocument * initialize (bool liveDQMFlag ) ;
90  void makeDirectoryBinaryTree (TDirectory * currentDirectory,
91  int indent ,
92  xercesc::DOMElement * anchorNode ) ;
93  void makeLiveDQMBinaryTree (TDirectory * currentDirectory,
94  int indent ,
95  std::string subDirName ,
96  xercesc::DOMElement * anchorNode ) ;
97  xercesc::DOMElement * populateBinaryTreeNode (xercesc::DOMElement * anchorNode ,
98  std::string name ,
100  bool isLeaf ) ;
101  void initializeXMLWriter (void ) ;
102 
103  private:
104 
105  std::string blanks (int level ) ;
106  void computeRFoldersPath (void ) ;
107  std::string computeHierarchyPaths (void ) ;
108  void dumpHierarchyPaths (std::string what ) ;
109  void shrinkHierarchyPaths (int number ) ;
110 
111  bool debug_ ;
112  bool liveDQMFlag_ ;
113  string fSystemPath_ ;
114  string fRootPath_ ;
115  string fFoldersPath_ ;
116  string fFileName_ ;
117  string fRFoldersPath_ ;
118  string fHistName_ ;
119  string fHistTitle_ ;
120  string rootDirectoryName_;
121  //std::string::size_type LDQM_pos_ ;
122  xercesc::DOMImplementation * theImplementation_;
123  xercesc::DOMDocument * theDocument_ ;
124  xercesc::DOMElement * rootElement_ ;
125  xercesc::DOMElement * anchorNodeLast_ ;
126  std::map<std::string, xercesc::DOMElement *> theNodes_ ;
127  std::map<std::string, xercesc::DOMElement *> theNodesB_ ;
128  std::map<std::string, std::string> theNodeName_ ;
129  std::map<std::string, std::string> theNodeNameB_ ;
130  std::vector<std::string> hierarchyPaths_ ;
131  std::string previousAncestor_ ;
132  std::map<bool,std::string> isALeaf_ ;
133  const std::string rootTagName_ ;
134  TFile * rootFile_ ;
135  int level_ ;
136  int counter_ ;
137  stringstream ss_ ;
138  xercesc::DOMLSSerializer * theSerializer_ ;
139  xercesc::XMLFormatTarget * myFormTarget_ ;
140  xercesc::DOMLSOutput * theOutput_ ;
141 // HttpXmlDocument xmlOut_ ;
142 } ;
143 // clang-format on
144 #endif