ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/yangyong/Pi0Calibration/Common/getGoodLS.cc
Revision: 1.1
Committed: Sat Aug 18 13:53:10 2012 UTC (12 years, 8 months ago) by yangyong
Content type: text/plain
Branch: MAIN
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 yangyong 1.1
2    
3    
4     vector<int> run_goodLS;
5    
6     map<int,vector<int> > map_runLS;
7    
8     vector<int> goodRunList;
9    
10     vector<int> crabRunList;
11    
12    
13     const int MAX_CHARS_PER_LINE = 99999;
14     const int MAX_TOKENS_PER_LINE = 99999;
15     const char* const DELIMITER = " ";
16    
17     //get LS ranges
18     ///cat Cert_132440-142664_7TeV_StreamExpress_Collisions10_CMSSWConfig.txt | grep : | grep - | sed s/"-"/" "/g | sed s/":"/" "/g | sed s/"'"/""/g | sed s/","/""/g
19    
20     ///update for multiple Json file
21    
22     void getLSrangeofEachRuns(vector<string> certfiles){
23    
24     int run;
25    
26     for(int n=0; n< int(certfiles.size()); n++){
27    
28     cout<<"certfile: "<< certfiles[n].c_str() <<endl;
29     ifstream txtin(certfiles[n].c_str(),ios::in);
30    
31    
32     while( txtin.good()){
33    
34     char buf[MAX_CHARS_PER_LINE];
35     txtin.getline(buf, MAX_CHARS_PER_LINE);
36    
37     if(txtin.eof()) break;
38    
39     const char* token[MAX_TOKENS_PER_LINE] = {0}; // initialize to 0
40     token[0] = strtok(buf, DELIMITER); // first token
41     vector<int> lsbl;
42     run = atoi(token[0]);
43     if (token[0]){
44     for (int k = 1; k < MAX_TOKENS_PER_LINE; k++){
45     token[k] = strtok(0, DELIMITER); // subsequent tokens
46     if (!token[k]) break; // no more tokens
47     int val = atoi(token[k]);
48     lsbl.push_back(val);
49     }
50     }
51     vector<int>::iterator it = find( goodRunList.begin(),goodRunList.end(),run);
52     if( it == goodRunList.end()){
53     goodRunList.push_back(run);
54     }
55     if( int(lsbl.size())< 2 || int(lsbl.size()) %2!=0){
56     cout<<"wrong format of goodLS file!! " << run <<" "<< lsbl.size()<<endl;
57     exit(1);
58     }
59     //insert into map
60     map_runLS.insert( make_pair(run,lsbl));
61    
62     }
63    
64     }
65    
66    
67     cout<<"total runs: "<< goodRunList.size()<<" map size "<< map_runLS.size()<<endl;
68    
69     for(int n=0; n< int( goodRunList.size());n++){
70    
71     map<int,vector<int> > :: const_iterator iterMap = map_runLS.find(goodRunList[n]);
72    
73     if( iterMap != map_runLS.end()){
74     vector<int> tmp = iterMap->second;
75     for(int j=0; j< int(tmp.size())/2; j++){
76     if( n<1 || n >int( goodRunList.size())-2 ) cout<< goodRunList[n]<<" "<< tmp[j*2] <<" "<< tmp[2*j+1]<<endl;
77     }
78     }else{
79     cout<<"wrongcheckmaprunLS.."<<endl;
80     exit(1);
81     }
82     }
83    
84    
85     }
86    
87    
88    
89     bool checkLumiBlockofRun(){
90    
91     bool goodLS = false;
92    
93     map<int,vector<int> > :: const_iterator iterMap = map_runLS.find(runNumber);
94    
95     if( iterMap != map_runLS.end()){
96     vector<int> tmp = iterMap->second;
97    
98     for(int j=0; j< int(tmp.size())/2; j++){
99     if( tmp[j*2] <= lumiBlock && lumiBlock <= tmp[2*j+1]){
100     goodLS = true;
101     break;
102     }
103     }
104    
105     }else{
106     return false;
107     }
108    
109     return goodLS;
110    
111    
112     }