File indexing completed on 2025-01-18 10:17:18
0001 import sys
0002 import re
0003
0004
0005 print("BAH!")
0006 regexes = [
0007
0008
0009
0010 (re.compile(r'void toStrings\(vector<pair<string,string> > &items\)\s*const\s*\{'), 'void Summarize(JObjectSummary& summary) const override {'),
0011
0012 (re.compile(r'AddString\(items,\s*"([^"]*)",\s*"([^"]*)",\s*([^,]*)\);'), r'summary.add(\3, "\1", "\2");'),
0013 (re.compile(r'AddString\(items, "([^"]*)",\s*"([^"]*)",\s*([^,]*),\s*"([^"]*)"\);'), r'summary.add(\3, "\1", "\2", "\4");'),
0014
0015
0016
0017 (re.compile(r"jana::JFactory<([a-zA-Z_0-9]+)>"), r'JFactoryT<\1>'),
0018
0019 (re.compile(r'#include <JANA/JFactory.h>'), r'#include <JANA/JFactoryT.h>'),
0020
0021 (re.compile(r'jerror_t init\(void\); ///< Called once at program start.'),
0022 r'void Init() override;'),
0023
0024 (re.compile(r'jerror_t brun\(jana::JEventLoop \*eventLoop, int32_t runnumber\); ///< Called everytime a new run number is detected.'),
0025 r'void ChangeRun(const std::shared_ptr<const JEvent>& event) override;'),
0026
0027 (re.compile(r'jerror_t evnt\(jana::JEventLoop \*eventLoop, uint64_t eventnumber\); ///< Called every event.'),
0028 r'void Process(const std::shared_ptr<const JEvent>& aEvent) override;'),
0029
0030 (re.compile(
0031 r'jerror_t erun\(void\); ///< Called everytime run number changes, provided brun has been called.'),
0032 r'void EndRun();'),
0033
0034 (re.compile(r'jerror_t fini\(void\); ///< Called after last event of last event source has been processed.'),
0035 r'void Finish();'),
0036
0037 (re.compile(r'jerror_t ([a-zA-Z_0-9]+)::init\(void\)'),
0038 r'void \1::Init()'),
0039
0040 (re.compile(r'jerror_t ([a-zA-Z_0-9]+)::brun\(JEventLoop \*eventLoop, int32_t runnumber\)'),
0041 r'void \1::ChangeRun(const std::shared_ptr<const JEvent>& event)'),
0042
0043 (re.compile(r'jerror_t ([a-zA-Z_0-9]+)::evnt\(JEventLoop \*loop, uint64_t eventnumber\)'),
0044 r'void \1::Process(const std::shared_ptr<const JEvent>& event)'),
0045
0046 (re.compile(r'jerror_t ([a-zA-Z_0-9]+)::erun\(void\)'),
0047 r'void \1::EndRun()'),
0048
0049 (re.compile(r'jerror_t ([a-zA-Z_0-9]+)::fini\(void\)'),
0050 r'void \1::Finish()'),
0051
0052
0053
0054 (re.compile(r'jana::'), ''),
0055
0056 (re.compile(r'#include <JANA/jerror\.h>\n'), ''),
0057
0058 (re.compile(r'jerror_t GenerateFactories\(JEventLoop \*loop\)'),
0059 r'void GenerateFactories(JFactorySet *factorySet)'),
0060
0061 (re.compile(r'loop->AddFactory'),
0062 r'factorySet->Add'),
0063 ]
0064
0065
0066 def main():
0067 filename = sys.argv[1]
0068 with open(filename, 'r') as f:
0069 contents = f.read()
0070
0071 for (before, after) in regexes:
0072 contents = re.sub(before, after, contents)
0073
0074 with open(filename, 'w') as f:
0075 f.write(contents)
0076 print(contents)
0077
0078
0079 if __name__ == '__main__':
0080 main()