ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/yangyong/Pi0Calibration/Common/getGoodLS.cc
Revision: 1.2
Committed: Sun Aug 19 12:09:25 2012 UTC (12 years, 8 months ago) by yangyong
Content type: text/plain
Branch: MAIN
CVS Tags: V00-00-01g, HEAD
Changes since 1.1: +5 -1 lines
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 yangyong 1.2 if (txtin.fail()) {
31     cout<<" file can not be opened!" <<endl;
32     exit(1);
33     }
34    
35 yangyong 1.1
36     while( txtin.good()){
37    
38     char buf[MAX_CHARS_PER_LINE];
39     txtin.getline(buf, MAX_CHARS_PER_LINE);
40    
41     if(txtin.eof()) break;
42    
43     const char* token[MAX_TOKENS_PER_LINE] = {0}; // initialize to 0
44     token[0] = strtok(buf, DELIMITER); // first token
45     vector<int> lsbl;
46     run = atoi(token[0]);
47     if (token[0]){
48     for (int k = 1; k < MAX_TOKENS_PER_LINE; k++){
49     token[k] = strtok(0, DELIMITER); // subsequent tokens
50     if (!token[k]) break; // no more tokens
51     int val = atoi(token[k]);
52     lsbl.push_back(val);
53     }
54     }
55     vector<int>::iterator it = find( goodRunList.begin(),goodRunList.end(),run);
56     if( it == goodRunList.end()){
57     goodRunList.push_back(run);
58     }
59     if( int(lsbl.size())< 2 || int(lsbl.size()) %2!=0){
60     cout<<"wrong format of goodLS file!! " << run <<" "<< lsbl.size()<<endl;
61     exit(1);
62     }
63     //insert into map
64     map_runLS.insert( make_pair(run,lsbl));
65    
66     }
67    
68     }
69    
70    
71     cout<<"total runs: "<< goodRunList.size()<<" map size "<< map_runLS.size()<<endl;
72    
73     for(int n=0; n< int( goodRunList.size());n++){
74    
75     map<int,vector<int> > :: const_iterator iterMap = map_runLS.find(goodRunList[n]);
76    
77     if( iterMap != map_runLS.end()){
78     vector<int> tmp = iterMap->second;
79     for(int j=0; j< int(tmp.size())/2; j++){
80     if( n<1 || n >int( goodRunList.size())-2 ) cout<< goodRunList[n]<<" "<< tmp[j*2] <<" "<< tmp[2*j+1]<<endl;
81     }
82     }else{
83     cout<<"wrongcheckmaprunLS.."<<endl;
84     exit(1);
85     }
86     }
87    
88    
89     }
90    
91    
92    
93     bool checkLumiBlockofRun(){
94    
95     bool goodLS = false;
96    
97     map<int,vector<int> > :: const_iterator iterMap = map_runLS.find(runNumber);
98    
99     if( iterMap != map_runLS.end()){
100     vector<int> tmp = iterMap->second;
101    
102     for(int j=0; j< int(tmp.size())/2; j++){
103     if( tmp[j*2] <= lumiBlock && lumiBlock <= tmp[2*j+1]){
104     goodLS = true;
105     break;
106     }
107     }
108    
109     }else{
110     return false;
111     }
112    
113     return goodLS;
114    
115    
116     }