ATLAS Offline Software
Loading...
Searching...
No Matches
selectblock.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
3*/
4//
5// $Id: selectblock.cxx, v0.0 Mon 23 Jan 2017 12:30:25 CET sutt $
6
7#include <iostream>
8#include <fstream>
9#include <string>
10#include <vector>
11#include <cstdlib>
12#include <cstdio>
13
14template<typename T>
15std::ostream& operator<<( std::ostream& s, std::vector<T>& v ) {
16 for ( size_t i=0 ; i<v.size() ; i++ ) s << v[i] << std::endl;
17 return s;
18}
19
20
21void replace( std::vector<std::string> b, int position, const std::string& regex, const std::string& pattern ) {
22 for ( int i=0 ; i<b.size() ; i++ ) {
23
24 size_t p0 = b[i].find( "position=" );
25
26 std::string newline;
27
28 if ( p0!=std::string::npos ) {
29 char nl[128];
30
31 sprintf( nl, b[i].substr( 0, p0 ).c_str() );
32
33 std::string ns=nl;
34 ns+="position=\"%02d\">";
35
36 sprintf( nl, ns.c_str(), position );
37
38
39 newline = nl;
40 }
41 else {
42
43 size_t p = b[i].find( regex );
44
45 if ( p!=std::string::npos ) {
46 newline = b[i].replace( p, regex.size(), pattern );
47 }
48 else newline = b[i];
49 }
50
51 if ( newline.find("-plots")!=std::string::npos ) {
52 newline.replace( newline.find("-plots"), 6, "-test-plots" );
53 }
54
55 std::cout << newline << std::endl;
56 }
57}
58
59
60bool comparitor( std::vector<std::string>& b ) {
61 // for ( size_t i=0 ; i<b.size() ; i++ ) if ( b[i].find("TIDAcomparitor")!=std::string::npos ) return true;
62 for ( size_t i=0 ; i<b.size() ; i++ ) if ( b[i].find("TIDArun")!=std::string::npos ) return true;
63 return false;
64}
65
66
67int main( int argc, char** argv ) {
68
69 if ( argc<2 ) return -1;
70
71 std::ifstream file( argv[1] );
72
73 std::vector<std::vector<std::string> > block(1,std::vector<std::string>() );
74
75 bool start = false;
76
77 std::string line;
78
79 std::vector<int> position(1, 0);
80
81 int iblock = 0;
82
83 while( getline( file, line ) && !file.fail() ) {
84
85 if ( line.find("action")!=std::string::npos ) {
86 if ( line.find("/action")==std::string::npos ) {
87 start = true;
88 std::string tmp = line;
89 size_t pos = tmp.find("\"");
90 std::string p = tmp.substr( pos+1, tmp.size()-pos-1 );
91 pos = p.find("\"");
92 if (pos!=std::string::npos) p.resize( pos );
93 // position[iblock] = std::atoi( p.c_str() );
94
95 // std::cout << "pos: " << position << std::endl;
96
97 if ( iblock==0 ) {
98 iblock++;
99 block.push_back(std::vector<std::string>());
100 position.push_back( 0 );
101 }
102 position[iblock] = std::atoi( p.c_str() );
103 }
104 }
105
106 block[iblock].push_back(line);
107
108
109 if ( line.find("/action")!=std::string::npos ) {
110 start = false;
111 iblock++;
112 block.push_back(std::vector<std::string>());
113 position.push_back( 0 );
114 }
115
116 }
117
118 // std::cout << "\nBLOCKS " << block.size() << "\t" << position.size() << std::endl;
119
120
121 int maxblock = 0;
122
123 for ( size_t i=0 ; i<block.size() ; i++ ) {
124 if ( comparitor(block[i]) && position[i]>position[maxblock] ) maxblock = i;
125 }
126
127 int lastblock = 0;
128
129 for ( size_t i=0 ; i<block.size() ; i++ ) if ( position[i]>0 ) lastblock = i;
130
131 // std::cout << "maxblock " << maxblock << std::endl;
132
133 for ( size_t i=0 ; i<=lastblock ; i++ ) {
134 if ( !comparitor( block[i] ) ) std::cout << block[i] << std::endl;
135 }
136
137 int nblock = position[maxblock]+1;
138
139 // for ( size_t i=0 ; i<block.size() ; i++ ) {
140 // if ( comparitor(block[i]) && position[i]>0 ) {
141 // replace( block[i], nblock++, "TIDAcomparitor.exe", "TIDArun.sh" );
142 // }
143 // }
144
145 for ( size_t i=lastblock+1 ; i<block.size() ; i++ ) std::cout << block[i] << std::endl;
146
147
148 return 0;
149}
150
std::string find(const std::string &s)
return a remapped string
Definition hcg.cxx:138
int main()
Definition hello.cxx:18
std::ostream & operator<<(std::ostream &s, std::vector< T > &v)
void replace(std::vector< std::string > b, int position, const std::string &regex, const std::string &pattern)
bool comparitor(std::vector< std::string > &b)
TFile * file